OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [services/] [curses/] [pdcurses/] [current/] [src/] [drivers/] [serial.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// ==========================================================================
2
//
3
//      serial.c
4
//
5
//      Public Domain Curses for eCos
6
//
7
// ===========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under    
14
// the terms of the GNU General Public License as published by the Free     
15
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
// ===========================================================================
40
// ===========================================================================
41
// #####DESCRIPTIONBEGIN####
42
//
43
// Author(s):    Sergei Gavrikov
44
// Contributors: Sergei Gavrikov
45
// Date:         2009-04-24
46
// Purpose:      PDCurses driver for a serial device
47
// Description:
48
//
49
// ####DESCRIPTIONEND####
50
//
51
// ========================================================================*/
52
 
53
#include <cyg/kernel/kapi.h>           // cyg_thread_delay
54
#include <cyg/infra/diag.h>            // diagnostic routings
55
#include <stdlib.h>                    // free, calloc
56
 
57
// eCos serial devices
58
#include <cyg/io/io.h>
59
#include <pkgconf/io_serial.h>
60
#include <cyg/io/serialio.h>
61
#include <cyg/io/config_keys.h>
62
 
63
// PDCurses
64
#include <pkgconf/pdcurses.h>
65
#include <curspriv.h>
66
 
67
#define NDEBUG
68
 
69
#if CYGDAT_PDCURSES_DRIVER_USE_VT100_ATTR
70
# define ENABLE_VT100_ATTR
71
#endif
72
#if CYGDAT_PDCURSES_DRIVER_USE_ANSI_COLORS
73
# define ENABLE_COLOR
74
#endif
75
#if CYGDAT_PDCURSES_DRIVER_USE_KEYPAD_KEYS
76
# define ENABLE_KEYPAD
77
#endif
78
 
79
static char     device[] = CYGDAT_PDCURSES_DRIVER_SERIAL_DEV;
80
static cyg_io_handle_t handle = NULL;
81
 
82
// ---------------------------------------------------------------------------
83
// acs_map --
84
//
85
// A port of PDCurses must provide acs_map[], a 128-element array of chtypes,
86
// with values laid out based on the Alternate Character Set of the VT100
87
// (see curses.h). PDC_transform_line() must use this table; when it
88
// encounters a chtype with the A_ALTCHARSET flag set. For far details reffer
89
// to a pdcurses/IMPLEMNT document.
90
 
91
chtype          acs_map[128];
92
// ---------------------------------------------------------------------------
93
 
94
unsigned long   pdc_key_modifiers = 0L;
95
 
96
// ---------------------------------------------------------------------------
97
// atrtab --
98
//
99
// An attibutes table (it is used internally for the port's PDC_init_pair(),
100
// PDC_pair_content().
101
 
102
static struct {
103
    short           f,
104
                    b;
105
} atrtab[PDC_COLOR_PAIRS];
106
// ---------------------------------------------------------------------------
107
 
108
// ---------------------------------------------------------------------------
109
// __gotoyx --
110
//
111
static void
112
__gotoyx(int y, int x)
113
{
114
    char            buf[8] = { '\033', '[', '0', '0', ';', '0', '0', 'H' };
115
    unsigned int    len = sizeof(buf);
116
 
117
    buf[2] = ((y + 1) / 10) + '0';
118
    buf[3] = ((y + 1) % 10) + '0';
119
    buf[5] = ((x + 1) / 10) + '0';
120
    buf[6] = ((x + 1) % 10) + '0';
121
 
122
    cyg_io_write(handle, buf, &len);
123
}
124
 
125
// ---------------------------------------------------------------------------
126
// PDC_gotoyx --
127
//
128
// Move the physical cursor (as opposed to the logical cursor affected by
129
// wmove()) to the given location. This is called mainly from doupdate(). In
130
// general, this function need not compare the old location with the new one,
131
// and should just move the cursor unconditionally.
132
// ---------------------------------------------------------------------------
133
 
134
void
135
PDC_gotoyx(int y, int x)
136
{
137
 
138
#ifdef DEBUG
139
    diag_printf("PDC_gotoyx called: x %d y %d\n", x, y);
140
#endif
141
 
142
    __gotoyx(y, x);
143
 
144
    cyg_io_get_config(handle, CYG_IO_GET_CONFIG_SERIAL_OUTPUT_DRAIN, NULL,
145
                      NULL);
146
}
147
 
148
// ---------------------------------------------------------------------------
149
// PDC_transform_line --
150
//
151
// The core output routine. It takes len chtype entities from srcp (a pointer
152
// into curscr) and renders them to the physical screen at line lineno,
153
// column x. It must also translate characters 0-127 via acs_map[], if
154
// they're flagged with A_ALTCHARSET in the attribute portion of the chtype.
155
// ---------------------------------------------------------------------------
156
 
157
static short    curstoansi[8] = { 0, 4, 2, 6, 1, 5, 3, 7 };
158
static chtype   prev_attr = A_PROTECT;
159
 
160
void
161
PDC_transform_line(int lineno, int x, int len, const chtype *srcp)
162
{
163
    int             i;
164
    chtype          attr;
165
 
166
#ifdef DEBUG
167
    diag_printf("PDC_transform_line called: lineno %d curpos %d len %d\n",
168
                lineno, x, len);
169
#endif
170
 
171
    __gotoyx(lineno, x);
172
 
173
    for (i = 0; i < len; i++) {
174
        unsigned char   byte;
175
        chtype          ch = srcp[i];
176
        unsigned int    single = 1;
177
 
178
#if defined(ENABLE_COLOR) || defined(ENABLE_VT100_ATTR)
179
        attr = ch & A_ATTRIBUTES;
180
        // <ESC>[#; ... m
181
        if (prev_attr != attr) {
182
            short           fg,
183
                            bg,
184
                            pair;
185
            char            escape[32];
186
            unsigned int    count;
187
 
188
            count = 0;
189
            escape[count++] = '\x1b';
190
            escape[count++] = '[';
191
            escape[count++] = '0';
192
# ifdef ENABLE_COLOR
193
            pair = PAIR_NUMBER(attr);
194
            fg = curstoansi[atrtab[pair].f];
195
            bg = curstoansi[atrtab[pair].b];
196
            escape[count++] = ';';
197
            escape[count++] = '3';
198
            escape[count++] = '0' + fg;
199
            escape[count++] = ';';
200
            escape[count++] = '4';
201
            escape[count++] = '0' + bg;
202
# endif                         // ENABLE_COLOR
203
# ifdef ENABLE_VT100_ATTR
204
            if (attr & A_BOLD) {
205
                escape[count++] = ';';
206
                escape[count++] = '1';
207
            }
208
            if (attr & A_UNDERLINE) {
209
                escape[count++] = ';';
210
                escape[count++] = '4';
211
            }
212
            if (attr & A_BLINK) {
213
                escape[count++] = ';';
214
                escape[count++] = '5';
215
            }
216
            if (attr & A_REVERSE) {
217
                escape[count++] = ';';
218
                escape[count++] = '7';
219
            }
220
            if (attr & A_INVIS) {
221
                escape[count++] = ';';
222
                escape[count++] = '8';
223
            }
224
# endif                         // ENABLE_VT100_ATTR
225
            escape[count++] = 'm';
226
            cyg_io_write(handle, escape, &count);
227
 
228
            prev_attr = attr;
229
        }
230
#endif                          // ENABLE_COLOR || ENABLE_VT100_ATTR
231
#ifdef CHTYPE_LONG
232
        if (ch & A_ALTCHARSET && !(ch & 0xff80))
233
            ch = acs_map[ch & 0x7f];
234
#endif
235
        ch &= 0xff;
236
        byte = (unsigned char) ch;
237
        cyg_io_write(handle, &byte, &single);
238
    }
239
 
240
    cyg_io_get_config(handle, CYG_IO_GET_CONFIG_SERIAL_OUTPUT_DRAIN, NULL,
241
                      NULL);
242
}
243
 
244
// ---------------------------------------------------------------------------
245
// PDC_get_columns --
246
//
247
// Returns the size of the screen in columns. It's used in resize_term() to
248
// set the new value of COLS. (Some existing implementations also call it
249
// internally from PDC_scr_open(), but this is not required.)
250
// ---------------------------------------------------------------------------
251
 
252
int
253
PDC_get_columns(void)
254
{
255
    return CYGDAT_PDCURSES_DRIVER_SCREEN_COLUMNS;
256
}
257
 
258
// ---------------------------------------------------------------------------
259
// PDC_get_cursor_mode --
260
//
261
// Returns the size/shape of the cursor. The format of the result is
262
// unspecified, except that it must be returned as an int. This function is
263
// called from initscr(), and the result is stored in SP->orig_cursor, which
264
// is used by PDC_curs_set() to determine the size/shape of the cursor in
265
// normal visibility mode (curs_set(1)).
266
// ---------------------------------------------------------------------------
267
 
268
int
269
PDC_get_cursor_mode(void)
270
{
271
    return 0;
272
}
273
 
274
// ---------------------------------------------------------------------------
275
// PDC_get_rows --
276
//
277
// Returns the size of the screen in rows. It's used in resize_term() to set
278
// the new value of LINES. (Some existing implementations also call it
279
// internally from PDC_scr_open(), but this is not required.)
280
// ---------------------------------------------------------------------------
281
 
282
int
283
PDC_get_rows(void)
284
{
285
    return CYGDAT_PDCURSES_DRIVER_SCREEN_ROWS;
286
}
287
 
288
// ---------------------------------------------------------------------------
289
// PDC_check_key --
290
//
291
// Keyboard/mouse event check, called from wgetch(). Returns TRUE if there's
292
// an event ready to process. This function must be non-blocking.
293
// ---------------------------------------------------------------------------
294
 
295
static int      key_code = ERR;
296
static unsigned char keystroke[4] = { '\0', '\0', '\0', '\0' };
297
 
298
#define _FLSH_KEY() *(unsigned int *) &keystroke[0] = 0;
299
#if (CYG_BYTEORDER == CYG_LSBFIRST)
300
// Little endian
301
# define _UNGET_KEY(_n_)  *(unsigned int *) &keystroke[0] >>= 8*(_n_)
302
#elif (CYG_BYTEORDER == CYG_MSBFIRST)
303
// Big endian
304
# define _UNGET_KEY(_n_)  *(unsigned int *) &keystroke[0] <<= 8*(_n_)
305
#endif
306
 
307
bool
308
PDC_check_key(void)
309
{
310
    unsigned int    len,
311
                    count;
312
    cyg_serial_buf_info_t dev_buf_conf;
313
 
314
    len = sizeof(dev_buf_conf);
315
    cyg_io_get_config(handle, CYG_IO_GET_CONFIG_SERIAL_BUFFER_INFO,
316
                      &dev_buf_conf, &len);
317
 
318
#ifndef ENABLE_KEYPAD
319
    return (dev_buf_conf.rx_count > 0);
320
#else
321
    if ((count = dev_buf_conf.rx_count) > 0) {
322
        if (keystroke[0] == '\0') {
323
            count = min(count, 4);
324
            cyg_io_read(handle, &keystroke[0], &count);
325
        } else if (keystroke[1] == '\0') {
326
            count = min(count, 3);
327
            cyg_io_read(handle, &keystroke[1], &count);
328
        } else if (keystroke[2] == '\0') {
329
            count = min(count, 2);
330
            cyg_io_read(handle, &keystroke[2], &count);
331
        } else if (keystroke[3] == '\0') {
332
            count = min(count, 1);
333
            cyg_io_read(handle, &keystroke[3], &count);
334
        }
335
    }
336
    if (keystroke[0] == '\0')
337
        return FALSE;
338
    switch (keystroke[0]) {
339
    case '\x1b':
340
        switch (keystroke[1]) {
341
        case '[':
342
            switch (keystroke[2]) {
343
                // ^[[A -- KEY_UP
344
            case 'A':
345
                key_code = KEY_UP;
346
                _UNGET_KEY(3);
347
                return TRUE;
348
                // ^[[B -- KEY_DOWN
349
            case 'B':
350
                key_code = KEY_DOWN;
351
                _UNGET_KEY(3);
352
                return TRUE;
353
                // ^[[C -- KEY_RIGHT
354
            case 'C':
355
                key_code = KEY_RIGHT;
356
                _UNGET_KEY(3);
357
                return TRUE;
358
                // ^[[D -- KEY_LEFT
359
            case 'D':
360
                key_code = KEY_LEFT;
361
                _UNGET_KEY(3);
362
                return TRUE;
363
            case '1':
364
            case '4':
365
            case '5':
366
            case '6':
367
                switch (keystroke[3]) {
368
                case '~':
369
                    switch (keystroke[2]) {
370
                        // ^[[1~ -- KEY_HOME
371
                    case '1':
372
                        key_code = KEY_HOME;
373
                        _FLSH_KEY();
374
                        return TRUE;
375
                        // ^[[4~ -- KEY_END
376
                    case '4':
377
                        key_code = KEY_END;
378
                        _FLSH_KEY();
379
                        return TRUE;
380
                        // ^[[5~ -- KEY_PPAGE
381
                    case '5':
382
                        key_code = KEY_PPAGE;
383
                        _FLSH_KEY();
384
                        return TRUE;
385
                        // ^[[6~ -- KEY_NPAGE
386
                    case '6':
387
                        key_code = KEY_NPAGE;
388
                        _FLSH_KEY();
389
                        return TRUE;
390
                    }
391
                default:
392
                    break;
393
                }
394
            default:
395
                break;
396
            }
397
        case 'O':
398
            switch (keystroke[2]) {
399
                // ^[OF -- KEY_END
400
            case 'F':
401
                key_code = KEY_END;
402
                _UNGET_KEY(3);
403
                return TRUE;
404
                // ^[OH -- KEY_HOME
405
            case 'H':
406
                key_code = KEY_HOME;
407
                _UNGET_KEY(3);
408
                return TRUE;
409
            default:
410
                break;
411
            }
412
        default:
413
            break;
414
        }
415
    default:
416
        break;
417
    }
418
    key_code = keystroke[0];
419
    _UNGET_KEY(1);
420
    return TRUE;
421
#endif                          // ENABLE_KEYPAD
422
}
423
 
424
// ---------------------------------------------------------------------------
425
// PDC_flushinp --
426
//
427
// This is the core of flushinp(). It discards any pending key or mouse
428
// events, removing them from any internal queue and from the OS queue, if
429
// applicable.
430
// ---------------------------------------------------------------------------
431
 
432
void
433
PDC_flushinp(void)
434
{
435
    cyg_io_get_config(handle, CYG_IO_GET_CONFIG_SERIAL_INPUT_FLUSH, NULL,
436
                      NULL);
437
#ifdef ENABLE_KEYPAD
438
    _FLSH_KEY();
439
#endif
440
}
441
 
442
// ---------------------------------------------------------------------------
443
// PDC_get_key --
444
//
445
// Get the next available key, or mouse event (indicated by a return of
446
// KEY_MOUSE), and remove it from the OS' input queue, if applicable. This
447
// function is called from wgetch(). This function may be blocking, and
448
// traditionally is; but it need not be. If a valid key or mouse event cannot
449
// be returned, for any reason, this function returns -1. For more details
450
// read `pdcurses/IMPLEMNT' document.
451
// ---------------------------------------------------------------------------
452
 
453
int
454
PDC_get_key(void)
455
{
456
#ifndef ENABLE_KEYPAD
457
    int             input = 0;
458
    unsigned int    count = 1;
459
 
460
    if (ENOERR == cyg_io_read(handle, &input, &count))
461
        return input;
462
 
463
    return ERR;
464
#else
465
    return key_code;
466
#endif                          // ENABLE_KEYPAD
467
}
468
 
469
// ---------------------------------------------------------------------------
470
// PDC_modifiers_set --
471
//
472
// Called from PDC_return_key_modifiers(). If your platform needs to do
473
// anything in response to a change in SP->return_key_modifiers, do it here.
474
// Returns OK or ERR, which is passed on by the caller.
475
// ---------------------------------------------------------------------------
476
 
477
int
478
PDC_modifiers_set(void)
479
{
480
    return ERR;
481
}
482
 
483
// ---------------------------------------------------------------------------
484
// PDC_mouse_set --
485
//
486
// Called by mouse_set(), mouse_on(), and mouse_off() -- all the functions
487
// that modify SP->_trap_mbe. If your platform needs to do anything in
488
// response to a change in SP->_trap_mbe (for example, turning the mouse
489
// cursor on or off), do it here. Returns OK or ERR, which is passed on by
490
// the caller.
491
// ---------------------------------------------------------------------------
492
 
493
int
494
PDC_mouse_set(void)
495
{
496
    return ERR;
497
}
498
 
499
// ---------------------------------------------------------------------------
500
// PDC_set_keyboard_binary --
501
//
502
// Set keyboard input to "binary" mode. If you need to do something to keep
503
// the OS from processing ^C, etc. on your platform, do it here. TRUE turns
504
// the mode on; FALSE reverts it. This function is called from raw() and
505
// noraw().
506
// ---------------------------------------------------------------------------
507
 
508
void
509
PDC_set_keyboard_binary(bool on)
510
{
511
#ifdef DEBUF
512
    diag_printf("PDC_set_keyboard_binary() called: on %d\n", on);
513
#endif
514
}
515
 
516
// ---------------------------------------------------------------------------
517
// PDC_can_change_color --
518
//
519
// Returns TRUE if init_color() and color_content() give meaningful results,
520
// FALSE otherwise. Called from can_change_color().
521
// ---------------------------------------------------------------------------
522
 
523
bool
524
PDC_can_change_color(void)
525
{
526
    return FALSE;
527
}
528
 
529
// ---------------------------------------------------------------------------
530
// PDC_color_content --
531
//
532
// The core of color_content(). This does all the work of that function,
533
// except checking for values out of range and null pointers.
534
// ---------------------------------------------------------------------------
535
 
536
int
537
PDC_color_content(short color, short *red, short *green, short *blue)
538
{
539
    return ERR;
540
}
541
 
542
// ---------------------------------------------------------------------------
543
// PDC_init_color --
544
//
545
// The core of init_color(). This does all the work of that function, except
546
// checking for values out of range.
547
// ---------------------------------------------------------------------------
548
 
549
int
550
PDC_init_color(short color, short red, short green, short blue)
551
{
552
    return ERR;
553
}
554
 
555
// ---------------------------------------------------------------------------
556
// PDC_init_pair --
557
//
558
// The core of init_pair(). This does all the work of that function, except
559
// checking for values out of range. The values passed to this function
560
// should be returned by a call to PDC_pair_content() with the same pair
561
// number. PDC_transform_line() should use the specified colors when
562
// rendering a chtype with the given pair number.
563
// ---------------------------------------------------------------------------
564
 
565
void
566
PDC_init_pair(short pair, short fg, short bg)
567
{
568
#ifdef DEBUG
569
    diag_printf("PDC_init_pair called: pair %d fg %d bg %d\n", pair, fg,
570
                bg);
571
#endif
572
 
573
    atrtab[pair].f = fg;
574
    atrtab[pair].b = bg;
575
}
576
 
577
// ---------------------------------------------------------------------------
578
// PDC_pair_content --
579
//
580
// The core of pair_content(). This does all the work of that function,
581
// except checking for values out of range and null pointers.
582
// ---------------------------------------------------------------------------
583
 
584
int
585
PDC_pair_content(short pair, short *fg, short *bg)
586
{
587
    *fg = atrtab[pair].f;
588
    *bg = atrtab[pair].b;
589
 
590
    return OK;
591
}
592
 
593
// ---------------------------------------------------------------------------
594
// PDC_reset_prog_mode --
595
//
596
// The non-portable functionality of reset_prog_mode() is handled here --
597
// whatever's not done in _restore_mode(). In current ports: In OS/2, this
598
// sets the keyboard to binary mode; in Win32, it enables or disables the
599
// mouse pointer to match the saved mode; in others it does nothing.
600
// ---------------------------------------------------------------------------
601
 
602
void
603
PDC_reset_prog_mode(void)
604
{
605
}
606
 
607
// ---------------------------------------------------------------------------
608
// PDC_reset_shell_mode --
609
//
610
// The same thing, for reset_shell_mode(). In OS/2 and Win32, it restores the
611
// default console mode; in others it does nothing.
612
// ---------------------------------------------------------------------------
613
 
614
void
615
PDC_reset_shell_mode(void)
616
{
617
}
618
 
619
// ---------------------------------------------------------------------------
620
// PDC_resize_screen --
621
//
622
// This does the main work of resize_term(). It may respond to non-zero
623
// parameters, by setting the screen to the specified size; to zero
624
// parameters, by setting the screen to a size chosen by the user at runtime,
625
// in an unspecified way (e.g., by dragging the edges of the window); or
626
// both. It may also do nothing, if there's no appropriate action for the
627
// platform.
628
// ---------------------------------------------------------------------------
629
 
630
int
631
PDC_resize_screen(int nlines, int ncols)
632
{
633
    if (nlines == 0 && ncols == 0)
634
        return OK;
635
 
636
    SP->resized = FALSE;
637
    SP->cursrow = SP->curscol = 0;
638
 
639
    return OK;
640
 
641
}
642
 
643
// ---------------------------------------------------------------------------
644
// PDC_restore_screen_mode --
645
//
646
// Called from _restore_mode() in kernel.c, this function does the actual
647
// mode changing, if applicable. Currently used only in DOS and OS/2.
648
// ---------------------------------------------------------------------------
649
 
650
void
651
PDC_restore_screen_mode(int i)
652
{
653
}
654
 
655
// ---------------------------------------------------------------------------
656
// PDC_save_screen_mode --
657
//
658
// Called from _save_mode() in kernel.c, this function saves the actual
659
// screen mode, if applicable. Currently used only in DOS and OS/2.
660
// ---------------------------------------------------------------------------
661
 
662
void
663
PDC_save_screen_mode(int i)
664
{
665
}
666
 
667
// ---------------------------------------------------------------------------
668
// PDC_scr_close --
669
//
670
// The platform-specific part of endwin(). It may restore the image of the
671
// original screen saved by PDC_scr_open(), if the PDC_RESTORE_SCREEN
672
// environment variable is set; either way, if using an existing terminal,
673
// this function should restore it to the mode it had at startup, and move
674
// the cursor to the lower left corner. (The X11 port does nothing.)
675
// ---------------------------------------------------------------------------
676
 
677
void
678
PDC_scr_close(void)
679
{
680
    handle = NULL;
681
}
682
 
683
// ---------------------------------------------------------------------------
684
// PDC_scr_free --
685
//
686
// Frees the memory for SP allocated by PDC_scr_open(). Called by
687
// delscreen().
688
// ---------------------------------------------------------------------------
689
 
690
void
691
PDC_scr_free(void)
692
{
693
#ifdef DEBUG
694
    diag_printf("PDC_scr_free called\n");
695
#endif
696
 
697
    if (SP)
698
        free(SP);
699
}
700
 
701
// ---------------------------------------------------------------------------
702
// PDC_scr_open --
703
//
704
// The platform-specific part of initscr(). It's actually called from
705
// Xinitscr(); the arguments, if present, correspond to those used with
706
// main(), and may be used to set the title of the terminal window, or for
707
// other, platform-specific purposes.
708
// ---------------------------------------------------------------------------
709
 
710
int
711
PDC_scr_open(int argc, char **argv)
712
{
713
    static bool     acs_map_init = false;
714
 
715
    int             i = 0;
716
 
717
#ifdef DEBUG
718
    diag_printf("PDC_scr_open called\n");
719
#endif
720
 
721
    if (NULL == handle) {
722
        unsigned int    wait = 0;
723
        unsigned int    len = sizeof(wait);
724
 
725
        if (ENOERR != cyg_io_lookup(device, &handle))
726
            return ERR;
727
 
728
        cyg_io_set_config(handle,
729
                          CYG_IO_SET_CONFIG_READ_BLOCKING, &wait, &len);
730
    }
731
 
732
    SP = calloc(1, sizeof(SCREEN));
733
 
734
    if (!SP)
735
        return ERR;
736
 
737
    SP->cols = PDC_get_columns();
738
    SP->lines = PDC_get_rows();
739
    SP->cursrow = SP->curscol = 0;
740
    SP->raw_inp = SP->raw_out = TRUE;
741
 
742
    if (!acs_map_init)
743
        for (i = 0; i < 128; i++) {
744
            // Square shapes, no more
745
            switch (i) {
746
            case 'j':
747
            case 'k':
748
            case 'l':
749
            case 'm':
750
                acs_map[i] = '+';
751
                break;
752
            case 'q':
753
                acs_map[i] = '-';
754
                break;
755
            case 'x':
756
                acs_map[i] = '|';
757
                break;
758
            default:
759
                acs_map[i] = (chtype) i | A_ALTCHARSET;
760
            }
761
        }
762
 
763
    return OK;
764
}
765
 
766
// ---------------------------------------------------------------------------
767
// PDC_curs_set --
768
//
769
// Called from curs_set(). Changes the appearance of the cursor -- 0 turns it
770
// off, 1 is normal (the terminal's default, if applicable, as determined by
771
// SP->orig_cursor), and 2 is high visibility. The exact appearance of these
772
// modes is not specified.
773
// ---------------------------------------------------------------------------
774
 
775
int
776
PDC_curs_set(int visibility)
777
{
778
    int             vis;
779
    char            buf[6] = { '\033', '[', '?', '2', '5', 'h' };
780
    unsigned int    len = sizeof(buf);
781
 
782
#ifdef DEBUG
783
    diag_printf("PDC_curs_set called: visibility %d\n", visibility);
784
#endif
785
 
786
    vis = SP->visibility;
787
 
788
    if (visibility)
789
        // <ESC>[?25h -- show cursor
790
        buf[5] = 'h';
791
    else
792
        // <ESC>[?25l -- hide cursor
793
        buf[5] = 'l';
794
 
795
    cyg_io_write(handle, buf, &len);
796
    cyg_io_get_config(handle, CYG_IO_GET_CONFIG_SERIAL_OUTPUT_DRAIN, NULL,
797
                      NULL);
798
 
799
    SP->visibility = vis;
800
 
801
    return vis;
802
}
803
 
804
// ---------------------------------------------------------------------------
805
// PDC_beep --
806
//
807
// Emits a short audible beep. If this is not possible on your platform, you
808
// must set SP->audible to FALSE during initialization (i.e., from
809
// PDC_scr_open() -- not here); otherwise, set it to TRUE. This function is
810
// called from beep().
811
// ---------------------------------------------------------------------------
812
 
813
void
814
PDC_beep(void)
815
{
816
    char            buf[1] = { '\007' };
817
    unsigned int    len = 1;
818
 
819
    cyg_io_write(handle, buf, &len);
820
    cyg_io_get_config(handle, CYG_IO_GET_CONFIG_SERIAL_OUTPUT_DRAIN, NULL,
821
                      NULL);
822
}
823
 
824
// ---------------------------------------------------------------------------
825
// PDC_napms --
826
//
827
// This is the core delay routine, called by napms(). It pauses for about
828
// (the X/Open spec says "at least") ms milliseconds, then returns. High
829
// degrees of accuracy and precision are not expected (though desirable, if
830
// you can achieve them). More important is that this function gives back the
831
// process' time slice to the OS, so that PDCurses idles at low CPU usage.
832
// ---------------------------------------------------------------------------
833
 
834
void
835
PDC_napms(int ms)
836
{
837
 
838
    // There is alone call of napms() in current PDCurses implementation, its
839
    // aragument is 50 (50 of 1/20th second ticks).
840
 
841
    cyg_thread_delay(ms / 10);
842
}
843
 
844
// ---------------------------------------------------------------------------
845
// PDC_sysname --
846
//
847
// Returns a short string describing the platform, such as "DOS" or "X11".
848
// This is used by longname(). It must be no more than 100 characters; it
849
// should be much, much shorter (existing platforms use no more than 5).
850
// ---------------------------------------------------------------------------
851
 
852
const char     *
853
PDC_sysname(void)
854
{
855
    return "ECOS";
856
}
857
 
858
// ---------------------------------------------------------------------------
859
// PDC_getclipboard, PDC_clearclipboard, PDC_freeclipboard PDC_setclipboard,
860
// PDC_get_input_fd, PDC_set_blink, PDC_set_title --
861
//
862
// The following functions are implemented in the platform directories, but
863
// are accessed directly by apps. Refer to the user documentation for their
864
// descriptions:
865
// ---------------------------------------------------------------------------
866
 
867
// ---------------------------------------------------------------------------
868
// PDC_getclipboard --
869
//
870
int
871
PDC_getclipboard(char **contents, long *length)
872
{
873
    return PDC_CLIP_ACCESS_ERROR;
874
}
875
 
876
// ---------------------------------------------------------------------------
877
// PDC_clearclipboard --
878
//
879
int
880
PDC_clearclipboard(void)
881
{
882
    return PDC_CLIP_ACCESS_ERROR;
883
}
884
 
885
// ---------------------------------------------------------------------------
886
// PDC_freeclipboard --
887
//
888
int
889
PDC_freeclipboard(char *contents)
890
{
891
    return PDC_CLIP_ACCESS_ERROR;
892
}
893
 
894
// ---------------------------------------------------------------------------
895
// PDC_setclipboard --
896
//
897
int
898
PDC_setclipboard(const char *contents, long length)
899
{
900
    return PDC_CLIP_ACCESS_ERROR;
901
}
902
 
903
// ---------------------------------------------------------------------------
904
// PDC_get_input_fd --
905
//
906
unsigned long
907
PDC_get_input_fd(void)
908
{
909
    return -1;
910
}
911
 
912
// ---------------------------------------------------------------------------
913
// PDC_set_blink --
914
//
915
int
916
PDC_set_blink(bool blinkon)
917
{
918
#ifdef DEBUG
919
    diag_printf("PDC_set_blink called: blinkon %d\n", blinkon);
920
#endif
921
 
922
    // start_color() guides that PDC_set_blink() should also set COLORS, to 8
923
    // or 16.
924
#ifdef ENABLE_COLOR
925
    COLORS = 8;
926
#else
927
    COLORS = 0;
928
#endif
929
 
930
    return blinkon ? ERR : OK;
931
}
932
 
933
// ---------------------------------------------------------------------------
934
// PDC_set_title --
935
//
936
void
937
PDC_set_title(const char *title)
938
{
939
}
940
 
941
// ---------------------------------------------------------------------------
942
// EOF serial.c

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.