src/mess/video/apple1.c
| r6058 | r6059 | |
| 64 | 64 | #include "includes/apple1.h" |
| 65 | 65 | #include "mscommon.h" |
| 66 | 66 | |
| 67 | |
| 68 | /*************************************************************************** |
| 69 | |
| 70 | Terminal code |
| 71 | |
| 72 | ***************************************************************************/ |
| 73 | |
| 74 | typedef short termchar_t; |
| 75 | |
| 76 | struct terminal |
| 77 | { |
| 78 | tilemap *tm; |
| 79 | int gfx; |
| 80 | int blank_char; |
| 81 | int char_bits; |
| 82 | int num_cols; |
| 83 | int num_rows; |
| 84 | int (*getcursorcode)(int original_code); |
| 85 | int cur_offset; |
| 86 | int cur_hidden; |
| 87 | termchar_t mem[1]; |
| 88 | }; |
| 89 | |
| 90 | static struct terminal *current_terminal; |
| 91 | |
| 92 | static TILE_GET_INFO(terminal_gettileinfo) |
| 93 | { |
| 94 | int ch, gfxfont, code, color; |
| 95 | |
| 96 | ch = current_terminal->mem[tile_index]; |
| 97 | code = ch & ((1 << current_terminal->char_bits) - 1); |
| 98 | color = ch >> current_terminal->char_bits; |
| 99 | gfxfont = current_terminal->gfx; |
| 100 | |
| 101 | if ((tile_index == current_terminal->cur_offset) && !current_terminal->cur_hidden && current_terminal->getcursorcode) |
| 102 | code = current_terminal->getcursorcode(code); |
| 103 | |
| 104 | SET_TILE_INFO( |
| 105 | gfxfont, /* gfx */ |
| 106 | code, /* character */ |
| 107 | color, /* color */ |
| 108 | 0); /* flags */ |
| 109 | } |
| 110 | |
| 111 | static void terminal_draw(bitmap_t *dest, const rectangle *cliprect, struct terminal *terminal) |
| 112 | { |
| 113 | current_terminal = terminal; |
| 114 | tilemap_draw(dest, cliprect, terminal->tm, 0, 0); |
| 115 | current_terminal = NULL; |
| 116 | } |
| 117 | |
| 118 | static void verify_coords(struct terminal *terminal, int x, int y) |
| 119 | { |
| 120 | assert(x >= 0); |
| 121 | assert(y >= 0); |
| 122 | assert(x < terminal->num_cols); |
| 123 | assert(y < terminal->num_rows); |
| 124 | } |
| 125 | |
| 126 | static void terminal_putchar(struct terminal *terminal, int x, int y, int ch) |
| 127 | { |
| 128 | int offs; |
| 129 | |
| 130 | verify_coords(terminal, x, y); |
| 131 | |
| 132 | offs = y * terminal->num_cols + x; |
| 133 | if (terminal->mem[offs] != ch) |
| 134 | { |
| 135 | terminal->mem[offs] = ch; |
| 136 | tilemap_mark_tile_dirty(terminal->tm, offs); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | static int terminal_getchar(struct terminal *terminal, int x, int y) |
| 141 | { |
| 142 | int offs; |
| 143 | |
| 144 | verify_coords(terminal, x, y); |
| 145 | offs = y * terminal->num_cols + x; |
| 146 | return terminal->mem[offs]; |
| 147 | } |
| 148 | |
| 149 | static void terminal_putblank(struct terminal *terminal, int x, int y) |
| 150 | { |
| 151 | terminal_putchar(terminal, x, y, terminal->blank_char); |
| 152 | } |
| 153 | |
| 154 | static void terminal_dirtycursor(struct terminal *terminal) |
| 155 | { |
| 156 | if (terminal->cur_offset >= 0) |
| 157 | tilemap_mark_tile_dirty(terminal->tm, terminal->cur_offset); |
| 158 | } |
| 159 | |
| 160 | static void terminal_setcursor(struct terminal *terminal, int x, int y) |
| 161 | { |
| 162 | terminal_dirtycursor(terminal); |
| 163 | terminal->cur_offset = y * terminal->num_cols + x; |
| 164 | terminal_dirtycursor(terminal); |
| 165 | } |
| 166 | |
| 167 | static void terminal_hidecursor(struct terminal *terminal) |
| 168 | { |
| 169 | terminal->cur_hidden = 1; |
| 170 | terminal_dirtycursor(terminal); |
| 171 | } |
| 172 | |
| 173 | static void terminal_showcursor(struct terminal *terminal) |
| 174 | { |
| 175 | terminal->cur_hidden = 0; |
| 176 | terminal_dirtycursor(terminal); |
| 177 | } |
| 178 | |
| 179 | static void terminal_getcursor(struct terminal *terminal, int *x, int *y) |
| 180 | { |
| 181 | *x = terminal->cur_offset % terminal->num_cols; |
| 182 | *y = terminal->cur_offset / terminal->num_cols; |
| 183 | } |
| 184 | |
| 185 | static void terminal_fill(struct terminal *terminal, int val) |
| 186 | { |
| 187 | int i; |
| 188 | for (i = 0; i < terminal->num_cols * terminal->num_rows; i++) |
| 189 | terminal->mem[i] = val; |
| 190 | tilemap_mark_all_tiles_dirty(terminal->tm); |
| 191 | } |
| 192 | |
| 193 | static void terminal_clear(struct terminal *terminal) |
| 194 | { |
| 195 | terminal_fill(terminal, terminal->blank_char); |
| 196 | } |
| 197 | |
| 198 | struct terminal *terminal_create( |
| 199 | running_machine *machine, |
| 200 | int gfx, int blank_char, int char_bits, |
| 201 | int (*getcursorcode)(int original_code), |
| 202 | int num_cols, int num_rows) |
| 203 | { |
| 204 | struct terminal *term; |
| 205 | int char_width, char_height; |
| 206 | |
| 207 | char_width = machine->gfx[gfx]->width; |
| 208 | char_height = machine->gfx[gfx]->height; |
| 209 | |
| 210 | term = (struct terminal *) auto_alloc_array(machine, char, sizeof(struct terminal) - sizeof(term->mem) |
| 211 | + (num_cols * num_rows * sizeof(termchar_t))); |
| 212 | |
| 213 | term->tm = tilemap_create(machine, terminal_gettileinfo, tilemap_scan_rows, |
| 214 | char_width, char_height, num_cols, num_rows); |
| 215 | |
| 216 | term->gfx = gfx; |
| 217 | term->blank_char = blank_char; |
| 218 | term->char_bits = char_bits; |
| 219 | term->num_cols = num_cols; |
| 220 | term->num_rows = num_rows; |
| 221 | term->getcursorcode = getcursorcode; |
| 222 | term->cur_offset = -1; |
| 223 | term->cur_hidden = 0; |
| 224 | terminal_clear(term); |
| 225 | return term; |
| 226 | } |
| 227 | |
| 228 | |
| 229 | /**************************************************************************/ |
| 230 | |
| 231 | |
| 67 | 232 | static struct terminal *apple1_terminal; |
| 68 | 233 | |
| 69 | 234 | int apple1_vh_clrscrn_pressed = 0; /* flag for CLEAR SCREEN switch */ |
src/mess/mscommon.c
| r6058 | r6059 | |
| 6 | 6 | |
| 7 | 7 | *********************************************************************/ |
| 8 | 8 | |
| 9 | | #include <assert.h> |
| 10 | 9 | #include "driver.h" |
| 11 | 10 | #include "mscommon.h" |
| 12 | 11 | |
| 13 | | /*************************************************************************** |
| 14 | 12 | |
| 15 | | Terminal code |
| 16 | | |
| 17 | | ***************************************************************************/ |
| 18 | | |
| 19 | | typedef short termchar_t; |
| 20 | | |
| 21 | | struct terminal |
| 22 | | { |
| 23 | | tilemap *tm; |
| 24 | | int gfx; |
| 25 | | int blank_char; |
| 26 | | int char_bits; |
| 27 | | int num_cols; |
| 28 | | int num_rows; |
| 29 | | int (*getcursorcode)(int original_code); |
| 30 | | int cur_offset; |
| 31 | | int cur_hidden; |
| 32 | | termchar_t mem[1]; |
| 33 | | }; |
| 34 | | |
| 35 | | static struct terminal *current_terminal; |
| 36 | | |
| 37 | | static TILE_GET_INFO(terminal_gettileinfo) |
| 38 | | { |
| 39 | | int ch, gfxfont, code, color; |
| 40 | | |
| 41 | | ch = current_terminal->mem[tile_index]; |
| 42 | | code = ch & ((1 << current_terminal->char_bits) - 1); |
| 43 | | color = ch >> current_terminal->char_bits; |
| 44 | | gfxfont = current_terminal->gfx; |
| 45 | | |
| 46 | | if ((tile_index == current_terminal->cur_offset) && !current_terminal->cur_hidden && current_terminal->getcursorcode) |
| 47 | | code = current_terminal->getcursorcode(code); |
| 48 | | |
| 49 | | SET_TILE_INFO( |
| 50 | | gfxfont, /* gfx */ |
| 51 | | code, /* character */ |
| 52 | | color, /* color */ |
| 53 | | 0); /* flags */ |
| 54 | | } |
| 55 | | |
| 56 | | struct terminal *terminal_create( |
| 57 | | running_machine *machine, |
| 58 | | int gfx, int blank_char, int char_bits, |
| 59 | | int (*getcursorcode)(int original_code), |
| 60 | | int num_cols, int num_rows) |
| 61 | | { |
| 62 | | struct terminal *term; |
| 63 | | int char_width, char_height; |
| 64 | | |
| 65 | | char_width = machine->gfx[gfx]->width; |
| 66 | | char_height = machine->gfx[gfx]->height; |
| 67 | | |
| 68 | | term = (struct terminal *) auto_alloc_array(machine, char, sizeof(struct terminal) - sizeof(term->mem) |
| 69 | | + (num_cols * num_rows * sizeof(termchar_t))); |
| 70 | | |
| 71 | | term->tm = tilemap_create(machine, terminal_gettileinfo, tilemap_scan_rows, |
| 72 | | char_width, char_height, num_cols, num_rows); |
| 73 | | |
| 74 | | term->gfx = gfx; |
| 75 | | term->blank_char = blank_char; |
| 76 | | term->char_bits = char_bits; |
| 77 | | term->num_cols = num_cols; |
| 78 | | term->num_rows = num_rows; |
| 79 | | term->getcursorcode = getcursorcode; |
| 80 | | term->cur_offset = -1; |
| 81 | | term->cur_hidden = 0; |
| 82 | | terminal_clear(term); |
| 83 | | return term; |
| 84 | | } |
| 85 | | |
| 86 | | void terminal_draw(bitmap_t *dest, const rectangle *cliprect, struct terminal *terminal) |
| 87 | | { |
| 88 | | current_terminal = terminal; |
| 89 | | tilemap_draw(dest, cliprect, terminal->tm, 0, 0); |
| 90 | | current_terminal = NULL; |
| 91 | | } |
| 92 | | |
| 93 | | static void verify_coords(struct terminal *terminal, int x, int y) |
| 94 | | { |
| 95 | | assert(x >= 0); |
| 96 | | assert(y >= 0); |
| 97 | | assert(x < terminal->num_cols); |
| 98 | | assert(y < terminal->num_rows); |
| 99 | | } |
| 100 | | |
| 101 | | void terminal_putchar(struct terminal *terminal, int x, int y, int ch) |
| 102 | | { |
| 103 | | int offs; |
| 104 | | |
| 105 | | verify_coords(terminal, x, y); |
| 106 | | |
| 107 | | offs = y * terminal->num_cols + x; |
| 108 | | if (terminal->mem[offs] != ch) |
| 109 | | { |
| 110 | | terminal->mem[offs] = ch; |
| 111 | | tilemap_mark_tile_dirty(terminal->tm, offs); |
| 112 | | } |
| 113 | | } |
| 114 | | |
| 115 | | int terminal_getchar(struct terminal *terminal, int x, int y) |
| 116 | | { |
| 117 | | int offs; |
| 118 | | |
| 119 | | verify_coords(terminal, x, y); |
| 120 | | offs = y * terminal->num_cols + x; |
| 121 | | return terminal->mem[offs]; |
| 122 | | } |
| 123 | | |
| 124 | | void terminal_putblank(struct terminal *terminal, int x, int y) |
| 125 | | { |
| 126 | | terminal_putchar(terminal, x, y, terminal->blank_char); |
| 127 | | } |
| 128 | | |
| 129 | | static void terminal_dirtycursor(struct terminal *terminal) |
| 130 | | { |
| 131 | | if (terminal->cur_offset >= 0) |
| 132 | | tilemap_mark_tile_dirty(terminal->tm, terminal->cur_offset); |
| 133 | | } |
| 134 | | |
| 135 | | void terminal_setcursor(struct terminal *terminal, int x, int y) |
| 136 | | { |
| 137 | | terminal_dirtycursor(terminal); |
| 138 | | terminal->cur_offset = y * terminal->num_cols + x; |
| 139 | | terminal_dirtycursor(terminal); |
| 140 | | } |
| 141 | | |
| 142 | | void terminal_hidecursor(struct terminal *terminal) |
| 143 | | { |
| 144 | | terminal->cur_hidden = 1; |
| 145 | | terminal_dirtycursor(terminal); |
| 146 | | } |
| 147 | | |
| 148 | | void terminal_showcursor(struct terminal *terminal) |
| 149 | | { |
| 150 | | terminal->cur_hidden = 0; |
| 151 | | terminal_dirtycursor(terminal); |
| 152 | | } |
| 153 | | |
| 154 | | void terminal_getcursor(struct terminal *terminal, int *x, int *y) |
| 155 | | { |
| 156 | | *x = terminal->cur_offset % terminal->num_cols; |
| 157 | | *y = terminal->cur_offset / terminal->num_cols; |
| 158 | | } |
| 159 | | |
| 160 | | void terminal_fill(struct terminal *terminal, int val) |
| 161 | | { |
| 162 | | int i; |
| 163 | | for (i = 0; i < terminal->num_cols * terminal->num_rows; i++) |
| 164 | | terminal->mem[i] = val; |
| 165 | | tilemap_mark_all_tiles_dirty(terminal->tm); |
| 166 | | } |
| 167 | | |
| 168 | | void terminal_clear(struct terminal *terminal) |
| 169 | | { |
| 170 | | terminal_fill(terminal, terminal->blank_char); |
| 171 | | } |
| 172 | | |
| 173 | 13 | /*************************************************************************** |
| 174 | 14 | |
| 175 | 15 | LED code |
src/mess/mscommon.h
| r6058 | r6059 | |
| 4 | 4 | |
| 5 | 5 | MESS specific generic functions |
| 6 | 6 | |
| 7 | TODO: This code needs to be removed, update the drivers |
| 8 | using it. |
| 9 | |
| 7 | 10 | *********************************************************************/ |
| 8 | 11 | |
| 9 | | #ifndef MSCOMMON_H |
| 10 | | #define MSCOMMON_H |
| 12 | #ifndef __MSCOMMON_H__ |
| 13 | #define __MSCOMMON_H__ |
| 11 | 14 | |
| 12 | | #ifdef __cplusplus |
| 13 | | extern "C" { |
| 14 | | #endif |
| 15 | | |
| 16 | 15 | #include "driver.h" |
| 17 | 16 | |
| 18 | | /*************************************************************************** |
| 19 | 17 | |
| 20 | | Terminal code |
| 21 | | |
| 22 | | ***************************************************************************/ |
| 23 | | |
| 24 | | struct terminal; |
| 25 | | |
| 26 | | struct terminal *terminal_create( |
| 27 | | running_machine *machine, |
| 28 | | int gfx, int blank_char, int char_bits, |
| 29 | | int (*getcursorcode)(int original_code), |
| 30 | | int num_cols, int num_rows); |
| 31 | | |
| 32 | | void terminal_draw(bitmap_t *dest, const rectangle *cliprect, |
| 33 | | struct terminal *terminal); |
| 34 | | void terminal_putchar(struct terminal *terminal, int x, int y, int ch); |
| 35 | | int terminal_getchar(struct terminal *terminal, int x, int y); |
| 36 | | void terminal_putblank(struct terminal *terminal, int x, int y); |
| 37 | | void terminal_setcursor(struct terminal *terminal, int x, int y); |
| 38 | | void terminal_hidecursor(struct terminal *terminal); |
| 39 | | void terminal_showcursor(struct terminal *terminal); |
| 40 | | void terminal_getcursor(struct terminal *terminal, int *x, int *y); |
| 41 | | void terminal_fill(struct terminal *terminal, int val); |
| 42 | | void terminal_clear(struct terminal *terminal); |
| 43 | | |
| 44 | 18 | /*************************************************************************** |
| 45 | 19 | |
| 46 | 20 | LED code |
| r6058 | r6059 | |
| 67 | 41 | |
| 68 | 42 | /**************************************************************************/ |
| 69 | 43 | |
| 70 | | #ifdef __cplusplus |
| 71 | | } |
| 72 | | #endif |
| 73 | | |
| 74 | | #endif /* MSCOMMON_H */ |
| 44 | #endif /* __MSCOMMON_H__ */ |