Previous 15994 Revisions Next

r6059 Tuesday 13th October, 2009 at 11:25:59 UTC by Dirk Best
Move terminal code out of mscommon.c and into apple1.c
[src/mess]mscommon.c mscommon.h
[src/mess/video]apple1.c

src/mess/video/apple1.c
r6058r6059
6464#include "includes/apple1.h"
6565#include "mscommon.h"
6666
67
68/***************************************************************************
69
70   Terminal code
71
72***************************************************************************/
73
74typedef short termchar_t;
75
76struct 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
90static struct terminal *current_terminal;
91
92static 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
111static 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
118static 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
126static 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
140static 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
149static void terminal_putblank(struct terminal *terminal, int x, int y)
150{
151   terminal_putchar(terminal, x, y, terminal->blank_char);
152}
153
154static 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
160static 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
167static void terminal_hidecursor(struct terminal *terminal)
168{
169   terminal->cur_hidden = 1;
170   terminal_dirtycursor(terminal);
171}
172
173static void terminal_showcursor(struct terminal *terminal)
174{
175   terminal->cur_hidden = 0;
176   terminal_dirtycursor(terminal);
177}
178
179static 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
185static 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
193static void terminal_clear(struct terminal *terminal)
194{
195   terminal_fill(terminal, terminal->blank_char);
196}
197
198struct 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
67232static struct terminal *apple1_terminal;
68233
69234int apple1_vh_clrscrn_pressed = 0;      /* flag for CLEAR SCREEN switch */
src/mess/mscommon.c
r6058r6059
66
77*********************************************************************/
88
9#include <assert.h>
109#include "driver.h"
1110#include "mscommon.h"
1211
13/***************************************************************************
1412
15   Terminal code
16
17***************************************************************************/
18
19typedef short termchar_t;
20
21struct 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
35static struct terminal *current_terminal;
36
37static 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
56struct 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
86void 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
93static 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
101void 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
115int 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
124void terminal_putblank(struct terminal *terminal, int x, int y)
125{
126   terminal_putchar(terminal, x, y, terminal->blank_char);
127}
128
129static 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
135void 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
142void terminal_hidecursor(struct terminal *terminal)
143{
144   terminal->cur_hidden = 1;
145   terminal_dirtycursor(terminal);
146}
147
148void terminal_showcursor(struct terminal *terminal)
149{
150   terminal->cur_hidden = 0;
151   terminal_dirtycursor(terminal);
152}
153
154void 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
160void 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
168void terminal_clear(struct terminal *terminal)
169{
170   terminal_fill(terminal, terminal->blank_char);
171}
172
17313/***************************************************************************
17414
17515   LED code
src/mess/mscommon.h
r6058r6059
44
55   MESS specific generic functions
66
7   TODO: This code needs to be removed, update the drivers
8   using it.
9
710*********************************************************************/
811
9#ifndef MSCOMMON_H
10#define MSCOMMON_H
12#ifndef __MSCOMMON_H__
13#define __MSCOMMON_H__
1114
12#ifdef __cplusplus
13extern "C" {
14#endif
15
1615#include "driver.h"
1716
18/***************************************************************************
1917
20   Terminal code
21
22***************************************************************************/
23
24struct terminal;
25
26struct 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
32void terminal_draw(bitmap_t *dest, const rectangle *cliprect,
33   struct terminal *terminal);
34void terminal_putchar(struct terminal *terminal, int x, int y, int ch);
35int terminal_getchar(struct terminal *terminal, int x, int y);
36void terminal_putblank(struct terminal *terminal, int x, int y);
37void terminal_setcursor(struct terminal *terminal, int x, int y);
38void terminal_hidecursor(struct terminal *terminal);
39void terminal_showcursor(struct terminal *terminal);
40void terminal_getcursor(struct terminal *terminal, int *x, int *y);
41void terminal_fill(struct terminal *terminal, int val);
42void terminal_clear(struct terminal *terminal);
43
4418/***************************************************************************
4519
4620   LED code
r6058r6059
6741
6842/**************************************************************************/
6943
70#ifdef __cplusplus
71}
72#endif
73
74#endif /* MSCOMMON_H */
44#endif /* __MSCOMMON_H__ */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team