[7c014d1] | 1 | /*
|
---|
| 2 | * Copyright (c) 2006 Ondrej Palkovsky
|
---|
| 3 | * Copyright (c) 2008 Martin Decky
|
---|
| 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
[4122410] | 30 | /** @addtogroup output
|
---|
[6d5e378] | 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /**
|
---|
| 34 | * @file
|
---|
[7c014d1] | 35 | */
|
---|
| 36 |
|
---|
| 37 | #include <errno.h>
|
---|
[6d5e378] | 38 | #include <io/chargrid.h>
|
---|
| 39 | #include "../output.h"
|
---|
[7c014d1] | 40 | #include "../proto/vt100.h"
|
---|
| 41 | #include "serial.h"
|
---|
| 42 |
|
---|
[6d5e378] | 43 | #define SERIAL_COLS 80
|
---|
| 44 | #define SERIAL_ROWS 24
|
---|
| 45 |
|
---|
| 46 | /** Draw the character at the specified position.
|
---|
[7c014d1] | 47 | *
|
---|
| 48 | * @param state VT100 protocol state.
|
---|
[6d5e378] | 49 | * @param field Character field.
|
---|
| 50 | * @param col Horizontal screen position.
|
---|
| 51 | * @param row Vertical screen position.
|
---|
[7c014d1] | 52 | *
|
---|
| 53 | */
|
---|
[6d5e378] | 54 | static void draw_char(vt100_state_t *state, charfield_t *field,
|
---|
| 55 | sysarg_t col, sysarg_t row)
|
---|
[7c014d1] | 56 | {
|
---|
[6d5e378] | 57 | vt100_goto(state, col, row);
|
---|
[7c014d1] | 58 | vt100_set_attr(state, field->attrs);
|
---|
[28a5ebd] | 59 | vt100_putuchar(state, field->ch);
|
---|
[7c014d1] | 60 | }
|
---|
| 61 |
|
---|
[b7fd2a0] | 62 | static errno_t serial_yield(outdev_t *dev)
|
---|
[7c014d1] | 63 | {
|
---|
| 64 | vt100_state_t *state = (vt100_state_t *) dev->data;
|
---|
[a35b458] | 65 |
|
---|
[7c014d1] | 66 | return vt100_yield(state);
|
---|
| 67 | }
|
---|
| 68 |
|
---|
[b7fd2a0] | 69 | static errno_t serial_claim(outdev_t *dev)
|
---|
[7c014d1] | 70 | {
|
---|
| 71 | vt100_state_t *state = (vt100_state_t *) dev->data;
|
---|
[a35b458] | 72 |
|
---|
[6d5e378] | 73 | return vt100_claim(state);
|
---|
[7c014d1] | 74 | }
|
---|
| 75 |
|
---|
[6d5e378] | 76 | static void serial_get_dimensions(outdev_t *dev, sysarg_t *cols,
|
---|
| 77 | sysarg_t *rows)
|
---|
[7c014d1] | 78 | {
|
---|
| 79 | vt100_state_t *state = (vt100_state_t *) dev->data;
|
---|
[a35b458] | 80 |
|
---|
[6d5e378] | 81 | vt100_get_dimensions(state, cols, rows);
|
---|
[7c014d1] | 82 | }
|
---|
| 83 |
|
---|
[6d5e378] | 84 | static console_caps_t serial_get_caps(outdev_t *dev)
|
---|
[7c014d1] | 85 | {
|
---|
| 86 | return (CONSOLE_CAP_STYLE | CONSOLE_CAP_INDEXED);
|
---|
| 87 | }
|
---|
| 88 |
|
---|
[6d5e378] | 89 | static void serial_cursor_update(outdev_t *dev, sysarg_t prev_col,
|
---|
| 90 | sysarg_t prev_row, sysarg_t col, sysarg_t row, bool visible)
|
---|
[7c014d1] | 91 | {
|
---|
| 92 | vt100_state_t *state = (vt100_state_t *) dev->data;
|
---|
[a35b458] | 93 |
|
---|
[6d5e378] | 94 | vt100_goto(state, col, row);
|
---|
[7c014d1] | 95 | vt100_cursor_visibility(state, visible);
|
---|
| 96 | }
|
---|
| 97 |
|
---|
[6d5e378] | 98 | static void serial_char_update(outdev_t *dev, sysarg_t col, sysarg_t row)
|
---|
[7c014d1] | 99 | {
|
---|
| 100 | vt100_state_t *state = (vt100_state_t *) dev->data;
|
---|
[6d5e378] | 101 | charfield_t *field =
|
---|
| 102 | chargrid_charfield_at(dev->backbuf, col, row);
|
---|
[a35b458] | 103 |
|
---|
[6d5e378] | 104 | draw_char(state, field, col, row);
|
---|
[7c014d1] | 105 | }
|
---|
| 106 |
|
---|
[bbc6277] | 107 | static void serial_flush(outdev_t *dev)
|
---|
| 108 | {
|
---|
| 109 | vt100_state_t *state = (vt100_state_t *) dev->data;
|
---|
| 110 |
|
---|
| 111 | vt100_flush(state);
|
---|
| 112 | }
|
---|
| 113 |
|
---|
[6d5e378] | 114 | static outdev_ops_t serial_ops = {
|
---|
[7c014d1] | 115 | .yield = serial_yield,
|
---|
| 116 | .claim = serial_claim,
|
---|
[6d5e378] | 117 | .get_dimensions = serial_get_dimensions,
|
---|
| 118 | .get_caps = serial_get_caps,
|
---|
| 119 | .cursor_update = serial_cursor_update,
|
---|
[bbc6277] | 120 | .char_update = serial_char_update,
|
---|
| 121 | .flush = serial_flush
|
---|
[7c014d1] | 122 | };
|
---|
| 123 |
|
---|
[28a5ebd] | 124 | errno_t serial_init(vt100_putuchar_t putuchar_fn,
|
---|
[bbc6277] | 125 | vt100_control_puts_t control_puts_fn, vt100_flush_t flush_fn)
|
---|
[7c014d1] | 126 | {
|
---|
| 127 | vt100_state_t *state =
|
---|
[28a5ebd] | 128 | vt100_state_create(SERIAL_COLS, SERIAL_ROWS, putuchar_fn,
|
---|
[bbc6277] | 129 | control_puts_fn, flush_fn);
|
---|
[7c014d1] | 130 | if (state == NULL)
|
---|
| 131 | return ENOMEM;
|
---|
[a35b458] | 132 |
|
---|
[6d5e378] | 133 | outdev_t *dev = outdev_register(&serial_ops, state);
|
---|
| 134 | if (dev == NULL) {
|
---|
| 135 | vt100_state_destroy(state);
|
---|
| 136 | return ENOMEM;
|
---|
| 137 | }
|
---|
[a35b458] | 138 |
|
---|
[7c014d1] | 139 | return EOK;
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | /** @}
|
---|
| 143 | */
|
---|