Previous 15994 Revisions Next

r2755 Monday 26th May, 2008 at 19:43:19 UTC by Wilbert Pol
[PC_EGA] Added EGA specific CRT Controller. Created some simple text drawing functions.
[src/mess]mess.mak
[src/mess/video]crtc_ega.c* crtc_ega.h* pc_ega.c pc_ega.h

src/mess/video/crtc_ega.c
r0r2755
1/**********************************************************************
2
3   IBM EGA CRT Controller emulation
4
5   This controller is very loosely based on the mc6845.
6
7**********************************************************************/
8
9#include "driver.h"
10#include "crtc_ega.h"
11
12
13#define LOG      (1)
14
15
16/* device types */
17enum
18{
19   TYPE_CRTC_EGA=0,
20   TYPE_CRTC_VGA,
21
22   NUM_TYPES
23};
24
25
26/* tags for state saving */
27static const char * const device_tags[NUM_TYPES] = { "crtc_ega", "crtc_vga" };
28
29
30typedef struct _crtc_ega_t crtc_ega_t;
31struct _crtc_ega_t
32{
33   int device_type;
34   const crtc_ega_interface *intf;
35   const device_config *screen;
36
37   /* ega/vga register file */
38   UINT8   horiz_char_total;   /* 0x00 */
39   UINT8   horiz_disp;         /* 0x01 */
40   UINT8   horiz_blank_start;   /* 0x02 */
41   UINT8   horiz_blank_end;   /* 0x03/0x05 */
42   UINT8   ena_vert_access;   /* 0x03 */
43   UINT8   de_skew;         /* 0x03 */
44   UINT8   horiz_retr_start;   /* 0x04 */
45   UINT8   horiz_retr_end;      /* 0x05 */
46   UINT8   horiz_retr_skew;   /* 0x05 */
47   UINT16   vert_total;         /* 0x06/0x07 */
48   UINT8   preset_row_scan;   /* 0x08 */
49   UINT8   byte_panning;      /* 0x08 */
50   UINT8   max_ras_addr;      /* 0x09 */
51   UINT8   scan_doubling;      /* 0x09 */
52   UINT8   cursor_start_ras;   /* 0x0a */
53   UINT8   cursor_disable;      /* 0x0a */
54   UINT8   cursor_end_ras;      /* 0x0b */
55   UINT8   cursor_skew;      /* 0x0b */
56   UINT16   disp_start_addr;   /* 0x0c/0x0d */
57   UINT16   cursor_addr;      /* 0x0e/0x0f */
58   UINT16   light_pen_addr;      /* 0x10/0x11 */
59   UINT16   vert_retr_start;   /* 0x10/0x07 */
60   UINT8   vert_retr_end;      /* 0x11 */
61   UINT8   protect;         /* 0x11 */
62   UINT8   bandwidth;         /* 0x11 */
63   UINT16   vert_disp_end;      /* 0x12/0x07 */
64   UINT8   offset;            /* 0x13 */
65   UINT8   underline_loc;      /* 0x14 */
66   UINT16   vert_blank_start;   /* 0x15/0x07/0x09 */
67   UINT8   vert_blank_end;      /* 0x16 */
68   UINT8   mode_control;      /* 0x17 */
69   UINT16   line_compare;      /* 0x18/0x07/0x09 */
70
71   /* other internal state */
72   UINT64   clock;
73   UINT8   register_address_latch;
74   UINT8   hpixels_per_column;
75   UINT8   cursor_state;   /* 0 = off, 1 = on */
76   UINT8   cursor_blink_count;
77
78   /* timers */
79   emu_timer *de_changed_timer;
80   emu_timer *hsync_on_timer;
81   emu_timer *hsync_off_timer;
82   emu_timer *vsync_on_timer;
83   emu_timer *vsync_off_timer;
84   emu_timer *light_pen_latch_timer;
85
86   /* computed values - do NOT state save these! */
87   UINT16   horiz_pix_total;
88   UINT16   vert_pix_total;
89   UINT16   max_visible_x;
90   UINT16   max_visible_y;
91   UINT16   hsync_on_pos;
92   UINT16   hsync_off_pos;
93   UINT16   vsync_on_pos;
94   UINT16   vsync_off_pos;
95   UINT16  current_disp_addr;   /* the display address currently drawn */
96   UINT8   light_pen_latched;
97   int      has_valid_parameters;
98};
99
100static DEVICE_GET_INFO( crtc_vga );
101
102static STATE_POSTLOAD( crtc_ega_state_save_postload );
103static void recompute_parameters(crtc_ega_t *crtc_ega, int postload);
104static void update_de_changed_timer(crtc_ega_t *crtc_ega);
105static void update_hsync_changed_timers(crtc_ega_t *crtc_ega);
106static void update_vsync_changed_timers(crtc_ega_t *crtc_ega);
107
108
109/* makes sure that the passed in device is the right type */
110INLINE crtc_ega_t *get_safe_token(const device_config *device)
111{
112   assert(device != NULL);
113   assert(device->token != NULL);
114   assert((device->type == DEVICE_GET_INFO_NAME(crtc_ega)) ||
115         (device->type == DEVICE_GET_INFO_NAME(crtc_vga)) );
116
117   return (crtc_ega_t *)device->token;
118}
119
120
121static STATE_POSTLOAD( crtc_ega_state_save_postload )
122{
123   recompute_parameters(param, TRUE);
124}
125
126
127WRITE8_DEVICE_HANDLER( crtc_ega_address_w )
128{
129   crtc_ega_t *crtc_ega = get_safe_token(device);
130
131   crtc_ega->register_address_latch = data & 0x1f;
132}
133
134
135READ8_DEVICE_HANDLER( crtc_ega_register_r )
136{
137   crtc_ega_t *crtc_ega = get_safe_token(device);
138   UINT8 ret = 0;
139
140   switch (crtc_ega->register_address_latch)
141   {
142      case 0x0c:  ret = (crtc_ega->disp_start_addr >> 8) & 0xff; break;
143      case 0x0d:  ret = (crtc_ega->disp_start_addr >> 0) & 0xff; break;
144      case 0x0e:  ret = (crtc_ega->cursor_addr    >> 8) & 0xff; break;
145      case 0x0f:  ret = (crtc_ega->cursor_addr    >> 0) & 0xff; break;
146      case 0x10:  ret = (crtc_ega->light_pen_addr >> 8) & 0xff; crtc_ega->light_pen_latched = FALSE; break;
147      case 0x11:  ret = (crtc_ega->light_pen_addr >> 0) & 0xff; crtc_ega->light_pen_latched = FALSE; break;
148
149      /* all other registers are write only and return 0 */
150      default: break;
151   }
152
153   return ret;
154}
155
156
157WRITE8_DEVICE_HANDLER( crtc_ega_register_w )
158{
159   crtc_ega_t *crtc_ega = get_safe_token(device);
160
161   if (LOG)  logerror("CRTC_EGA PC %04x: reg 0x%02x = 0x%02x\n", activecpu_get_pc(), crtc_ega->register_address_latch, data);
162
163   switch (crtc_ega->register_address_latch)
164   {
165      case 0x00:  crtc_ega->horiz_char_total  =   data & 0xff; break;
166      case 0x01:  crtc_ega->horiz_disp        =   data & 0xff; break;
167      case 0x02:  crtc_ega->horiz_blank_start =   data & 0xff; break;
168      case 0x03:  crtc_ega->horiz_blank_end   =  ((data & 0x1f) << 0) | (crtc_ega->horiz_blank_end & 0x20);
169               crtc_ega->de_skew           =  ((data & 0x60) >> 5);
170               crtc_ega->ena_vert_access   =  data & 0x80;
171               break;
172      case 0x04:  crtc_ega->horiz_retr_start  =   data & 0xff; break;
173      case 0x05:  crtc_ega->horiz_retr_end    =   data & 0x1f;
174               crtc_ega->horiz_retr_skew   = ((data & 0x60) >> 5);
175               crtc_ega->horiz_blank_end   = ((data & 0x80) >> 2) | (crtc_ega->horiz_blank_end & 0x1f);
176               break;
177      case 0x06:  crtc_ega->vert_total        = ((data & 0xff) << 0) | (crtc_ega->vert_total & 0x0300); break;
178      case 0x07:  crtc_ega->vert_total        = ((data & 0x01) << 8) | (crtc_ega->vert_total & 0x02ff);
179               crtc_ega->vert_disp_end     = ((data & 0x02) << 7) | (crtc_ega->vert_disp_end & 0x02ff);
180               crtc_ega->vert_retr_start   = ((data & 0x04) << 6) | (crtc_ega->vert_retr_start & 0x02ff);
181               crtc_ega->vert_blank_start  = ((data & 0x08) << 5) | (crtc_ega->vert_blank_start & 0x02ff);
182               crtc_ega->line_compare      = ((data & 0x10) << 4) | (crtc_ega->line_compare & 0x02ff);
183               crtc_ega->vert_total        = ((data & 0x20) << 4) | (crtc_ega->vert_total & 0x01ff);
184               crtc_ega->vert_disp_end     = ((data & 0x40) << 3) | (crtc_ega->vert_disp_end & 0x1ff);
185               crtc_ega->vert_retr_start   = ((data & 0x80) << 2) | (crtc_ega->vert_retr_start & 0x01ff);
186               break;
187      case 0x08:  crtc_ega->preset_row_scan   =   data & 0x1f;
188               crtc_ega->byte_panning      = ((data & 0x60) >> 5);
189               break;
190      case 0x09:  crtc_ega->max_ras_addr      =   data & 0x1f;
191               crtc_ega->vert_blank_start  = ((data & 0x20) << 4) | (crtc_ega->vert_blank_start & 0x01ff);
192               crtc_ega->line_compare      = ((data & 0x40) << 3) | (crtc_ega->line_compare & 0x01ff);
193               crtc_ega->scan_doubling     =   data & 0x80;
194               break;
195      case 0x0a:  crtc_ega->cursor_start_ras  =   data & 0x1f;
196               crtc_ega->cursor_disable    =   data & 0x20;
197               break;
198      case 0x0b:  crtc_ega->cursor_end_ras    =   data & 0x1f;
199               crtc_ega->cursor_skew       = ((data & 0x60) >> 5);
200               break;
201      case 0x0c:  crtc_ega->disp_start_addr   = ((data & 0xff) << 8) | (crtc_ega->disp_start_addr & 0x00ff); break;
202      case 0x0d:  crtc_ega->disp_start_addr   = ((data & 0xff) << 0) | (crtc_ega->disp_start_addr & 0xff00); break;
203      case 0x0e:  crtc_ega->cursor_addr       = ((data & 0xff) << 8) | (crtc_ega->cursor_addr & 0x00ff); break;
204      case 0x0f:  crtc_ega->cursor_addr       = ((data & 0xff) << 0) | (crtc_ega->cursor_addr & 0xff00); break;
205      case 0x10:   crtc_ega->vert_retr_start   = ((data & 0xff) << 0) | (crtc_ega->vert_retr_start & 0x03ff); break;
206      case 0x11:   crtc_ega->vert_retr_end     =   data & 0x0f;
207               crtc_ega->bandwidth         =   data & 0x40;
208               crtc_ega->protect           =   data & 0x80;
209               break;
210      case 0x12:   crtc_ega->vert_disp_end     = ((data & 0xff) << 0) | (crtc_ega->vert_disp_end & 0x0300); break;
211      case 0x13:   crtc_ega->offset            =  data & 0xff; break;
212      case 0x14:   crtc_ega->underline_loc     =  data & 0x7f; break;
213      case 0x15:   crtc_ega->vert_blank_start  = ((data & 0xff) << 0) | (crtc_ega->vert_blank_start & 0x0300); break;
214      case 0x16:   crtc_ega->vert_blank_end    =   data & 0x7f; break;
215      case 0x17:   crtc_ega->mode_control      =   data & 0xff; break;
216      case 0x18:   crtc_ega->line_compare      = ((data & 0xff) << 0) | (crtc_ega->line_compare & 0x0300); break;
217      default:   break;
218   }
219
220//   /* display message if the Mode Control register is not zero */
221//   if ((crtc_ega->register_address_latch == 0x08) && (crtc_ega->mode_control != 0))
222//      popmessage("Mode Control %02X is not supported!!!", crtc_ega->mode_control);
223
224   recompute_parameters(crtc_ega, FALSE);
225}
226
227
228static void recompute_parameters(crtc_ega_t *crtc_ega, int postload)
229{
230   if (crtc_ega->intf != NULL)
231   {
232      UINT16 hsync_on_pos, hsync_off_pos, vsync_on_pos, vsync_off_pos;
233
234      /* compute the screen sizes */
235      UINT16 horiz_pix_total = (crtc_ega->horiz_char_total + 5) * crtc_ega->hpixels_per_column;
236      UINT16 vert_pix_total = crtc_ega->vert_total + 1;
237
238      /* determine the visible area, avoid division by 0 */
239      UINT16 max_visible_x = ( crtc_ega->horiz_disp + 1 ) * crtc_ega->hpixels_per_column - 1;
240      UINT16 max_visible_y = crtc_ega->vert_disp_end;
241
242      /* determine the syncing positions */
243      int horiz_sync_char_width = ( crtc_ega->horiz_retr_end + 1 ) - ( crtc_ega->horiz_retr_start & 0x1f );
244      int vert_sync_pix_width = crtc_ega->vert_retr_end - ( crtc_ega->vert_retr_start & 0x0f );
245
246      if (horiz_sync_char_width <= 0)
247         horiz_sync_char_width += 0x10;
248
249      if (vert_sync_pix_width <= 0)
250         vert_sync_pix_width += 0x10;
251
252      hsync_on_pos = crtc_ega->horiz_retr_start * crtc_ega->hpixels_per_column;
253      hsync_off_pos = hsync_on_pos + (horiz_sync_char_width * crtc_ega->hpixels_per_column);
254      vsync_on_pos = crtc_ega->vert_retr_start;      /* + 1 ?? */
255      vsync_off_pos = vsync_on_pos + vert_sync_pix_width;
256
257      /* the Commodore PET computers program a horizontal synch pulse that extends
258          past the scanline width.  I assume that the real device will clamp it */
259      if (hsync_off_pos > horiz_pix_total)
260         hsync_off_pos = horiz_pix_total;
261
262      if (vsync_off_pos > vert_pix_total)
263         vsync_off_pos = vert_pix_total;
264
265      /* update only if screen parameters changed, unless we are coming here after loading the saved state */
266      if (postload ||
267          (horiz_pix_total != crtc_ega->horiz_pix_total) || (vert_pix_total != crtc_ega->vert_pix_total) ||
268         (max_visible_x != crtc_ega->max_visible_x) || (max_visible_y != crtc_ega->max_visible_y) ||
269         (hsync_on_pos != crtc_ega->hsync_on_pos) || (vsync_on_pos != crtc_ega->vsync_on_pos) ||
270         (hsync_off_pos != crtc_ega->hsync_off_pos) || (vsync_off_pos != crtc_ega->vsync_off_pos))
271      {
272         /* update the screen if we have valid data */
273         if ((horiz_pix_total > 0) && (max_visible_x < horiz_pix_total) &&
274            (vert_pix_total > 0) && (max_visible_y < vert_pix_total) &&
275            (hsync_on_pos <= horiz_pix_total) && (vsync_on_pos <= vert_pix_total) &&
276            (hsync_on_pos != hsync_off_pos))
277         {
278            rectangle visarea;
279
280            attoseconds_t refresh = HZ_TO_ATTOSECONDS(crtc_ega->clock) * (crtc_ega->horiz_char_total + 1) * vert_pix_total;
281
282            visarea.min_x = 0;
283            visarea.min_y = 0;
284            visarea.max_x = max_visible_x;
285            visarea.max_y = max_visible_y;
286
287            if (LOG) logerror("CRTC_EGA config screen: HTOTAL: 0x%x  VTOTAL: 0x%x  MAX_X: 0x%x  MAX_Y: 0x%x  HSYNC: 0x%x-0x%x  VSYNC: 0x%x-0x%x  Freq: %ffps\n",
288                          horiz_pix_total, vert_pix_total, max_visible_x, max_visible_y, hsync_on_pos, hsync_off_pos - 1, vsync_on_pos, vsync_off_pos - 1, 1 / ATTOSECONDS_TO_DOUBLE(refresh));
289
290            video_screen_configure(crtc_ega->screen, horiz_pix_total, vert_pix_total, &visarea, refresh);
291
292            crtc_ega->has_valid_parameters = TRUE;
293         }
294         else
295            crtc_ega->has_valid_parameters = FALSE;
296
297         crtc_ega->horiz_pix_total = horiz_pix_total;
298         crtc_ega->vert_pix_total = vert_pix_total;
299         crtc_ega->max_visible_x = max_visible_x;
300         crtc_ega->max_visible_y = max_visible_y;
301         crtc_ega->hsync_on_pos = hsync_on_pos;
302         crtc_ega->hsync_off_pos = hsync_off_pos;
303         crtc_ega->vsync_on_pos = vsync_on_pos;
304         crtc_ega->vsync_off_pos = vsync_off_pos;
305
306         update_de_changed_timer(crtc_ega);
307         update_hsync_changed_timers(crtc_ega);
308         update_vsync_changed_timers(crtc_ega);
309      }
310   }
311}
312
313
314INLINE int is_display_enabled(crtc_ega_t *crtc_ega)
315{
316   return !video_screen_get_vblank(crtc_ega->screen) && !video_screen_get_hblank(crtc_ega->screen);
317}
318
319
320static void update_de_changed_timer(crtc_ega_t *crtc_ega)
321{
322   if (crtc_ega->has_valid_parameters && (crtc_ega->de_changed_timer != NULL))
323   {
324      INT16 next_y;
325      UINT16 next_x;
326      attotime duration;
327
328      /* we are in a display region, get the location of the next blanking start */
329      if (is_display_enabled(crtc_ega))
330      {
331         /* normally, it's at end the current raster line */
332         next_y = video_screen_get_vpos(crtc_ega->screen);
333         next_x = crtc_ega->max_visible_x + 1;
334
335         /* but if visible width = horiz_pix_total, then we need
336               to go to the beginning of VBLANK */
337         if (next_x == crtc_ega->horiz_pix_total)
338         {
339            next_y = crtc_ega->max_visible_y + 1;
340            next_x = 0;
341
342            /* abnormal case, no vertical blanking, either */
343            if (next_y == crtc_ega->vert_pix_total)
344               next_y = -1;
345         }
346      }
347
348      /* we are in a blanking region, get the location of the next display start */
349      else
350      {
351         next_x = 0;
352         next_y = (video_screen_get_vpos(crtc_ega->screen) + 1) % crtc_ega->vert_pix_total;
353
354         /* if we would now fall in the vertical blanking, we need
355               to go to the top of the screen */
356         if (next_y > crtc_ega->max_visible_y)
357            next_y = 0;
358      }
359
360      if (next_y != -1)
361         duration = video_screen_get_time_until_pos(crtc_ega->screen, next_y, next_x);
362      else
363         duration = attotime_never;
364
365      timer_adjust_oneshot(crtc_ega->de_changed_timer, duration, 0);
366   }
367}
368
369
370static void update_hsync_changed_timers(crtc_ega_t *crtc_ega)
371{
372   if (crtc_ega->has_valid_parameters && (crtc_ega->hsync_on_timer != NULL))
373   {
374      UINT16 next_y;
375
376      /* we are before the HSYNC position, we trigger on the current line */
377      if (video_screen_get_hpos(crtc_ega->screen) < crtc_ega->hsync_on_pos)
378         next_y = video_screen_get_vpos(crtc_ega->screen);
379
380      /* trigger on the next line */
381      else
382         next_y = (video_screen_get_vpos(crtc_ega->screen) + 1) % crtc_ega->vert_pix_total;
383
384      /* if the next line is not in the visible region, go to the beginning of the screen */
385      if (next_y > crtc_ega->max_visible_y)
386         next_y = 0;
387
388      timer_adjust_oneshot(crtc_ega->hsync_on_timer,  video_screen_get_time_until_pos(crtc_ega->screen, next_y, crtc_ega->hsync_on_pos) , 0);
389      timer_adjust_oneshot(crtc_ega->hsync_off_timer, video_screen_get_time_until_pos(crtc_ega->screen, next_y, crtc_ega->hsync_off_pos), 0);
390   }
391}
392
393
394static void update_vsync_changed_timers(crtc_ega_t *crtc_ega)
395{
396   if (crtc_ega->has_valid_parameters && (crtc_ega->vsync_on_timer != NULL))
397   {
398      timer_adjust_oneshot(crtc_ega->vsync_on_timer,  video_screen_get_time_until_pos(crtc_ega->screen, crtc_ega->vsync_on_pos,  0), 0);
399      timer_adjust_oneshot(crtc_ega->vsync_off_timer, video_screen_get_time_until_pos(crtc_ega->screen, crtc_ega->vsync_off_pos, 0), 0);
400   }
401}
402
403
404static TIMER_CALLBACK( de_changed_timer_cb )
405{
406   const device_config *device = ptr;
407   crtc_ega_t *crtc_ega = get_safe_token(device);
408
409   /* call the callback function -- we know it exists */
410   crtc_ega->intf->on_de_changed(device, is_display_enabled(crtc_ega));
411
412   update_de_changed_timer(crtc_ega);
413}
414
415
416static TIMER_CALLBACK( vsync_on_timer_cb )
417{
418   const device_config *device = ptr;
419   crtc_ega_t *crtc_ega = get_safe_token(device);
420
421   /* call the callback function -- we know it exists */
422   crtc_ega->intf->on_vsync_changed(device, TRUE);
423}
424
425
426static TIMER_CALLBACK( vsync_off_timer_cb )
427{
428   const device_config *device = ptr;
429   crtc_ega_t *crtc_ega = get_safe_token(device);
430
431   /* call the callback function -- we know it exists */
432   crtc_ega->intf->on_vsync_changed(device, FALSE);
433
434   update_vsync_changed_timers(crtc_ega);
435}
436
437
438static TIMER_CALLBACK( hsync_on_timer_cb )
439{
440   const device_config *device = ptr;
441   crtc_ega_t *crtc_ega = get_safe_token(device);
442
443   /* call the callback function -- we know it exists */
444   crtc_ega->intf->on_hsync_changed(device, TRUE);
445}
446
447
448static TIMER_CALLBACK( hsync_off_timer_cb )
449{
450   const device_config *device = ptr;
451   crtc_ega_t *crtc_ega = get_safe_token(device);
452
453   /* call the callback function -- we know it exists */
454   crtc_ega->intf->on_hsync_changed(device, FALSE);
455
456   update_hsync_changed_timers(crtc_ega);
457}
458
459
460
461UINT16 crtc_ega_get_ma(const device_config *device)
462{
463   UINT16 ret;
464   crtc_ega_t *crtc_ega = get_safe_token(device);
465
466   if (crtc_ega->has_valid_parameters)
467   {
468      /* clamp Y/X to the visible region */
469      int y = video_screen_get_vpos(crtc_ega->screen);
470      int x = video_screen_get_hpos(crtc_ega->screen);
471
472      /* since the MA counter stops in the blanking regions, if we are in a
473           VBLANK, both X and Y are at their max */
474      if ((y > crtc_ega->max_visible_y) || (x > crtc_ega->max_visible_x))
475         x = crtc_ega->max_visible_x;
476
477      if (y > crtc_ega->max_visible_y)
478         y = crtc_ega->max_visible_y;
479
480      ret = (crtc_ega->disp_start_addr +
481           (y / (crtc_ega->max_ras_addr + 1)) * ( crtc_ega->horiz_disp + 1 ) +
482           (x / crtc_ega->hpixels_per_column)) & 0x3fff;
483   }
484   else
485      ret = 0;
486
487   return ret;
488}
489
490
491UINT8 crtc_ega_get_ra(const device_config *device)
492{
493   UINT8 ret;
494   crtc_ega_t *crtc_ega = get_safe_token(device);
495
496   if (crtc_ega->has_valid_parameters)
497   {
498      /* get the current vertical raster position and clamp it to the visible region */
499      int y = video_screen_get_vpos(crtc_ega->screen);
500
501      if (y > crtc_ega->max_visible_y)
502         y = crtc_ega->max_visible_y;
503
504      ret = y % (crtc_ega->max_ras_addr + 1);
505   }
506   else
507      ret = 0;
508
509   return ret;
510}
511
512
513static TIMER_CALLBACK( light_pen_latch_timer_cb )
514{
515   const device_config *device = ptr;
516   crtc_ega_t *crtc_ega = get_safe_token(device);
517
518   crtc_ega->light_pen_addr = crtc_ega_get_ma(device);
519   crtc_ega->light_pen_latched = TRUE;
520}
521
522
523void crtc_ega_assert_light_pen_input(const device_config *device)
524{
525   int y, x;
526   int char_x;
527
528   crtc_ega_t *crtc_ega = get_safe_token(device);
529
530   if (crtc_ega->has_valid_parameters)
531   {
532      /* get the current pixel coordinates */
533      y = video_screen_get_vpos(crtc_ega->screen);
534      x = video_screen_get_hpos(crtc_ega->screen);
535
536      /* compute the pixel coordinate of the NEXT character -- this is when the light pen latches */
537      char_x = x / crtc_ega->hpixels_per_column;
538      x = (char_x + 1) * crtc_ega->hpixels_per_column;
539
540      /* adjust if we are passed the boundaries of the screen */
541      if (x == crtc_ega->horiz_pix_total)
542      {
543         y = y + 1;
544         x = 0;
545
546         if (y == crtc_ega->vert_pix_total)
547            y = 0;
548      }
549
550      /* set the timer that will latch the display address into the light pen registers */
551      timer_adjust_oneshot(crtc_ega->light_pen_latch_timer, video_screen_get_time_until_pos(crtc_ega->screen, y, x), 0);
552   }
553}
554
555
556void crtc_ega_set_clock(const device_config *device, int clock)
557{
558   crtc_ega_t *crtc_ega = get_safe_token(device);
559
560   /* validate arguments */
561   assert(clock > 0);
562
563   if (clock != crtc_ega->clock)
564   {
565      crtc_ega->clock = clock;
566      recompute_parameters(crtc_ega, FALSE);
567   }
568}
569
570
571void crtc_ega_set_hpixels_per_column(const device_config *device, int hpixels_per_column)
572{
573   crtc_ega_t *crtc_ega = get_safe_token(device);
574
575   /* validate arguments */
576   assert(hpixels_per_column > 0);
577
578   if (hpixels_per_column != crtc_ega->hpixels_per_column)
579   {
580      crtc_ega->hpixels_per_column = hpixels_per_column;
581      recompute_parameters(crtc_ega, FALSE);
582   }
583}
584
585
586static void update_cursor_state(crtc_ega_t *crtc_ega)
587{
588   /* save and increment cursor counter */
589   UINT8 last_cursor_blink_count = crtc_ega->cursor_blink_count;
590   crtc_ega->cursor_blink_count = crtc_ega->cursor_blink_count + 1;
591
592   /* switch on cursor blinking mode */
593   switch (crtc_ega->cursor_start_ras & 0x60)
594   {
595      /* always on */
596      case 0x00: crtc_ega->cursor_state = TRUE; break;
597
598      /* always off */
599      default:
600      case 0x20: crtc_ega->cursor_state = FALSE; break;
601
602      /* fast blink */
603      case 0x40:
604         if ((last_cursor_blink_count & 0x10) != (crtc_ega->cursor_blink_count & 0x10))
605            crtc_ega->cursor_state = !crtc_ega->cursor_state;
606         break;
607
608      /* slow blink */
609      case 0x60:
610         if ((last_cursor_blink_count & 0x20) != (crtc_ega->cursor_blink_count & 0x20))
611            crtc_ega->cursor_state = !crtc_ega->cursor_state;
612         break;
613   }
614}
615
616
617void crtc_ega_update(const device_config *device, bitmap_t *bitmap, const rectangle *cliprect)
618{
619   crtc_ega_t *crtc_ega = get_safe_token(device);
620   assert(bitmap != NULL);
621   assert(cliprect != NULL);
622
623   if (crtc_ega->has_valid_parameters)
624   {
625      UINT16 y;
626
627      void *param = NULL;
628
629      assert(crtc_ega->intf != NULL);
630      assert(crtc_ega->intf->update_row != NULL);
631
632      /* call the set up function if any */
633      if (crtc_ega->intf->begin_update != NULL)
634         param = crtc_ega->intf->begin_update(device, bitmap, cliprect);
635
636      if (cliprect->min_y == 0)
637      {
638         /* read the start address at the beginning of the frame */
639         crtc_ega->current_disp_addr = crtc_ega->disp_start_addr;
640
641         /* also update the cursor state now */
642         update_cursor_state(crtc_ega);
643      }
644
645      /* for each row in the visible region */
646      for (y = cliprect->min_y; y <= cliprect->max_y; y++)
647      {
648         /* compute the current raster line */
649         UINT8 ra = y % (crtc_ega->max_ras_addr + 1);
650
651         /* check if the cursor is visible and is on this scanline */
652         int cursor_visible = crtc_ega->cursor_state &&
653                         (ra >= (crtc_ega->cursor_start_ras & 0x1f)) &&
654                         (ra <= crtc_ega->cursor_end_ras) &&
655                         (crtc_ega->cursor_addr >= crtc_ega->current_disp_addr) &&
656                         (crtc_ega->cursor_addr < (crtc_ega->current_disp_addr + ( crtc_ega->horiz_disp + 1 )));
657
658         /* compute the cursor X position, or -1 if not visible */
659         INT8 cursor_x = cursor_visible ? (crtc_ega->cursor_addr - crtc_ega->current_disp_addr) : -1;
660
661         /* call the external system to draw it */
662         crtc_ega->intf->update_row(device, bitmap, cliprect, crtc_ega->current_disp_addr, ra, y, crtc_ega->horiz_disp + 1, cursor_x, param);
663
664         /* update MA if the last raster address */
665         if (ra == crtc_ega->max_ras_addr)
666            crtc_ega->current_disp_addr = (crtc_ega->current_disp_addr + crtc_ega->horiz_disp + 1) & 0xffff;
667      }
668
669      /* call the tear down function if any */
670      if (crtc_ega->intf->end_update != NULL)
671         crtc_ega->intf->end_update(device, bitmap, cliprect, param);
672
673      popmessage(NULL);
674   }
675   else
676      popmessage("Invalid crtc_ega screen parameters - display disabled!!!");
677}
678
679
680/* device interface */
681static void common_start(const device_config *device, int device_type)
682{
683   crtc_ega_t *crtc_ega = get_safe_token(device);
684   char unique_tag[30];
685
686   /* validate arguments */
687   assert(device != NULL);
688   assert(device->tag != NULL);
689   assert(strlen(device->tag) < 20);
690
691   crtc_ega->intf = device->static_config;
692   crtc_ega->device_type = device_type;
693
694   if (crtc_ega->intf != NULL)
695   {
696      assert(crtc_ega->intf->clock > 0);
697      assert(crtc_ega->intf->hpixels_per_column > 0);
698
699      /* copy the initial parameters */
700      crtc_ega->clock = crtc_ega->intf->clock;
701      crtc_ega->hpixels_per_column = crtc_ega->intf->hpixels_per_column;
702
703      /* get the screen device */
704      crtc_ega->screen = device_list_find_by_tag(device->machine->config->devicelist, VIDEO_SCREEN, crtc_ega->intf->screen_tag);
705      assert(crtc_ega->screen != NULL);
706
707      /* create the timers */
708      if (crtc_ega->intf->on_de_changed != NULL)
709         crtc_ega->de_changed_timer = timer_alloc(de_changed_timer_cb, (void *)device);
710
711      if (crtc_ega->intf->on_hsync_changed != NULL)
712      {
713         crtc_ega->hsync_on_timer = timer_alloc(hsync_on_timer_cb, (void *)device);
714         crtc_ega->hsync_off_timer = timer_alloc(hsync_off_timer_cb, (void *)device);
715      }
716
717      if (crtc_ega->intf->on_vsync_changed != NULL)
718      {
719         crtc_ega->vsync_on_timer = timer_alloc(vsync_on_timer_cb, (void *)device);
720         crtc_ega->vsync_off_timer = timer_alloc(vsync_off_timer_cb, (void *)device);
721      }
722   }
723
724   crtc_ega->light_pen_latch_timer = timer_alloc(light_pen_latch_timer_cb, (void *)device);
725
726   /* register for state saving */
727   state_save_combine_module_and_tag(unique_tag, device_tags[device_type], device->tag);
728
729   state_save_register_postload(device->machine, crtc_ega_state_save_postload, crtc_ega);
730
731   state_save_register_item(unique_tag, 0, crtc_ega->clock);
732   state_save_register_item(unique_tag, 0, crtc_ega->hpixels_per_column);
733   state_save_register_item(unique_tag, 0, crtc_ega->register_address_latch);
734   state_save_register_item(unique_tag, 0, crtc_ega->horiz_char_total);
735   state_save_register_item(unique_tag, 0, crtc_ega->horiz_disp);
736   state_save_register_item(unique_tag, 0, crtc_ega->horiz_blank_start);
737   state_save_register_item(unique_tag, 0, crtc_ega->mode_control);
738   state_save_register_item(unique_tag, 0, crtc_ega->cursor_start_ras);
739   state_save_register_item(unique_tag, 0, crtc_ega->cursor_end_ras);
740   state_save_register_item(unique_tag, 0, crtc_ega->disp_start_addr);
741   state_save_register_item(unique_tag, 0, crtc_ega->cursor_addr);
742   state_save_register_item(unique_tag, 0, crtc_ega->light_pen_addr);
743   state_save_register_item(unique_tag, 0, crtc_ega->light_pen_latched);
744   state_save_register_item(unique_tag, 0, crtc_ega->cursor_state);
745   state_save_register_item(unique_tag, 0, crtc_ega->cursor_blink_count);
746   state_save_register_item(unique_tag, 0, crtc_ega->horiz_blank_end);
747   state_save_register_item(unique_tag, 0, crtc_ega->ena_vert_access);
748   state_save_register_item(unique_tag, 0, crtc_ega->de_skew);
749   state_save_register_item(unique_tag, 0, crtc_ega->horiz_retr_start);
750   state_save_register_item(unique_tag, 0, crtc_ega->horiz_retr_end);
751   state_save_register_item(unique_tag, 0, crtc_ega->horiz_retr_skew);
752   state_save_register_item(unique_tag, 0, crtc_ega->vert_total);
753   state_save_register_item(unique_tag, 0, crtc_ega->preset_row_scan);
754   state_save_register_item(unique_tag, 0, crtc_ega->byte_panning);
755   state_save_register_item(unique_tag, 0, crtc_ega->max_ras_addr);
756   state_save_register_item(unique_tag, 0, crtc_ega->scan_doubling);
757   state_save_register_item(unique_tag, 0, crtc_ega->cursor_disable);
758   state_save_register_item(unique_tag, 0, crtc_ega->cursor_skew);
759   state_save_register_item(unique_tag, 0, crtc_ega->vert_retr_start);
760   state_save_register_item(unique_tag, 0, crtc_ega->vert_retr_end);
761   state_save_register_item(unique_tag, 0, crtc_ega->protect);
762   state_save_register_item(unique_tag, 0, crtc_ega->bandwidth);
763   state_save_register_item(unique_tag, 0, crtc_ega->vert_disp_end);
764   state_save_register_item(unique_tag, 0, crtc_ega->offset);
765   state_save_register_item(unique_tag, 0, crtc_ega->underline_loc);
766   state_save_register_item(unique_tag, 0, crtc_ega->vert_blank_start);
767   state_save_register_item(unique_tag, 0, crtc_ega->vert_blank_end);
768   state_save_register_item(unique_tag, 0, crtc_ega->line_compare);
769}
770
771
772static DEVICE_START( crtc_ega )
773{
774   common_start(device, TYPE_CRTC_EGA);
775}
776
777
778static DEVICE_RESET( crtc_ega )
779{
780   crtc_ega_t *crtc_ega = get_safe_token(device);
781
782   /* internal registers other than status remain unchanged, all outputs go low */
783   if (crtc_ega->intf != NULL)
784   {
785      if (crtc_ega->intf->on_de_changed != NULL)
786         crtc_ega->intf->on_de_changed(device, FALSE);
787
788      if (crtc_ega->intf->on_hsync_changed != NULL)
789         crtc_ega->intf->on_hsync_changed(device, FALSE);
790
791      if (crtc_ega->intf->on_vsync_changed != NULL)
792         crtc_ega->intf->on_vsync_changed(device, FALSE);
793   }
794
795   crtc_ega->light_pen_latched = FALSE;
796}
797
798
799static DEVICE_SET_INFO( crtc_ega )
800{
801   switch (state)
802   {
803      /* no parameters to set */
804   }
805}
806
807
808DEVICE_GET_INFO( crtc_ega )
809{
810   switch (state)
811   {
812      /* --- the following bits of info are returned as 64-bit signed integers --- */
813      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(crtc_ega_t);               break;
814      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                        break;
815      case DEVINFO_INT_CLASS:                     info->i = DEVICE_CLASS_PERIPHERAL;         break;
816
817      /* --- the following bits of info are returned as pointers to data or functions --- */
818      case DEVINFO_FCT_SET_INFO:                  info->set_info = DEVICE_SET_INFO_NAME(crtc_ega); break;
819      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(crtc_ega);   break;
820      case DEVINFO_FCT_STOP:                     /* Nothing */                        break;
821      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(crtc_ega);   break;
822
823      /* --- the following bits of info are returned as NULL-terminated strings --- */
824      case DEVINFO_STR_NAME:                     info->s = "IBM EGA CRTC";               break;
825      case DEVINFO_STR_FAMILY:                  info->s = "EGA CRTC";                  break;
826      case DEVINFO_STR_VERSION:                  info->s = "1.00";                     break;
827      case DEVINFO_STR_SOURCE_FILE:               info->s = __FILE__;                     break;
828      case DEVINFO_STR_CREDITS:                  info->s = "Copyright the MESS Team"; break;
829   }
830}
831
832
833DEVICE_GET_INFO( crtc_vga )
834{
835   switch (state)
836   {
837      default:                              DEVICE_GET_INFO_CALL( crtc_ega );         break;
838   }
839}
840
src/mess/video/crtc_ega.h
r0r2755
1/**********************************************************************
2
3    IBM EGA CRT Controller emulation
4
5**********************************************************************/
6
7#ifndef __CRTC_EGA__
8#define __CRTC_EGA__
9
10
11#define CRTC_EGA   DEVICE_GET_INFO_NAME(crtc_ega)
12
13
14/* callback definitions */
15typedef void * (*crtc_ega_begin_update_func)(const device_config *device, bitmap_t *bitmap, const rectangle *cliprect);
16#define CRTC_EGA_BEGIN_UPDATE(name)   void *name(const device_config *device, bitmap_t *bitmap, const rectangle *cliprect)
17
18typedef void (*crtc_ega_update_row_func)(const device_config *device, bitmap_t *bitmap,
19                                 const rectangle *cliprect, UINT16 ma, UINT8 ra,
20                                 UINT16 y, UINT8 x_count, INT8 cursor_x, void *param);
21#define CRTC_EGA_UPDATE_ROW(name)      void name(const device_config *device, bitmap_t *bitmap,   \
22                                      const rectangle *cliprect, UINT16 ma, UINT8 ra,               \
23                                      UINT16 y, UINT8 x_count, INT8 cursor_x, void *param)
24
25typedef void (*crtc_ega_end_update_func)(const device_config *device, bitmap_t *bitmap, const rectangle *cliprect, void *param);
26#define CRTC_EGA_END_UPDATE(name)      void name(const device_config *device, bitmap_t *bitmap, const rectangle *cliprect, void *param)
27
28typedef void (*crtc_ega_on_de_changed_func)(const device_config *device, int display_enabled);
29#define CRTC_EGA_ON_DE_CHANGED(name)   void name(const device_config *device, int display_enabled)
30
31typedef void (*crtc_ega_on_hsync_changed_func)(const device_config *device, int hsync);
32#define CRTC_EGA_ON_HSYNC_CHANGED(name)   void name(const device_config *device, int hsync)
33
34typedef void (*crtc_ega_on_vsync_changed_func)(const device_config *device, int vsync);
35#define CRTC_EGA_ON_VSYNC_CHANGED(name)   void name(const device_config *device, int vsync)
36
37
38/* interface */
39typedef struct _crtc_ega_interface crtc_ega_interface;
40struct _crtc_ega_interface
41{
42   const char *screen_tag;      /* screen we are acting on */
43   int clock;               /* the clock (pin 21) of the chip */
44   int hpixels_per_column;      /* number of pixels per video memory address */
45
46   /* if specified, this gets called before any pixel update,
47       optionally return a pointer that will be passed to the
48       update and tear down callbacks */
49   crtc_ega_begin_update_func      begin_update;
50
51   /* this gets called for every row, the driver must output
52       x_count * hpixels_per_column pixels.
53       cursor_x indicates the character position where the cursor is, or -1
54       if there is no cursor on this row */
55   crtc_ega_update_row_func      update_row;
56
57   /* if specified, this gets called after all row updating is complete */
58   crtc_ega_end_update_func         end_update;
59
60   /* if specified, this gets called for every change of the disply enable pin (pin 18) */
61   crtc_ega_on_de_changed_func      on_de_changed;
62
63   /* if specified, this gets called for every change of the HSYNC pin (pin 39) */
64   crtc_ega_on_hsync_changed_func   on_hsync_changed;
65
66   /* if specified, this gets called for every change of the VSYNC pin (pin 40) */
67   crtc_ega_on_vsync_changed_func   on_vsync_changed;
68};
69
70
71/* device interface */
72DEVICE_GET_INFO( crtc_ega );
73
74/* select one of the registers for reading or writing */
75WRITE8_DEVICE_HANDLER( crtc_ega_address_w );
76
77/* read from the currently selected register */
78READ8_DEVICE_HANDLER( crtc_ega_register_r );
79
80/* write to the currently selected register */
81WRITE8_DEVICE_HANDLER( crtc_ega_register_w );
82
83/* return the current value on the MA0-MA15 pins */
84UINT16 crtc_ega_get_ma(const device_config *device);
85
86/* return the current value on the RA0-RA4 pins */
87UINT8 crtc_ega_get_ra(const device_config *device);
88
89/* simulates the LO->HI clocking of the light pen pin (pin 3) */
90void crtc_ega_assert_light_pen_input(const device_config *device);
91
92/* set the clock (pin 21) of the chip */
93void crtc_ega_set_clock(const device_config *device, int clock);
94
95/* set number of pixels per video memory address */
96void crtc_ega_set_hpixels_per_column(const device_config *device, int hpixels_per_column);
97
98/* updates the screen -- this will call begin_update(),
99   followed by update_row() reapeatedly and after all row
100   updating is complete, end_update() */
101void crtc_ega_update(const device_config *device, bitmap_t *bitmap, const rectangle *cliprect);
102
103
104#endif
src/mess/video/pc_ega.c
r2754r2755
411411
412412#include "driver.h"
413413#include "video/pc_ega.h"
414#include "video/mc6845.h"
414#include "video/crtc_ega.h"
415415#include "video/pc_video.h"
416416#include "memconv.h"
417417
r2754r2755
421421
422422static struct
423423{
424   const device_config   *mc6845;
425   mc6845_update_row_func   update_row;
424   const device_config   *crtc_ega;
425   crtc_ega_update_row_func   update_row;
426426
427427   /* Video memory and related variables */
428428   UINT8   *videoram;
r2754r2755
430430   UINT8   *videoram_a0000;
431431   UINT8   *videoram_b0000;
432432   UINT8   *videoram_b8000;
433   UINT8   *charA;
434   UINT8   *charB;
433435
434436   /* Registers */
435437   UINT8   misc_output;
r2754r2755
459461
460462   UINT8   frame_cnt;
461463   UINT8   vsync;
462   UINT8   hsync;
464   UINT8   display_enable;
463465} ega;
464466
465467
r2754r2755
467469   Prototypes
468470*/
469471static VIDEO_START( pc_ega );
470static VIDEO_UPDATE( mc6845_ega );
472static VIDEO_UPDATE( pc_ega );
471473static PALETTE_INIT( pc_ega );
472static MC6845_UPDATE_ROW( ega_update_row );
473static MC6845_ON_HSYNC_CHANGED( ega_hsync_changed );
474static MC6845_ON_VSYNC_CHANGED( ega_vsync_changed );
474static CRTC_EGA_UPDATE_ROW( ega_update_row );
475static CRTC_EGA_ON_DE_CHANGED( ega_de_changed );
476static CRTC_EGA_ON_VSYNC_CHANGED( ega_vsync_changed );
475477static READ8_HANDLER( pc_ega8_3b0_r );
476478static WRITE8_HANDLER( pc_ega8_3b0_w );
477479static READ16_HANDLER( pc_ega16le_3b0_r );
r2754r2755
495497static WRITE32_HANDLER( pc_ega_videoram32le_w );
496498
497499
498static const mc6845_interface mc6845_ega_intf =
500static const crtc_ega_interface crtc_ega_ega_intf =
499501{
500502   EGA_SCREEN_NAME,   /* screen number */
501503   16257000/8,         /* clock */
r2754r2755
503505   NULL,            /* begin_update */
504506   ega_update_row,      /* update_row */
505507   NULL,            /* end_update */
506   NULL,            /* on_de_chaged */
507   ega_hsync_changed,   /* on_hsync_changed */
508   ega_de_changed,      /* on_de_chaged */
509   NULL,            /* on_hsync_changed */
508510   ega_vsync_changed   /* on_vsync_changed */
509511};
510512
r2754r2755
512514MACHINE_DRIVER_START( pcvideo_ega )
513515   MDRV_SCREEN_ADD(EGA_SCREEN_NAME, RASTER)
514516   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
515   MDRV_SCREEN_RAW_PARAMS(XTAL_14_31818MHz,912,0,640,262,0,200)
517   MDRV_SCREEN_RAW_PARAMS(16257000,912,0,640,262,0,200)
516518   MDRV_PALETTE_LENGTH( 64 )
517519
518520   MDRV_PALETTE_INIT(pc_ega)
519521
520   MDRV_DEVICE_ADD(EGA_MC6845_NAME, MC6845)
521   MDRV_DEVICE_CONFIG( mc6845_ega_intf )
522   MDRV_DEVICE_ADD(EGA_CRTC_NAME, CRTC_EGA)
523   MDRV_DEVICE_CONFIG( crtc_ega_ega_intf )
522524
523525   MDRV_VIDEO_START( pc_ega )
524   MDRV_VIDEO_UPDATE( mc6845_ega )
526   MDRV_VIDEO_UPDATE( pc_ega )
525527MACHINE_DRIVER_END
526528
527529
r2754r2755
633635
634636   pc_ega_install_banks();
635637
636   ega.mc6845 = device_list_find_by_tag(machine->config->devicelist, MC6845, EGA_MC6845_NAME);
638   ega.crtc_ega = device_list_find_by_tag(machine->config->devicelist, CRTC_EGA, EGA_CRTC_NAME);
637639   ega.update_row = NULL;
638640   ega.misc_output = 0;
639641   ega.attribute.index_write = 1;
r2754r2755
658660}
659661
660662
661static VIDEO_UPDATE( mc6845_ega )
663static VIDEO_UPDATE( pc_ega )
662664{
663   mc6845_update( ega.mc6845, bitmap, cliprect);
665   crtc_ega_update( ega.crtc_ega, bitmap, cliprect);
664666   return 0;
665667}
666668
667669
668static MC6845_UPDATE_ROW( ega_update_row )
670static CRTC_EGA_UPDATE_ROW( ega_update_row )
669671{
670672   if ( ega.update_row )
671673   {
r2754r2755
674676}
675677
676678
677static MC6845_ON_HSYNC_CHANGED( ega_hsync_changed )
679static CRTC_EGA_ON_DE_CHANGED( ega_de_changed )
678680{
679   ega.hsync = hsync ? 1 : 0;
681   ega.display_enable = display_enabled ? 1 : 0;
680682}
681683
682684
683static MC6845_ON_VSYNC_CHANGED( ega_vsync_changed )
685static CRTC_EGA_ON_VSYNC_CHANGED( ega_vsync_changed )
684686{
685687   ega.vsync = vsync ? 8 : 0;
686688   if ( vsync )
r2754r2755
690692}
691693
692694
693static MC6845_UPDATE_ROW( pc_ega_graphics )
695static CRTC_EGA_UPDATE_ROW( pc_ega_graphics )
694696{
695697   UINT16   *p = BITMAP_ADDR16(bitmap, y, 0);
696698   int   i;
r2754r2755
702704}
703705
704706
705static MC6845_UPDATE_ROW( pc_ega_text )
707static CRTC_EGA_UPDATE_ROW( pc_ega_text )
706708{
707709   UINT16   *p = BITMAP_ADDR16(bitmap, y, 0);
708710   int   i;
r2754r2755
714716      UINT16   offset = ( ma + i ) << 1;
715717      UINT8   chr = ega.videoram[ offset ];
716718      UINT8   attr = ega.videoram[ offset + 1 ];
717      UINT8   data = ega.videoram[ 0x10000 + chr * 32 + ra ];
719      UINT8   data = ( attr & 0x08 ) ? ega.charA[ chr * 32 + ra ] : ega.charB[ chr * 32 + ra ];
718720      UINT16   fg = ega.attribute.data[ attr & 0x0F ];
719721      UINT16   bg = ega.attribute.data[ attr >> 4 ];
720722
r2754r2755
730732}
731733
732734
733static void pc_ega_change_mode( void )
735static void pc_ega_change_mode( const device_config *device )
734736{
737   int clock, pixels;
738
735739   ega.update_row = NULL;
736740
737741   /* Check for graphics mode */
r2754r2755
758762      }
759763
760764      ega.update_row = pc_ega_text;
765
766      /* Set character maps */
767      if ( ega.sequencer.data[0x04] & 0x02 )
768      {
769         ega.charA = ega.videoram + 0x10000 + ( ( ega.sequencer.data[0x03] & 0x0c ) >> 1 ) * 0x2000;
770         ega.charB = ega.videoram + 0x10000 + ( ega.sequencer.data[0x03] & 0x03 ) * 0x2000;
771      }
772      else
773      {
774         ega.charA = ega.videoram + 0x10000;
775         ega.charB = ega.videoram + 0x10000;
776      }
761777   }
778
779   /* Check for changes to the crtc input clock and number of pixels per clock */
780   clock = ( ( ega.misc_output & 0x0c ) ? 16257000 : XTAL_14_31818MHz );
781   pixels = ( ( ega.sequencer.data[0x01] & 0x01 ) ? 8 : 9 );
782
783   if ( ega.sequencer.data[0x01] & 0x08 )
784   {
785      clock >>= 1;
786   }
787   crtc_ega_set_clock( device, clock / pixels );
788   crtc_ega_set_hpixels_per_column( device, pixels );
762789}
763790
764791
r2754r2755
780807
781808   /* CRT Controller - data register */
782809   case 1: case 3: case 5: case 7:
783      data = mc6845_register_r( ega.mc6845, offset );
810      data = crtc_ega_register_r( ega.crtc_ega, offset );
784811      break;
785812
786813   /* Input Status Register 1 */
787814   case 10:
788      data = ega.vsync | ega.hsync;
815      data = ega.vsync | ega.display_enable;
789816
790817      /* Reset the attirubte writing flip flop to let the next write go to the index reigster */
791818      ega.attribute.index_write = 1;
r2754r2755
807834   {
808835   /* CRT Controller - address register */
809836   case 0: case 2: case 4: case 6:
810      mc6845_address_w( ega.mc6845, offset, data );
837      crtc_ega_address_w( ega.crtc_ega, offset, data );
811838      break;
812839
813840   /* CRT Controller - data register */
814841   case 1: case 3: case 5: case 7:
815      mc6845_register_w( ega.mc6845, offset, data );
842      crtc_ega_register_w( ega.crtc_ega, offset, data );
816843      break;
817844
818845   /* Set Light Pen Flip Flop */
r2754r2755
944971         switch ( index )
945972         {
946973         case 0x10:      /* AR10 */
947            pc_ega_change_mode();
974            pc_ega_change_mode( ega.crtc_ega );
948975            break;
949976         }
950977      }
r2754r2755
954981   /* Misccellaneous Output */
955982   case 2:
956983      ega.misc_output = data;
984      pc_ega_change_mode( ega.crtc_ega );
957985      break;
958986
959987   /* Sequencer */
r2754r2755
971999      switch ( index )
9721000      {
9731001      case 0x01:      /* SR01 */
1002      case 0x03:      /* SR03 */
9741003      case 0x04:      /* SR04 */
975         pc_ega_change_mode();
1004         pc_ega_change_mode( ega.crtc_ega );
9761005         break;
9771006      }
9781007      break;
r2754r2755
9921021      switch ( index )
9931022      {
9941023      case 0x06:      /* GR06 */
995         pc_ega_change_mode();
1024         pc_ega_change_mode( ega.crtc_ega );
9961025         pc_ega_install_banks();
9971026         break;
9981027      }
src/mess/video/pc_ega.h
r2754r2755
11
2#define EGA_SCREEN_NAME "ega_screen"
3#define EGA_MC6845_NAME "mc6845_ega"
2#define EGA_SCREEN_NAME   "ega_screen"
3#define EGA_CRTC_NAME   "crtc_ega_ega"
44
55MACHINE_DRIVER_EXTERN( pcvideo_ega );
66
src/mess/mess.mak
r2754r2755
796796   $(MESS_VIDEO)/pc_cga.o   \
797797   $(MESS_VIDEO)/cgapal.o   \
798798   $(MESS_VIDEO)/pc_vga.o   \
799   $(MESS_VIDEO)/crtc_ega.o   \
799800   $(MESS_VIDEO)/pc_ega.o
800801
801802$(MESSOBJ)/pc.a:      \

Previous 15994 Revisions Next


© 1998-2018 The MESS Team