Previous 15994 Revisions Next

r11539 Friday 13th May, 2011 at 15:11:17 UTC by Miodrag Milanović
Converted dgn_beta to use mame mc6845 code (no whatsnew)
Note: after bbc is converted m6845 can be removed from mess video folder
[src/mess/drivers]dgn_beta.c
[src/mess/includes]dgn_beta.h
[src/mess/machine]dgn_beta.c
[src/mess/video]dgn_beta.c

src/mess/machine/dgn_beta.c
r11538r11539
11011101
11021102   state->m_videoram = ram_get_ptr(machine.device(RAM_TAG));      /* Point video ram at the start of physical ram */
11031103
1104    dgnbeta_video_reset(machine);
11051104    wd17xx_reset(fdc);
11061105    state->m_wd2797_written=0;
11071106}
r11538r11539
11111110   dgn_beta_state *state = machine.driver_data<dgn_beta_state>();
11121111   logerror("MACHINE_START( dgnbeta )\n");
11131112
1114    dgnbeta_init_video(machine);
1115
11161113   if (machine.device<cpu_device>(MAINCPU_TAG)->debug()) {
11171114      machine.device<cpu_device>(MAINCPU_TAG)->debug()->set_dasm_override(dgnbeta_dasm_override);
11181115   }
src/mess/includes/dgn_beta.h
r11538r11539
77#ifndef DGN_BETA_H_
88#define DGN_BETA_H_
99
10#include "video/mc6845.h"
1011#include "machine/wd17xx.h"
1112#include "machine/6821pia.h"
1213
r11538r11539
8485{
8586public:
8687   dgn_beta_state(const machine_config &mconfig, device_type type, const char *tag)
87      : driver_device(mconfig, type, tag) { }
88      : driver_device(mconfig, type, tag),
89        m_mc6845(*this, "crtc")
90      { }
8891
8992   UINT8 *m_videoram;
9093   UINT8 *m_system_rom;
r11538r11539
137140   int m_ColourRAM[4];
138141   int m_Field;
139142   int m_DrawInterlace;
143   
144   required_device<device_t> m_mc6845;
140145};
141146
142147
r11538r11539
162167/*----------- defined in video/dgn_beta.c -----------*/
163168
164169/* mc6845 video display generator */
165void dgnbeta_init_video(running_machine &machine);
166void dgnbeta_video_reset(running_machine &machine);
167170extern SCREEN_UPDATE( dgnbeta );
168171void dgnbeta_vid_set_gctrl(running_machine &machine, int data);
169172
170173/* 74HC670 4x4bit colour ram */
171174WRITE8_HANDLER(dgnbeta_colour_ram_w);
172175
173READ8_HANDLER(dgnbeta_6845_r);
174WRITE8_HANDLER(dgnbeta_6845_w);
176extern const mc6845_interface dgnbeta_crtc6845_interface;
175177
176
177178#endif /* DGN_BETA_H_ */
src/mess/video/dgn_beta.c
r11538r11539
8181
8282#include "emu.h"
8383#include "includes/dgn_beta.h"
84#include "video/m6845.h"
85#include "machine/ram.h"
8684
87#include "debug/debugcpu.h"
88#include "debug/debugcon.h"
89
90#define LOG_VIDEO
91
92/* Names for 6845 regs, to save having to remember their offsets */
93/* perhaps these should move into 6845 header ? */
94typedef enum {
95   H_TOTAL = 0,      // Horizontal total
96   H_DISPLAYED,      // Horizontal displayed
97   H_SYNC_POS,          // Horizontal sync pos
98   H_SYNC_WIDTH,      // Horizontal sync width
99   V_TOTAL,          // Vertical total
100   V_TOTAL_ADJ,      // Vertical total adjust
101   V_DISPLAYED,      // Vertical displayed
102   V_SYNC_POS,          // Vertical sync pos
103   INTERLACE,          // Interlace
104   MAX_SCAN,          // Maximum scan line
105   CURS_START,          // Cursor start pos
106   CURS_END,          // Cursor end pos
107   START_ADDR_H,      // Start address High
108   START_ADDR_L,      // Start address low
109   CURS_H,             // Cursor addr High
110   CURS_L             // CURSOR addr Low
111} m6845_regs;
112
113
114//static BETA_VID_MODES VIDMODE = TEXT_40x25;
115
116/* Debugging variables */
117
118/* Debugging commands and handlers. */
119static void execute_beta_vid_log(running_machine &machine, int ref, int params, const char *param[]);
120static void RegLog(running_machine &machine, int offset, int data);
121static void execute_beta_vid_fill(running_machine &machine, int ref, int params, const char *param[]);
122static void execute_beta_vid_box(running_machine &machine, int ref, int params, const char *param[]);
123static void execute_beta_vid(running_machine &machine, int ref, int params, const char *param[]);
124static void execute_beta_vid_limits(running_machine &machine, int ref, int params, const char *param[]);
125static void execute_beta_vid_clkmax(running_machine &machine, int ref, int params, const char *param[]);
126
127
128
129static void beta_Set_RA(running_machine &machine, int offset, int data);
130static void beta_Set_HSync(running_machine &machine, int offset, int data);
131static void beta_Set_VSync(running_machine &machine, int offset, int data);
132static void beta_Set_DE(running_machine &machine, int offset, int data);
133
134static const struct m6845_interface beta_m6845_interface = {
135   0,              // Memory Address register
136   beta_Set_RA,   // Row Address register
137   beta_Set_HSync,   // Horizontal status
138   beta_Set_VSync,   // Vertical status
139   beta_Set_DE,   // Display Enabled status
140   0,              // Cursor status
141   0
142};
143
144
145
146
147
148typedef enum {
149   INTERLACE_OFF=0,   /* No interlace mode, normal drawing */
150   INTERLACE_ON=1,      /* Interlaced mode, use Field to determine which field to draw */
151   INTERLACE_AT_VS=2   /* Turn on interlace at next VSync, then go to INTERLACE */
152} INTERLACE_MODES;
153
154#define Background   1   /* Background colour, red now so I can see where border is ! */
155
15685/* GCtrl bitmasks, infered from bits of Beta schematic */
15786#define GCtrlWI      0x01
15887#define GCtrlSWChar   0x02   /* Character set select */
r11538r11539
16796#define IsGfx2      ((state->m_GCtrl & GCtrlHiLo) && (~state->m_GCtrl & GCtrlFS)) ? 1 : 0      // Is this a 2 colour mode
16897#define SWChar      (state->m_GCtrl & GCtrlSWChar)>>1               // Swchar bit
16998
170//static int beta_state;
171
172/* Set video control register from I28 port B, the control register is laid out as */
173/* follows :-                                                                      */
174/*  bit function                               */
175/*  0   WI, unknown                            */
176/*  1   Character set select, drives A12 of character rom in text mode     */
177/*  2   High (1) or Low(0) resolution if in graphics mode.         */
178/*  3   Text (1) or Graphics(0) mode                       */
179/*  4   Control bit, Selects between colour palate and drirect drive       */
180/*  5   F/S bit, 1=80 bytes/line, 0=40bytes/line               */
181/*  6   Effective A14, to ram, in text mode                    */
182/*  7   Effective A15, to ram, in text mode                */
183/* the top two address lines for the video ram, are supplied by the BB6 and PB7 on */
184/* 6821-I28, this allows the 6845 to access the full 64K address range, however    */
185/* since the ram data is addressed as a 16bit wide unit, this allows the 6845      */
186/* access to the first 128K or ram.                                                */
187void dgnbeta_vid_set_gctrl(running_machine &machine, int data)
99static MC6845_UPDATE_ROW( dgnbeta_update_row )
188100{
189   dgn_beta_state *state = machine.driver_data<dgn_beta_state>();
190   state->m_GCtrl=data;
191   if (state->m_LogRegWrites)
192      debug_console_printf(machine, "I28-PB=$%2X, %2X-%s-%s-%s-%s-%s-%s PC=%4X\n",
193                 data,
194                 data & GCtrlAddrLines,
195                 data & GCtrlFS       ? "FS" : "  ",
196                 data & GCtrlControl   ? "CT" : "  ",
197                 data & GCtrlChrGfx      ? "Ch" : "Gf",
198                 data & GCtrlHiLo      ? "Hi" : "Lo",
199                 data & GCtrlSWChar      ? "C0" : "C1",
200                 data & GCtrlWI      ? "Wi" : "  ",
201                 cpu_get_pc(machine.device("maincpu")));
202}
203
204// called when the 6845 changes the character row
205static void beta_Set_RA(running_machine &machine, int offset, int data)
206{
207   dgn_beta_state *state = machine.driver_data<dgn_beta_state>();
208   state->m_beta_6845_RA=data;
209}
210
211// called when the 6845 changes the HSync
212static void beta_Set_HSync(running_machine &machine, int offset, int data)
213{
214   dgn_beta_state *state = machine.driver_data<dgn_beta_state>();
215   int Dots;   /* Pixels per 16 bits */
216
217   state->m_beta_HSync=data;
218
219   if(IsGfx16)
220      Dots=2;
221   else
222      Dots=8;
223
224   if(!state->m_beta_HSync)
225   {
226      int HT=m6845_get_register(H_TOTAL);             // Get H total
227      int HS=m6845_get_register(H_SYNC_POS);          // Get Hsync pos
228      int HW=m6845_get_register(H_SYNC_WIDTH)&0xF;   // Hsync width (in chars)
229
230      state->m_beta_scr_y++;
231//      state->m_beta_scr_x=0-(((HT-HS)-HW)*8);  // Number of dots after HS to wait before start of next line
232      state->m_beta_scr_x=0-((HT-(HS+HW))*Dots);
233
234//debug_console_printf(machine, "HT=%d, HS=%d, HW=%d, (HS+HW)=%d, HT-(HS+HW)=%d\n",HT,HS,HW,(HS+HW),(HT-(HS+HW)));
235//debug_console_printf(machine, "Scanline=%d, row=%d\n",m6845_get_scanline_counter(),m6845_get_row_counter());
236      state->m_HSyncMin=state->m_beta_scr_x;
237   }
238}
239
240// called when the 6845 changes the VSync
241static void beta_Set_VSync(running_machine &machine, int offset, int data)
242{
243   dgn_beta_state *state = machine.driver_data<dgn_beta_state>();
244   state->m_beta_VSync=data;
245   if (!state->m_beta_VSync)
246   {
247      state->m_beta_scr_y = -20;
248      state->m_FlashCount++;
249      if(state->m_FlashCount==10)
250      {
251         state->m_FlashCount=0;         // Reset counter
252         state->m_FlashBit=(!state->m_FlashBit) & 0x01;   // Invert flash bit.
253      }
254
255      if (state->m_DrawInterlace==INTERLACE_AT_VS)
256      {
257         state->m_DrawInterlace=INTERLACE_ON;
258         state->m_Field=0;
259      }
260      else if (state->m_DrawInterlace==INTERLACE_ON)
261      {
262         state->m_Field=(state->m_Field+1) & 0x01;   /* Invert field */
263//          debug_console_printf(machine, "Invert field=%d\n",state->m_Field);
264      }
265      state->m_VSyncMin=state->m_beta_scr_y;
266   }
267
268   dgn_beta_frame_interrupt(machine, data);
269}
270
271static void beta_Set_DE(running_machine &machine, int offset, int data)
272{
273   dgn_beta_state *state = machine.driver_data<dgn_beta_state>();
274   state->m_beta_DE = data;
275
276   if(state->m_beta_DE)
277      state->m_DEPos=state->m_beta_scr_x;
278}
279
280/* Video init */
281void dgnbeta_init_video(running_machine &machine)
282{
283   dgn_beta_state *state = machine.driver_data<dgn_beta_state>();
101   dgn_beta_state *state = device->machine().driver_data<dgn_beta_state>();
284102   UINT8 *videoram = state->m_videoram;
285   /* initialise 6845 */
286   m6845_config(&beta_m6845_interface);
287   m6845_set_personality(M6845_PERSONALITY_HD6845S);
288
289   state->m_GCtrl=0;
290
291   videoram=ram_get_ptr(machine.device(RAM_TAG));
292
293   state->m_ClkMax=65000;
294   state->m_FlashCount=0;
295   state->m_FlashBit=0;
296   state->m_DoubleHL=1;         /* Default to normal height */
297   state->m_s_DoubleY=1;
298   state->m_DrawInterlace=INTERLACE_OFF;   /* No interlace by default */
299
300   /* setup debug commands */
301   if (machine.debug_flags & DEBUG_FLAG_ENABLED)
103   UINT16  *p = BITMAP_ADDR16(bitmap, y, 0);
104   int i;
105   if(IsTextMode)
302106   {
303      debug_console_register_command(machine, "beta_vid_log", CMDFLAG_NONE, 0, 0, 0, execute_beta_vid_log);
304      debug_console_register_command(machine, "beta_vid_fill", CMDFLAG_NONE, 0, 0, 0, execute_beta_vid_fill);
305      debug_console_register_command(machine, "beta_vid_box", CMDFLAG_NONE, 0, 0, 5, execute_beta_vid_box);
306      debug_console_register_command(machine, "beta_vid", CMDFLAG_NONE, 0, 0, 0, execute_beta_vid);
307      debug_console_register_command(machine, "beta_vid_limits", CMDFLAG_NONE, 0, 0, 0, execute_beta_vid_limits);
308      debug_console_register_command(machine, "beta_vid_clkmax", CMDFLAG_NONE, 0, 0, 1, execute_beta_vid_clkmax);
309   }
310   state->m_LogRegWrites=0;
311   state->m_BoxColour=1;
312   state->m_BoxMinX      = 100;
313   state->m_BoxMinY      = 100;
314   state->m_BoxMaxX      = 500;
315   state->m_BoxMaxY      = 500;
316
317   state->m_MinAddr       = 0xFFFF;
318   state->m_MaxAddr       = 0x0000;
319   state->m_MinX           = 0xFFFF;
320   state->m_MaxX           = 0x0000;
321   state->m_MinY           = 0xFFFF;
322   state->m_MaxY           = 0x0000;
323}
324
325void dgnbeta_video_reset(running_machine &machine)
326{
327    logerror("dgnbeta_video_reset\n");
328    m6845_reset();
329}
330
331/**************************/
332/** Text screen handlers **/
333/**************************/
334
335/* Plot a pixel on beta text screen, takes care of doubling height and width where needed */
336static void plot_text_pixel(dgn_beta_state *state, bitmap_t *bitmap, int x, int y,int Dot,int Colour, int CharsPerLine)
337{
338   int PlotX;
339   int PlotY;
340   int Double = (~state->m_GCtrl & GCtrlHiLo);
341
342   /* We do this so that we can plot 40 column characters twice as wide */
343   if(Double)
344   {
345      PlotX=(x+Dot)*2;
346   }
347   else
348   {
349      PlotX=(x+Dot);
350   }
351
352   PlotY=y*2;
353
354   /* Error check, make sure we're drawing onm the actual bitmap ! */
355   if (((PlotX+1)<bitmap->width) && ((PlotY+1)<bitmap->height))
356   {
357      /* As the max resolution of the beta is 640x512, we need to draw characters */
358      /* 2 pixel lines high as the with a screen of 40 or 80 by 25 lines of 10 pixels high */
359      /* the effective character to pixel resolution is 320x250 or 640x250 */
360      /* Plot characters twice as wide in 40 col mode */
361      if(Double)
107      UINT8 *chr_gen = device->machine().region("gfx1")->base();
108      for ( i = 0; i < x_count; i++ )
362109      {
363         *BITMAP_ADDR16(bitmap, (PlotY+0), (PlotX+0)) = Colour;
364         *BITMAP_ADDR16(bitmap, (PlotY+0), (PlotX+1)) = Colour;
110         UINT16 offset = ( (( ma + i ) << 1 ) | ((state->m_GCtrl & GCtrlAddrLines)<<8));
365111
366         *BITMAP_ADDR16(bitmap, (PlotY+1), (PlotX+0)) = Colour;
367         *BITMAP_ADDR16(bitmap, (PlotY+1), (PlotX+1)) = Colour;
368      }
369      else
370      {
371         *BITMAP_ADDR16(bitmap, (PlotY+0), PlotX) = Colour;
372         *BITMAP_ADDR16(bitmap, (PlotY+1), PlotX) = Colour;
373      }
374   }
375}
112         UINT8 chr = videoram[ offset ];
113         UINT8 attr = videoram[ offset +1 ];
376114
377static void beta_plot_char_line(running_machine &machine, int x,int y, bitmap_t *bitmap)
378{
379   dgn_beta_state *state = machine.driver_data<dgn_beta_state>();
380   UINT8 *videoram = state->m_videoram;
381   int CharsPerLine   = m6845_get_register(H_DISPLAYED);   // Get chars per line.
382   unsigned char *data = machine.region("gfx1")->base();      // ptr to char rom
383   int Dot;
384   unsigned char data_byte;
385   int char_code;
386   int crtcAddr;                     // Character to draw
387   int Offset;
388   int FgColour;                     // Foreground colour
389   int BgColour;                     // Background colour
390   int CursorOn      = m6845_cursor_enabled_r(0);
391   int Invert;
392   int UnderLine;                     // Underline
393   int FlashChar;                     // Flashing char
394   int ULActive;                     // Underline active
115         /* Extract non-colour attributes, in character set 1, undeline is used */
116         /* We will extract the colours below, when we have decoded inverse */
117         /* to indicate a double height character */
118         int UnderLine=(attr & 0x40) >> 6; // Underline active
119         int   FlashChar=(attr & 0x80) >> 7; // Flashing char
395120
396   state->m_bit=bitmap;
121         // underline is active for character set 0, on character row 9
122         int ULActive=(UnderLine && (ra==9) && ~SWChar);
397123
398   if (state->m_beta_DE)
399   {
400      /* The beta text RAM contains alternate character and attribute bytes */
401      /* Top two address lines from PIA, IC28 PB6,7 */
402      crtcAddr=m6845_memory_address_r(0)-1;
403      Offset=(crtcAddr | ((state->m_GCtrl & GCtrlAddrLines)<<8))*2;
404      if (Offset<0)
405         Offset=0;
124         /* Invert forground and background if flashing char and flash acive */
125         int Invert=(FlashChar & state->m_FlashBit);
406126
407      /* Get the character to display */
408      char_code   = videoram[Offset];
127         /* Underline inverts flash */
128         if (ULActive)
129            Invert=~Invert;
409130
410      /* Extract non-colour attributes, in character set 1, undeline is used */
411      /* We will extract the colours below, when we have decoded inverse */
412      /* to indicate a double height character */
413      UnderLine=(videoram[Offset+1] & 0x40) >> 6;
414      FlashChar=(videoram[Offset+1] & 0x80) >> 7;
131         /* Cursor on also inverts */
132         if (i == cursor_x)
133            Invert=~Invert;
415134
416      // underline is active for character set 0, on character row 9
417      ULActive=(UnderLine && (state->m_beta_6845_RA==9) && ~SWChar);
418
419      /* If Character set one, and undeline set, latch double height */
420      state->m_s_DoubleY=(UnderLine & SWChar & state->m_DoubleHL) |
421              (SWChar & ~state->m_s_DoubleY & state->m_DoubleHL) |
422         (SWChar & ~state->m_s_DoubleY & (state->m_beta_6845_RA==9));
423
424      /* Invert forground and background if flashing char and flash acive */
425      Invert=(FlashChar & state->m_FlashBit);
426
427      /* Underline inverts flash */
428      if (ULActive)
429         Invert=~Invert;
430
431      /* Cursor on also inverts */
432      if (CursorOn)
433         Invert=~Invert;
434
435      /* Invert colours if invert is true */
436      if(!Invert)
437      {
438         FgColour   = (videoram[Offset+1] & 0x38) >> 3;
439         BgColour   = (videoram[Offset+1] & 0x07);
440      }
441      else
442      {
443         BgColour   = (videoram[Offset+1] & 0x38) >> 3;
444         FgColour   = (videoram[Offset+1] & 0x07);
445      }
446
447      /* The beta Character ROM has characters of 8x10, each aligned to a 16 byte boundry */
448      data_byte = data[(char_code*16) + state->m_beta_6845_RA];
449
450      for (Dot=0; Dot<8; Dot++)
451      {
452         if (data_byte & 0x080)
453            plot_text_pixel(state, bitmap, x, y, Dot, FgColour, CharsPerLine);
135         UINT16 fg = 0;
136         UINT16 bg = 0;
137         
138         /* Invert colours if invert is true */
139         if(!Invert)
140         {
141            fg   = (attr & 0x38) >> 3;
142            bg   = (attr & 0x07);
143         }
454144         else
455            plot_text_pixel(state, bitmap, x, y, Dot, BgColour, CharsPerLine);
145         {
146            bg   = (attr & 0x38) >> 3;
147            fg   = (attr & 0x07);
148         }
456149
457         data_byte = data_byte<<1;
458      }
459   }
460   else
461   {
462      for (Dot=0; Dot<8; Dot++)
463         plot_text_pixel(state, bitmap, x, y, Dot, Background, CharsPerLine);
150         
151         
152         UINT8 data = chr_gen[ chr * 16 + ra ];
464153
465   }
466
467}
468
469/******************************/
470/** Graphics screen handlers **/
471/******************************/
472
473/* Plot a pixel on the graphics screen, similar to character plotter above */
474/* May merge at some point in the future, if they turn out to be sufficiently similar ! */
475static void plot_gfx_pixel(dgn_beta_state *state, bitmap_t *bitmap, int x, int y, int Dot, int Colour)
476{
477   int   DoubleX      = (~state->m_GCtrl & GCtrlHiLo) ? 1 : 0;
478   int   DoubleY      = (~m6845_get_register(INTERLACE) & 0x03) ? 1 : 0;
479   int   PlotX;
480   int   PlotY;
481
482   if (DoubleX)
483      PlotX=(x+Dot)*2;
484   else
485      PlotX=x+Dot;
486
487   if(DoubleY)
488      PlotY=(y)*2;
489   else
490      PlotY=y;
491
492   if(state->m_DrawInterlace==INTERLACE_ON)
493   {
494      PlotY=(y*2);//+state->m_Field;
495      DoubleY=0;
496//      debug_console_printf(machine, "Field=%d\n",state->m_Field);
497   }
498
499   /* Error check, make sure we're drawing on the actual bitmap ! */
500   if (((PlotX+1)<bitmap->width) && ((PlotY+1)<bitmap->height))
501   {
502      /* As the max resolution of the beta is 640x512, we need to draw pixels */
503      /* twice as high and twice as wide when plotting in 320x modes */
504      if(DoubleX)
505      {
506         *BITMAP_ADDR16(bitmap, (PlotY+0), (PlotX+0)) = Colour;
507         *BITMAP_ADDR16(bitmap, (PlotY+0), (PlotX+1)) = Colour;
154         *p = ( data & 0x80 ) ? fg : bg; p++;
155         *p = ( data & 0x80 ) ? fg : bg; p++;
156         *p = ( data & 0x40 ) ? fg : bg; p++;
157         *p = ( data & 0x40 ) ? fg : bg; p++;
158         *p = ( data & 0x20 ) ? fg : bg; p++;
159         *p = ( data & 0x20 ) ? fg : bg; p++;
160         *p = ( data & 0x10 ) ? fg : bg; p++;
161         *p = ( data & 0x10 ) ? fg : bg; p++;
162         *p = ( data & 0x08 ) ? fg : bg; p++;
163         *p = ( data & 0x08 ) ? fg : bg; p++;
164         *p = ( data & 0x04 ) ? fg : bg; p++;
165         *p = ( data & 0x04 ) ? fg : bg; p++;
166         *p = ( data & 0x02 ) ? fg : bg; p++;
167         *p = ( data & 0x02 ) ? fg : bg; p++;
168         *p = ( data & 0x01 ) ? fg : bg; p++;
169         *p = ( data & 0x01 ) ? fg : bg; p++;
508170      }
509
510      /* Plot pixels twice as high if in x256 modes */
511      if (DoubleY)
512      {
513         *BITMAP_ADDR16(bitmap, (PlotY+1), (PlotX+0)) = Colour;
514         *BITMAP_ADDR16(bitmap, (PlotY+1), (PlotX+1)) = Colour;
515      }
516
517      if (~(DoubleX | DoubleY))
518      {
519         *BITMAP_ADDR16(bitmap, PlotY, PlotX) = Colour;
520      }
521   }
522}
523
524/* Get and plot a graphics bixel block */
525
526static void beta_plot_gfx_line(running_machine &machine,int x,int y, bitmap_t *bitmap)
527{
528   dgn_beta_state *state = machine.driver_data<dgn_beta_state>();
529   UINT8 *videoram = state->m_videoram;
530   int crtcAddr;
531   int Addr;
532   int Red;
533   int Green;
534   int Blue;
535   int Intense;
536   int Colour;
537   int Dot;
538   int Hi;
539   int Lo;
540   int Word;
541   int Dots;   /* pixesls per byte */
542
543   /* We have to do this here so that it is correct for border and drawing area ! */
544   if (IsGfx16)
545      Dots=4;
546   else if (IsGfx2)
547      Dots=16;
171   
172   }   
548173   else
549      Dots=8;
550
551   if (state->m_beta_DE)
552174   {
553      /* Calculate address of graphics pixels */
554      crtcAddr=(m6845_memory_address_r(0) & 0x1FFF);
555      Addr=((crtcAddr<<3) | (state->m_beta_6845_RA & 0x07))*2;
556
557      if(Addr<state->m_MinAddr)
558         state->m_MinAddr=Addr;
559
560      if(Addr>state->m_MaxAddr)
561         state->m_MaxAddr=Addr;
562
563      if(x>state->m_MaxX) state->m_MaxX=x;
564      if(x<state->m_MinX) state->m_MinX=x;
565      if(y>state->m_MaxY) state->m_MaxY=y;
566      if(y<state->m_MinY) state->m_MinY=y;
567
568      Lo   = videoram[Addr];
569      Hi   = videoram[Addr+1];
570      Word   = (Hi<<8) | Lo;
571
572      /* If contol is low then we are plotting 4 bit per pixel, 16 colour mode */
573      /* This directly drives the colour output lines, from the pixel value */
574      /* If Control is high, then we lookup the colour from the LS670 4x4 bit */
575      /* palate register */
576      if (IsGfx16)
175      for ( i = 0; i < x_count; i++ )
577176      {
578         Intense   =(Lo & 0x0F);
579         Red   =(Lo & 0xF0)>>4;
580         Green   =(Hi & 0x0F);
581         Blue   =(Hi & 0xF0)>>4;
582         Colour=((Intense&0x08) | (Red&0x08)>>1) | ((Green&0x08)>>2) | ((Blue&0x08)>>3);
177         UINT16 offset = ((((ma + i ) & 0x1FFF) << 3) | (ra & 0x07)) << 1;
178     
179         UINT8 Lo = videoram[ offset ];
180         UINT8 Hi = videoram[ offset +1 ];
181         UINT16 Word   = (Hi<<8) | Lo;
182         int Red;
183         int Green;
184         int Blue;
185         int Intense;
186         int Colour;
187         int Dot;
583188
584         for (Dot=0;Dot<Dots;Dot++)
189         /* If contol is low then we are plotting 4 bit per pixel, 16 colour mode */
190         /* This directly drives the colour output lines, from the pixel value */
191         /* If Control is high, then we lookup the colour from the LS670 4x4 bit */
192         /* palate register */
193         if (IsGfx16)
585194         {
586            plot_gfx_pixel(state,bitmap,x,y,Dot,Colour);
195            Intense   =(Lo & 0x0F);
196            Red   =(Lo & 0xF0)>>4;
197            Green   =(Hi & 0x0F);
198            Blue   =(Hi & 0xF0)>>4;
199            Colour=((Intense&0x08) | (Red&0x08)>>1) | ((Green&0x08)>>2) | ((Blue&0x08)>>3);
587200
588            Intense   =Intense<<1;
589            Red   =Red<<1;
590            Green   =Green<<1;
591            Blue   =Blue<<1;
201            for (Dot=0;Dot<4;Dot++)
202            {               
203               *p = Colour; p++;
204               *p = Colour; p++;
205               *p = Colour; p++;
206               *p = Colour; p++;
207               
208               Intense   =Intense<<1;
209               Red   =Red<<1;
210               Green   =Green<<1;
211               Blue   =Blue<<1;
212            }
592213         }
593      }
594      else if (IsGfx2)
595      {
596         for (Dot=0;Dot<Dots;Dot=Dot+1)
214         else if (IsGfx2)
597215         {
598            Colour=state->m_ColourRAM[((Word&0x8000)>>15)];
599            plot_gfx_pixel(state,bitmap,x,y,Dot,Colour);
216            for (Dot=0;Dot<16;Dot=Dot+1)
217            {
218               Colour=state->m_ColourRAM[((Word&0x8000)>>15)];
219               
220               *p = Colour; p++;
600221
601//              Colour=state->m_ColourRAM[((Word&0x0080)>>7)];
602//              plot_gfx_pixel(state,bitmap,x,y,Dot+1,Colour);
603
604            Hi=Word&0x8000;
605            Word=((Word<<1)&0xFFFE) | (Hi>>15);
222               Hi=(Word&0x8000) >> 15;
223               Word=((Word<<1)&0xFFFE) | Hi;
224            }
606225         }
607      }
608      else
609      {
610         for (Dot=0;Dot<Dots;Dot++)
226         else
611227         {
612            Colour=state->m_ColourRAM[((Word&0x8000)>>14) | ((Word&0x80)>>7)];
613            plot_gfx_pixel(state,bitmap,x,y,Dot,Colour);
614
615            Hi=Word&0x8000;
616            Word=((Word<<1)&0xFFFE) | (Hi>>15);
617         }
228            for (Dot=0;Dot<8;Dot++)
229            {
230               Colour=state->m_ColourRAM[((Word&0x8000)>>14) | ((Word&0x80)>>7)];               
231               *p = Colour; p++;
232               *p = Colour; p++;
233               
234               Hi=(Word&0x8000) >> 15;
235               Word=((Word<<1)&0xFFFE) | Hi;
236            }
237         }   
618238      }
619
620239   }
621   else
622   {
623      for (Dot=0;Dot<Dots;Dot++)
624      {
625         plot_gfx_pixel(state,bitmap,x,y,Dot,Background);
626      }
627   }
628}
629240
630/* Update video screen, calls either text or graphics update routine as needed */
631SCREEN_UPDATE( dgnbeta )
632{
633   dgn_beta_state *state = screen->machine().driver_data<dgn_beta_state>();
634   long c=0; // this is used to time out the screen redraw, in the case that the 6845 is in some way out state.
635
636   state->m_bit=bitmap;
637
638   c=0;
639
640   // loop until the end of the Vertical Sync pulse
641   while((state->m_beta_VSync)&&(c<state->m_ClkMax))
642   {
643      // Clock the 6845
644      m6845_clock(screen->machine());
645      c++;
646   }
647
648   // loop until the Vertical Sync pulse goes high
649   // or until a timeout (this catches the 6845 with silly register values that would not give a VSYNC signal)
650   while((!state->m_beta_VSync)&&(c<state->m_ClkMax))
651   {
652      while ((state->m_beta_HSync)&&(c<state->m_ClkMax))
653      {
654         m6845_clock(screen->machine());
655         c++;
656      }
657
658      while ((!state->m_beta_HSync)&&(c<state->m_ClkMax))
659      {
660         // check that we are on the emulated screen area.
661         if ((state->m_beta_scr_x>=0) && (state->m_beta_scr_x<699) && (state->m_beta_scr_y>=0) && (state->m_beta_scr_y<549))
662         {
663            if(IsTextMode)
664               beta_plot_char_line(screen->machine(), state->m_beta_scr_x, state->m_beta_scr_y, bitmap);
665            else
666               beta_plot_gfx_line(screen->machine(), state->m_beta_scr_x, state->m_beta_scr_y, bitmap);
667         }
668
669         /* In direct drive mode we have 4bpp, so 4 pixels per word, so increment x by 4 */
670         /* In lookup mode we have 2bpp, so 8 pixels per word, so increment by 8 */
671         /* In text mode characters are 8 pixels wide, so increment by 8 */
672         if (IsGfx16)
673            state->m_beta_scr_x+=4;
674         else if (IsGfx2)
675            state->m_beta_scr_x+=16;
676         else
677            state->m_beta_scr_x+=8;
678
679         // Clock the 6845
680         m6845_clock(screen->machine());
681         c++;
682      }
683   }
684   return 0;
685241}
686242
687/* Read and write handlers for CPU interface to 6845 */
688READ8_HANDLER(dgnbeta_6845_r)
689{
690   return m6845_register_r(offset);
691}
243static WRITE_LINE_DEVICE_HANDLER( dgnbeta_vsync_changed )
244{   
245   dgn_beta_state *st = device->machine().driver_data<dgn_beta_state>();
692246
693WRITE8_HANDLER(dgnbeta_6845_w)
694{
695   dgn_beta_state *state = space->machine().driver_data<dgn_beta_state>();
696   if(offset&0x1)
247   st->m_beta_VSync=state;
248   if (!st->m_beta_VSync)
697249   {
698      m6845_register_w(offset,data);
699
700      if(state->m_VidAddr==INTERLACE)
250      st->m_FlashCount++;
251      if(st->m_FlashCount==10)
701252      {
702         state->m_DrawInterlace=(data & 0x03) ? INTERLACE_AT_VS : INTERLACE_OFF;
253         st->m_FlashCount=0;         // Reset counter
254         st->m_FlashBit=(!st->m_FlashBit) & 0x01;   // Invert flash bit.
703255      }
704256   }
705   else
706   {
707      m6845_address_w(offset,data);
708      state->m_VidAddr=data;                    /* Record reg being written to */
709   }
710   if (state->m_LogRegWrites)
711      RegLog(space->machine(), offset,data);
712}
713257
714/* Write handler for colour, pallate ram */
715WRITE8_HANDLER(dgnbeta_colour_ram_w)
716{
717   dgn_beta_state *state = space->machine().driver_data<dgn_beta_state>();
718   state->m_ColourRAM[offset]=data&0x0f;         /* Colour ram 4 bit and write only to CPU */
258   dgn_beta_frame_interrupt(device->machine(), state);
719259}
720260
721/*************************************
722 *
723 *  Debugging
724 *
725 *************************************/
726
727static void execute_beta_vid_log(running_machine &machine, int ref, int params, const char *param[])
261const mc6845_interface dgnbeta_crtc6845_interface =
728262{
729   dgn_beta_state *state = machine.driver_data<dgn_beta_state>();
730   state->m_LogRegWrites=!state->m_LogRegWrites;
263   "screen",
264   16 /*?*/,
265   NULL,
266   dgnbeta_update_row,
267   NULL,
268   DEVCB_NULL,
269   DEVCB_NULL,
270   DEVCB_NULL,
271   DEVCB_LINE(dgnbeta_vsync_changed),
272   NULL
273};
731274
732   debug_console_printf(machine, "6845 register write info set : %d\n",state->m_LogRegWrites);
733}
734275
735
736static void RegLog(running_machine &machine, int offset, int data)
276/* Set video control register from I28 port B, the control register is laid out as */
277/* follows :-                                                                      */
278/*  bit function                               */
279/*  0   WI, unknown                            */
280/*  1   Character set select, drives A12 of character rom in text mode     */
281/*  2   High (1) or Low(0) resolution if in graphics mode.         */
282/*  3   Text (1) or Graphics(0) mode                       */
283/*  4   Control bit, Selects between colour palate and drirect drive       */
284/*  5   F/S bit, 1=80 bytes/line, 0=40bytes/line               */
285/*  6   Effective A14, to ram, in text mode                    */
286/*  7   Effective A15, to ram, in text mode                */
287/* the top two address lines for the video ram, are supplied by the BB6 and PB7 on */
288/* 6821-I28, this allows the 6845 to access the full 64K address range, however    */
289/* since the ram data is addressed as a 16bit wide unit, this allows the 6845      */
290/* access to the first 128K or ram.                                                */
291void dgnbeta_vid_set_gctrl(running_machine &machine, int data)
737292{
738293   dgn_beta_state *state = machine.driver_data<dgn_beta_state>();
739   char   RegName[16];
740
741   switch (state->m_VidAddr)
742   {
743      case H_TOTAL      : sprintf(RegName,"H Total      "); break;
744      case H_DISPLAYED   : sprintf(RegName,"H Displayed  "); break;
745      case H_SYNC_POS      : sprintf(RegName,"H Sync Pos   "); break;
746      case H_SYNC_WIDTH   : sprintf(RegName,"H Sync Width "); break;
747      case V_TOTAL      : sprintf(RegName,"V Total      "); break;
748      case V_TOTAL_ADJ   : sprintf(RegName,"V Total Adj  "); break;
749      case V_DISPLAYED   : sprintf(RegName,"V Displayed  "); break;
750      case V_SYNC_POS      : sprintf(RegName,"V Sync Pos   "); break;
751      case INTERLACE      : sprintf(RegName,"Interlace    "); break;
752      case MAX_SCAN      : sprintf(RegName,"Max Scan Line"); break;
753      case CURS_START      : sprintf(RegName,"Cusror Start "); break;
754      case CURS_END      : sprintf(RegName,"Cusrsor End  "); break;
755      case START_ADDR_H   : sprintf(RegName,"Start Addr H "); break;
756      case START_ADDR_L   : sprintf(RegName,"Start Addr L "); break;
757      case CURS_H          : sprintf(RegName,"Cursor H     "); break;
758      case CURS_L          : sprintf(RegName,"Cursor L     "); break;
759   }
760
761   if(offset&0x1)
762      debug_console_printf(machine, "6845 write Reg %s Addr=%3d Data=%3d ($%02X) \n",RegName,state->m_VidAddr,data,data);
294   state->m_GCtrl=data;
763295}
764296
765static void execute_beta_vid_fill(running_machine &machine, int ref, int params, const char *param[])
297/* Update video screen, calls either text or graphics update routine as needed */
298SCREEN_UPDATE( dgnbeta )
766299{
767   dgn_beta_state *state = machine.driver_data<dgn_beta_state>();
768   int   x;
769
770   for(x=1;x<899;x++)
771   {
772      plot_box(state->m_bit, x, 1, 1, 698, x & 0x07);
773   }
774   state->m_NoScreen=1;
300   dgn_beta_state *state = screen->machine().driver_data<dgn_beta_state>();
301   mc6845_update(state->m_mc6845, bitmap, cliprect);
302   return 0;
775303}
776304
777static void execute_beta_vid_box(running_machine &machine, int ref, int params, const char *param[])
778{
779   dgn_beta_state *state = machine.driver_data<dgn_beta_state>();
780   int   x,y;
781305
782   if(params>0)   sscanf(param[0],"%d",&state->m_BoxMinX);
783   if(params>1)   sscanf(param[1],"%d",&state->m_BoxMinY);
784   if(params>2)   sscanf(param[2],"%d",&state->m_BoxMaxX);
785   if(params>3)   sscanf(param[3],"%d",&state->m_BoxMaxY);
786   if(params>4)   sscanf(param[4],"%d",&state->m_BoxColour);
787
788   for(x=state->m_BoxMinX;x<state->m_BoxMaxX;x++)
789   {
790      *BITMAP_ADDR16(state->m_bit, state->m_BoxMinY, x) = state->m_BoxColour;
791      *BITMAP_ADDR16(state->m_bit, state->m_BoxMaxY, x) = state->m_BoxColour;
792   }
793
794   for(y=state->m_BoxMinY;y<state->m_BoxMaxY;y++)
795   {
796      *BITMAP_ADDR16(state->m_bit, y, state->m_BoxMinX) = state->m_BoxColour;
797      *BITMAP_ADDR16(state->m_bit, y, state->m_BoxMaxX) = state->m_BoxColour;
798   }
799   debug_console_printf(machine, "ScreenBox()\n");
800}
801
802
803static void execute_beta_vid(running_machine &machine, int ref, int params, const char *param[])
306/* Write handler for colour, pallate ram */
307WRITE8_HANDLER(dgnbeta_colour_ram_w)
804308{
805   dgn_beta_state *state = machine.driver_data<dgn_beta_state>();
806   state->m_NoScreen=!state->m_NoScreen;
309   dgn_beta_state *state = space->machine().driver_data<dgn_beta_state>();
310   state->m_ColourRAM[offset]=data&0x0f;         /* Colour ram 4 bit and write only to CPU */
807311}
808
809static void execute_beta_vid_limits(running_machine &machine, int ref, int params, const char *param[])
810{
811   dgn_beta_state *state = machine.driver_data<dgn_beta_state>();
812   debug_console_printf(machine, "Min X     =$%4X, Max X     =$%4X\n",state->m_MinX,state->m_MaxX);
813   debug_console_printf(machine, "Min Y     =$%4X, Max Y     =$%4X\n",state->m_MinY,state->m_MaxY);
814   debug_console_printf(machine, "MinVidAddr=$%5X, MaxVidAddr=$%5X\n",state->m_MinAddr,state->m_MaxAddr);
815   debug_console_printf(machine, "HsyncMin  =%d, VSyncMin=%d\n",state->m_HSyncMin, state->m_VSyncMin);
816   debug_console_printf(machine, "Interlace =%d\n",state->m_DrawInterlace);
817   debug_console_printf(machine, "DEPos=%d\n",state->m_DEPos);
818   if (IsGfx16)
819      debug_console_printf(machine, "Gfx16\n");
820   else if (IsGfx2)
821      debug_console_printf(machine, "Gfx2\n");
822   else
823      debug_console_printf(machine, "Gfx4/Text\n");
824}
825
826static void execute_beta_vid_clkmax(running_machine &machine, int ref, int params, const char *param[])
827{
828   dgn_beta_state *state = machine.driver_data<dgn_beta_state>();
829   if(params>0)   sscanf(param[0],"%d",&state->m_ClkMax);
830}
src/mess/drivers/dgn_beta.c
r11538r11539
4747#include "imagedev/flopdrv.h"
4848#include "devices/coco_vhd.h"
4949#include "machine/ram.h"
50#include "video/mc6845.h"
5051
52
5153/*
5254 Colour codes are as below acording to os-9 headers, however the presise values
5355 may not be quite correct, also this will need changing as the pallate seems to
r11538r11539
154156   AM_RANGE(0xFC20, 0xFC23)   AM_DEVREADWRITE_MODERN(PIA_0_TAG, pia6821_device, read, write)
155157   AM_RANGE(0xFC24, 0xFC27)   AM_DEVREADWRITE_MODERN(PIA_1_TAG, pia6821_device, read, write)
156158   AM_RANGE(0xFC28, 0xfC7F)   AM_NOP
157   AM_RANGE(0xfc80, 0xfc81)   AM_READWRITE(dgnbeta_6845_r   ,dgnbeta_6845_w)
159   AM_RANGE(0xfc80, 0xfc80)    AM_DEVWRITE("crtc", mc6845_address_w)
160   AM_RANGE(0xfc81, 0xfc81)    AM_DEVREADWRITE("crtc", mc6845_register_r , mc6845_register_w)   
158161   AM_RANGE(0xfc82, 0xfC9F)   AM_NOP
159162   AM_RANGE(0xFCA0, 0xFCA3)   AM_READNOP AM_WRITE(dgnbeta_colour_ram_w)          /* 4x4bit colour ram for graphics modes */
160163   AM_RANGE(0xFCC0, 0xFCC3)   AM_DEVREADWRITE_MODERN(PIA_2_TAG, pia6821_device, read, write)
r11538r11539
347350   MCFG_WD179X_ADD(FDC_TAG, dgnbeta_wd17xx_interface )
348351
349352   MCFG_FLOPPY_4_DRIVES_ADD(dgnbeta_floppy_config)
353   
354   MCFG_MC6845_ADD("crtc", MC6845, XTAL_12_288MHz / 8, dgnbeta_crtc6845_interface)   
350355
351356   /* internal ram */
352357   MCFG_RAM_ADD(RAM_TAG)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team