[565] | 1 | /* |
---|
[672] | 2 | * libcaca Colour ASCII-Art library |
---|
[565] | 3 | * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> |
---|
| 4 | * All Rights Reserved |
---|
| 5 | * |
---|
[769] | 6 | * $Id: driver_vga.c 2049 2007-11-25 11:11:54Z sam $ |
---|
| 7 | * |
---|
[1462] | 8 | * This library is free software. It comes without any warranty, to |
---|
[1452] | 9 | * the extent permitted by applicable law. You can redistribute it |
---|
| 10 | * and/or modify it under the terms of the Do What The Fuck You Want |
---|
| 11 | * To Public License, Version 2, as published by Sam Hocevar. See |
---|
[565] | 12 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
---|
| 13 | */ |
---|
| 14 | |
---|
[769] | 15 | /* |
---|
[565] | 16 | * This file contains the libcaca VGA input and output driver |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | #include "config.h" |
---|
[859] | 20 | #include "common.h" |
---|
[565] | 21 | |
---|
| 22 | #if defined(USE_VGA) |
---|
| 23 | |
---|
| 24 | #include "caca.h" |
---|
| 25 | #include "caca_internals.h" |
---|
| 26 | #include "cucul.h" |
---|
| 27 | #include "cucul_internals.h" |
---|
| 28 | |
---|
| 29 | /* Address of the VGA screen */ |
---|
| 30 | #define VGA_SCREEN ((char *)(intptr_t)0x000b8000) |
---|
| 31 | |
---|
| 32 | static uint8_t const vga_colors[][4] = |
---|
| 33 | { |
---|
[574] | 34 | /* Colour values range from 0x00 to 0x3f */ |
---|
| 35 | { 0, 0x00, 0x00, 0x00 }, |
---|
| 36 | { 1, 0x00, 0x00, 0x1f }, |
---|
| 37 | { 2, 0x00, 0x1f, 0x00 }, |
---|
| 38 | { 3, 0x00, 0x1f, 0x1f }, |
---|
| 39 | { 4, 0x1f, 0x00, 0x00 }, |
---|
| 40 | { 5, 0x1f, 0x00, 0x1f }, |
---|
| 41 | { 0x14, 0x1f, 0x1f, 0x00 }, |
---|
| 42 | { 7, 0x1f, 0x1f, 0x1f }, |
---|
[565] | 43 | |
---|
[574] | 44 | { 0x38, 0x0f, 0x0f, 0x0f }, |
---|
| 45 | { 0x39, 0x0f, 0x0f, 0x3f }, |
---|
| 46 | { 0x3a, 0x0f, 0x3f, 0x0f }, |
---|
| 47 | { 0x3b, 0x0f, 0x3f, 0x3f }, |
---|
| 48 | { 0x3c, 0x3f, 0x0f, 0x0f }, |
---|
| 49 | { 0x3d, 0x3f, 0x0f, 0x3f }, |
---|
| 50 | { 0x3e, 0x3f, 0x3f, 0x0f }, |
---|
| 51 | { 0x3f, 0x3f, 0x3f, 0x3f }, |
---|
[565] | 52 | }; |
---|
| 53 | |
---|
[811] | 54 | static int vga_init_graphics(caca_display_t *dp) |
---|
[565] | 55 | { |
---|
| 56 | int i; |
---|
| 57 | uint8_t tmp; |
---|
| 58 | |
---|
| 59 | /* Blank screen */ |
---|
| 60 | memset(VGA_SCREEN, 0, 80 * 25 * 2); |
---|
| 61 | |
---|
| 62 | /* Fill VGA palette */ |
---|
| 63 | for(i = 0; i < 16; i++) |
---|
| 64 | { |
---|
| 65 | outb(vga_colors[i][0], 0x3c8); |
---|
| 66 | outb(vga_colors[i][1], 0x3c9); |
---|
| 67 | outb(vga_colors[i][2], 0x3c9); |
---|
| 68 | outb(vga_colors[i][3], 0x3c9); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | /* Hide cursor */ |
---|
| 72 | outb(0x0a, 0x3d4); |
---|
| 73 | tmp = inb(0x3d5); |
---|
| 74 | tmp |= 0x20; |
---|
| 75 | outb(0x0a, 0x3d4); |
---|
| 76 | outb(tmp, 0x3d5); |
---|
| 77 | |
---|
[580] | 78 | /* We don't have much choice */ |
---|
[2040] | 79 | __cucul_set_canvas_size(dp->cv, 80, 25); |
---|
[580] | 80 | |
---|
[565] | 81 | return 0; |
---|
| 82 | } |
---|
| 83 | |
---|
[811] | 84 | static int vga_end_graphics(caca_display_t *dp) |
---|
[565] | 85 | { |
---|
| 86 | uint8_t tmp; |
---|
| 87 | |
---|
| 88 | /* Show cursor again */ |
---|
| 89 | outb(0x0a, 0x3d4); |
---|
| 90 | tmp = inb(0x3d5); |
---|
| 91 | tmp &= 0xdf; |
---|
| 92 | outb(0x0a, 0x3d4); |
---|
| 93 | outb(tmp, 0x3d5); |
---|
| 94 | |
---|
| 95 | return 0; |
---|
| 96 | } |
---|
| 97 | |
---|
[819] | 98 | static int vga_set_display_title(caca_display_t *dp, char const *title) |
---|
[565] | 99 | { |
---|
| 100 | /* Unsupported, of course. */ |
---|
[1006] | 101 | return -1; |
---|
[565] | 102 | } |
---|
| 103 | |
---|
[2043] | 104 | static unsigned int vga_get_display_width(caca_display_t const *dp) |
---|
[565] | 105 | { |
---|
[580] | 106 | /* Fallback to a 320x200 screen */ |
---|
| 107 | return 320; |
---|
[565] | 108 | } |
---|
| 109 | |
---|
[2043] | 110 | static unsigned int vga_get_display_height(caca_display_t const *dp) |
---|
[565] | 111 | { |
---|
[580] | 112 | /* Fallback to a 320x200 screen */ |
---|
| 113 | return 200; |
---|
[565] | 114 | } |
---|
| 115 | |
---|
[811] | 116 | static void vga_display(caca_display_t *dp) |
---|
[565] | 117 | { |
---|
| 118 | char *screen = (char *)(intptr_t)0x000b8000; |
---|
[1254] | 119 | uint32_t *attrs = dp->cv->attrs; |
---|
[811] | 120 | uint32_t *chars = dp->cv->chars; |
---|
[565] | 121 | int n; |
---|
| 122 | |
---|
[811] | 123 | for(n = dp->cv->height * dp->cv->width; n--; ) |
---|
[565] | 124 | { |
---|
[1218] | 125 | char ch = cucul_utf32_to_cp437(*chars++); |
---|
| 126 | if(n && *chars == CUCUL_MAGIC_FULLWIDTH) |
---|
| 127 | { |
---|
| 128 | *screen++ = '['; |
---|
[1333] | 129 | *screen++ = cucul_attr_to_ansi(*attrs++); |
---|
[1218] | 130 | ch = ']'; |
---|
| 131 | chars++; |
---|
| 132 | n--; |
---|
| 133 | } |
---|
| 134 | *screen++ = ch; |
---|
[1333] | 135 | *screen++ = cucul_attr_to_ansi(*attrs++); |
---|
[565] | 136 | } |
---|
| 137 | } |
---|
| 138 | |
---|
[811] | 139 | static void vga_handle_resize(caca_display_t *dp) |
---|
[565] | 140 | { |
---|
| 141 | /* We know nothing about our window */ |
---|
[811] | 142 | dp->resize.w = dp->cv->width; |
---|
| 143 | dp->resize.h = dp->cv->height; |
---|
[565] | 144 | } |
---|
| 145 | |
---|
[2049] | 146 | static int vga_get_event(caca_display_t *dp, caca_privevent_t *ev) |
---|
[565] | 147 | { |
---|
| 148 | /* FIXME */ |
---|
[681] | 149 | ev->type = CACA_EVENT_NONE; |
---|
| 150 | return 0; |
---|
[565] | 151 | } |
---|
| 152 | |
---|
| 153 | /* |
---|
| 154 | * Driver initialisation |
---|
| 155 | */ |
---|
| 156 | |
---|
[811] | 157 | int vga_install(caca_display_t *dp) |
---|
[565] | 158 | { |
---|
[811] | 159 | dp->drv.driver = CACA_DRIVER_VGA; |
---|
[565] | 160 | |
---|
[811] | 161 | dp->drv.init_graphics = vga_init_graphics; |
---|
| 162 | dp->drv.end_graphics = vga_end_graphics; |
---|
[819] | 163 | dp->drv.set_display_title = vga_set_display_title; |
---|
| 164 | dp->drv.get_display_width = vga_get_display_width; |
---|
| 165 | dp->drv.get_display_height = vga_get_display_height; |
---|
[811] | 166 | dp->drv.display = vga_display; |
---|
| 167 | dp->drv.handle_resize = vga_handle_resize; |
---|
| 168 | dp->drv.get_event = vga_get_event; |
---|
| 169 | dp->drv.set_mouse = NULL; |
---|
[1430] | 170 | dp->drv.set_cursor = NULL; |
---|
[684] | 171 | |
---|
| 172 | return 0; |
---|
[565] | 173 | } |
---|
| 174 | |
---|
| 175 | #endif /* USE_VGA */ |
---|
| 176 | |
---|