Changeset 52c4264 in mainline for uspace/srv/hid/output/port/ega.c
- Timestamp:
- 2012-08-17T12:23:52Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 267f235
- Parents:
- ae2c925 (diff), ad78054 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/output/port/ega.c
rae2c925 r52c4264 33 33 #include <errno.h> 34 34 #include <sysinfo.h> 35 #include <task.h> 35 #include <align.h> 36 #include <as.h> 36 37 #include <ddi.h> 37 38 #include <libarch/ddi.h> 38 #include <as.h> 39 #include <malloc.h> 40 #include <align.h> 41 #include <screenbuffer.h> 42 #include "../fb.h" 39 #include <io/chargrid.h> 40 #include "../output.h" 43 41 #include "ega.h" 44 42 … … 46 44 #define EGA_IO_SIZE 2 47 45 48 #define FB_POS(x, y) (((y) * ega. width+ (x)) << 1)46 #define FB_POS(x, y) (((y) * ega.cols + (x)) << 1) 49 47 50 48 typedef struct { 51 sysarg_t width; 52 sysarg_t height; 49 sysarg_t cols; 50 sysarg_t rows; 51 52 uint8_t style_normal; 53 uint8_t style_inverted; 53 54 54 55 size_t size; 55 56 uint8_t *addr; 56 57 uint8_t style_normal;58 uint8_t style_inverted;59 60 uint8_t *backbuf;61 57 } ega_t; 62 58 … … 101 97 } 102 98 103 /** Draw the character at the specified position in viewport. 104 * 105 * @param vp Viewport. 106 * @param col Screen position relative to viewport. 107 * @param row Screen position relative to viewport. 108 * 109 */ 110 static void draw_vp_char(fbvp_t *vp, sysarg_t col, sysarg_t row) 111 { 112 sysarg_t x = vp->x + col; 113 sysarg_t y = vp->y + row; 114 115 charfield_t *field = screenbuffer_field_at(vp->backbuf, col, row); 116 99 /** Draw the character at the specified position. 100 * 101 * @param field Character field. 102 * @param col Horizontal screen position. 103 * @param row Vertical screen position. 104 * 105 */ 106 static void draw_char(charfield_t *field, sysarg_t col, sysarg_t row) 107 { 117 108 uint8_t glyph; 118 109 … … 124 115 uint8_t attr = attrs_attr(field->attrs); 125 116 126 ega.addr[FB_POS(x, y)] = glyph; 127 ega.addr[FB_POS(x, y) + 1] = attr; 128 } 129 130 static int ega_yield(fbdev_t *dev) 131 { 132 if (ega.backbuf == NULL) { 133 ega.backbuf = malloc(ega.size); 134 if (ega.backbuf == NULL) 135 return ENOMEM; 136 } 137 138 memcpy(ega.backbuf, ega.addr, ega.size); 117 ega.addr[FB_POS(col, row)] = glyph; 118 ega.addr[FB_POS(col, row) + 1] = attr; 119 } 120 121 static int ega_yield(outdev_t *dev) 122 { 139 123 return EOK; 140 124 } 141 125 142 static int ega_claim(fbdev_t *dev) 143 { 144 if (ega.backbuf == NULL) 145 return ENOENT; 146 147 memcpy(ega.addr, ega.backbuf, ega.size); 126 static int ega_claim(outdev_t *dev) 127 { 148 128 return EOK; 149 129 } 150 130 151 static int ega_get_resolution(fbdev_t *dev, sysarg_t *width, sysarg_t *height) 152 { 153 *width = ega.width; 154 *height = ega.height; 155 return EOK; 156 } 157 158 static void ega_font_metrics(fbdev_t *dev, sysarg_t width, sysarg_t height, 159 sysarg_t *cols, sysarg_t *rows) 160 { 161 *cols = width; 162 *rows = height; 163 } 164 165 static int ega_vp_create(fbdev_t *dev, fbvp_t *vp) 166 { 167 vp->attrs.type = CHAR_ATTR_STYLE; 168 vp->attrs.val.style = STYLE_NORMAL; 169 vp->data = NULL; 170 171 return EOK; 172 } 173 174 static void ega_vp_destroy(fbdev_t *dev, fbvp_t *vp) 175 { 176 /* No-op */ 177 } 178 179 static void ega_vp_clear(fbdev_t *dev, fbvp_t *vp) 180 { 181 for (sysarg_t row = 0; row < vp->rows; row++) { 182 for (sysarg_t col = 0; col < vp->cols; col++) { 183 charfield_t *field = 184 screenbuffer_field_at(vp->backbuf, col, row); 185 186 field->ch = 0; 187 field->attrs = vp->attrs; 188 189 draw_vp_char(vp, col, row); 190 } 191 } 192 } 193 194 static console_caps_t ega_vp_get_caps(fbdev_t *dev, fbvp_t *vp) 131 static void ega_get_dimensions(outdev_t *dev, sysarg_t *cols, sysarg_t *rows) 132 { 133 *cols = ega.cols; 134 *rows = ega.rows; 135 } 136 137 static console_caps_t ega_get_caps(outdev_t *dev) 195 138 { 196 139 return (CONSOLE_CAP_STYLE | CONSOLE_CAP_INDEXED); 197 140 } 198 141 199 static void ega_ vp_cursor_update(fbdev_t *dev, fbvp_t *vp, sysarg_t prev_col,142 static void ega_cursor_update(outdev_t *dev, sysarg_t prev_col, 200 143 sysarg_t prev_row, sysarg_t col, sysarg_t row, bool visible) 201 144 { 202 145 /* Cursor position */ 203 uint16_t cursor = row * ega. width+ col;146 uint16_t cursor = row * ega.cols + col; 204 147 205 148 pio_write_8(EGA_IO_BASE, 0x0e); … … 220 163 } 221 164 222 static void ega_vp_char_update(fbdev_t *dev, fbvp_t *vp, sysarg_t col, 223 sysarg_t row) 224 { 225 draw_vp_char(vp, col, row); 226 } 227 228 static fbdev_ops_t ega_ops = { 165 static void ega_char_update(outdev_t *dev, sysarg_t col, sysarg_t row) 166 { 167 charfield_t *field = 168 chargrid_charfield_at(dev->backbuf, col, row); 169 170 draw_char(field, col, row); 171 } 172 173 static outdev_ops_t ega_ops = { 229 174 .yield = ega_yield, 230 175 .claim = ega_claim, 231 .get_resolution = ega_get_resolution, 232 .font_metrics = ega_font_metrics, 233 .vp_create = ega_vp_create, 234 .vp_destroy = ega_vp_destroy, 235 .vp_clear = ega_vp_clear, 236 .vp_get_caps = ega_vp_get_caps, 237 .vp_cursor_update = ega_vp_cursor_update, 238 .vp_char_update = ega_vp_char_update 176 .get_dimensions = ega_get_dimensions, 177 .get_caps = ega_get_caps, 178 .cursor_update = ega_cursor_update, 179 .char_update = ega_char_update 239 180 }; 240 181 … … 262 203 return rc; 263 204 264 sysarg_t width; 265 rc = sysinfo_get_value("fb.width", &width); 266 if (rc != EOK) 267 return rc; 268 269 sysarg_t height; 270 rc = sysinfo_get_value("fb.height", &height); 271 if (rc != EOK) 272 return rc; 273 274 rc = iospace_enable(task_get_id(), (void *) EGA_IO_BASE, EGA_IO_SIZE); 275 if (rc != EOK) 276 return rc; 277 278 ega.width = width; 279 ega.height = height; 280 281 ega.size = (width * height) << 1; 205 rc = sysinfo_get_value("fb.width", &ega.cols); 206 if (rc != EOK) 207 return rc; 208 209 rc = sysinfo_get_value("fb.height", &ega.rows); 210 if (rc != EOK) 211 return rc; 212 213 rc = iospace_enable(task_get_id(), (void *) EGA_IO_BASE, 214 EGA_IO_SIZE); 215 if (rc != EOK) 216 return rc; 217 218 ega.size = (ega.cols * ega.rows) << 1; 282 219 283 220 rc = physmem_map((void *) paddr, … … 300 237 } 301 238 302 ega.backbuf = NULL; 303 304 fbdev_t *dev = fbdev_register(&ega_ops, (void *) &ega); 239 outdev_t *dev = outdev_register(&ega_ops, (void *) &ega); 305 240 if (dev == NULL) { 306 241 as_area_destroy(ega.addr); … … 311 246 } 312 247 313 /** 314 * @} 315 */ 248 /** @} 249 */
Note:
See TracChangeset
for help on using the changeset viewer.