Previous 15994 Revisions Next

r980 Sunday 16th September, 2007 at 13:09:10 UTC by Wilbert Pol
[PCE] Made some basic changes to eventually allow more than one VDC chip in a driver.
[src/mess/drivers]pce.c
[src/mess/video]vdc.c vdc.h

src/mess/video/vdc.c
r979r980
4949   mame_bitmap   *bmp;
5050}VCE;
5151
52static VDC vdc;
52static VDC vdc[2];
5353static VCE vce;
5454
5555/* Function prototypes */
5656
57void draw_black_line(int line);
58void draw_overscan_line(int line);
59void pce_refresh_line(int bitmap_line, int line);
60void pce_refresh_sprites(int bitmap_line, int line, UINT8 *drawn);
61void vdc_do_dma(void);
57static void vdc_advance_line(int which);
58static void draw_black_line(int line);
59static void draw_overscan_line(int line);
60static void pce_refresh_line(int which, int bitmap_line, int line, int external_input, UINT8 *drawn);
61static void pce_refresh_sprites(int which, int bitmap_line, int line, UINT8 *drawn);
62static void vdc_do_dma(int which);
6263
6364INTERRUPT_GEN( pce_interrupt )
6465{
65   int ret = 0;
66
6766   /* Draw the last scanline */
6867   if ( vce.current_bitmap_line >= 14 && vce.current_bitmap_line < 14 + 242 ) {
6968      /* We are in the active display area */
70      if ( vdc.current_segment == STATE_VDW ) {
71         vdc.y_scroll = ( vdc.current_segment_line == 0 ) ? vdc.vdc_data[BYR].w : ( vdc.y_scroll + 1 );
72         pce_refresh_line( vce.current_bitmap_line, vdc.current_segment_line );
73      } else {
74         draw_overscan_line( vce.current_bitmap_line );
69      /* First fill the line with the overscan color */
70      draw_overscan_line( vce.current_bitmap_line );
71
72      /* Check if we need to draw more just the overscan color */
73      if ( vdc[0].current_segment == STATE_VDW ) {
74         /* 0 - no sprite and background pixels drawn
75            1 - background pixel drawn
76            otherwise is 2 + sprite# */
77         UINT8 drawn[VDC_WPF];
78
79         /* clear our priority/sprite collision detection buffer. */
80         memset(drawn, 0, VDC_WPF);
81
82         vdc[0].y_scroll = ( vdc[0].current_segment_line == 0 ) ? vdc[0].vdc_data[BYR].w : ( vdc[0].y_scroll + 1 );
83
84         /* Draw VDC #0 background layer */
85         pce_refresh_line( 0, vce.current_bitmap_line, vdc[0].current_segment_line, 0, drawn );
86
87         /* Draw VDC #0 sprite layer */
88         if(vdc[0].vdc_data[CR].w & CR_SB) {
89            pce_refresh_sprites(0, vce.current_bitmap_line, vdc[0].current_segment_line, drawn);
90         }
7591      }
7692   } else {
7793      /* We are in one of the blanking areas */
r979r980
8096
8197   /* bump current scanline */
8298   vce.current_bitmap_line = ( vce.current_bitmap_line + 1 ) % VDC_LPF;
83   vdc.curline += 1;
84   vdc.current_segment_line += 1;
85   vdc.raster_count += 1;
99   vdc_advance_line( 0 );
100}
86101
87   if ( vdc.satb_countdown ) {
88      vdc.satb_countdown -= 1;
89      if ( vdc.satb_countdown == 0 ) {
90         if ( vdc.vdc_data[DCR].w & DCR_DSC ) {
91            vdc.status |= VDC_DS;   /* set satb done flag */
102static void vdc_advance_line(int which) {
103   int ret = 0;
104
105   vdc[which].curline += 1;
106   vdc[which].current_segment_line += 1;
107   vdc[which].raster_count += 1;
108
109   if ( vdc[which].satb_countdown ) {
110      vdc[which].satb_countdown -= 1;
111      if ( vdc[which].satb_countdown == 0 ) {
112         if ( vdc[which].vdc_data[DCR].w & DCR_DSC ) {
113            vdc[which].status |= VDC_DS;   /* set satb done flag */
92114            ret = 1;
93115         }
94116      }
95117   }
96118
97119   if ( vce.current_bitmap_line == 0 ) {
98      vdc.current_segment = STATE_VSW;
99      vdc.current_segment_line = 0;
100      vdc.vblank_triggered = 0;
101      vdc.curline = 0;
120      vdc[which].current_segment = STATE_VSW;
121      vdc[which].current_segment_line = 0;
122      vdc[which].vblank_triggered = 0;
123      vdc[which].curline = 0;
102124   }
103125
104   if ( STATE_VSW == vdc.current_segment && vdc.current_segment_line >= ( vdc.vdc_data[VPR].b.l & 0x1F ) ) {
105      vdc.current_segment = STATE_VDS;
106      vdc.current_segment_line = 0;
126   if ( STATE_VSW == vdc[which].current_segment && vdc[which].current_segment_line >= ( vdc[which].vdc_data[VPR].b.l & 0x1F ) ) {
127      vdc[which].current_segment = STATE_VDS;
128      vdc[which].current_segment_line = 0;
107129   }
108130
109   if ( STATE_VDS == vdc.current_segment && vdc.current_segment_line >= vdc.vdc_data[VPR].b.h ) {
110      vdc.current_segment = STATE_VDW;
111      vdc.current_segment_line = 0;
112      vdc.raster_count = 0x40;
131   if ( STATE_VDS == vdc[which].current_segment && vdc[which].current_segment_line >= vdc[which].vdc_data[VPR].b.h ) {
132      vdc[which].current_segment = STATE_VDW;
133      vdc[which].current_segment_line = 0;
134      vdc[which].raster_count = 0x40;
113135   }
114136
115   if ( STATE_VDW == vdc.current_segment && vdc.current_segment_line > ( vdc.vdc_data[VDW].w & 0x01FF ) ) {
116      vdc.current_segment = STATE_VCR;
117      vdc.current_segment_line = 0;
137   if ( STATE_VDW == vdc[which].current_segment && vdc[which].current_segment_line > ( vdc[which].vdc_data[VDW].w & 0x01FF ) ) {
138      vdc[which].current_segment = STATE_VCR;
139      vdc[which].current_segment_line = 0;
118140
119141      /* Generate VBlank interrupt, sprite DMA */
120      vdc.vblank_triggered = 1;
121      if ( vdc.vdc_data[CR].w & CR_VR ) {
122         vdc.status |= VDC_VD;
142      vdc[which].vblank_triggered = 1;
143      if ( vdc[which].vdc_data[CR].w & CR_VR ) {
144         vdc[which].status |= VDC_VD;
123145         ret = 1;
124146      }
125147
126148      /* do VRAM > SATB DMA if the enable bit is set or the DVSSR reg. was written to */
127      if( ( vdc.vdc_data[DCR].w & DCR_DSR ) || vdc.dvssr_write ) {
149      if( ( vdc[which].vdc_data[DCR].w & DCR_DSR ) || vdc[which].dvssr_write ) {
128150         int i;
129151
130         vdc.dvssr_write = 0;
152         vdc[which].dvssr_write = 0;
131153
132154         for( i = 0; i < 256; i++ ) {
133            vdc.sprite_ram[i] = ( vdc.vram[ ( vdc.vdc_data[DVSSR].w << 1 ) + i * 2 + 1 ] << 8 ) | vdc.vram[ ( vdc.vdc_data[DVSSR].w << 1 ) + i * 2 ];
155            vdc[which].sprite_ram[i] = ( vdc[which].vram[ ( vdc[which].vdc_data[DVSSR].w << 1 ) + i * 2 + 1 ] << 8 ) | vdc[which].vram[ ( vdc[which].vdc_data[DVSSR].w << 1 ) + i * 2 ];
134156         }
135157
136158         /* generate interrupt if needed */
137         if ( vdc.vdc_data[DCR].w & DCR_DSC ) {
138            vdc.satb_countdown = 4;
159         if ( vdc[which].vdc_data[DCR].w & DCR_DSC ) {
160            vdc[which].satb_countdown = 4;
139161         }
140162      }
141163   }
142164
143   if ( STATE_VCR == vdc.current_segment ) {
144      if ( vdc.current_segment_line >= 3 && vdc.current_segment_line >= vdc.vdc_data[VCR].b.l ) {
145         vdc.current_segment = STATE_VSW;
146         vdc.current_segment_line = 0;
147         vdc.curline = 0;
165   if ( STATE_VCR == vdc[which].current_segment ) {
166      if ( vdc[which].current_segment_line >= 3 && vdc[which].current_segment_line >= vdc[which].vdc_data[VCR].b.l ) {
167         vdc[which].current_segment = STATE_VSW;
168         vdc[which].current_segment_line = 0;
169         vdc[which].curline = 0;
148170      }
149171   }
150172
151173   /* generate interrupt on line compare if necessary */
152   if ( vdc.raster_count == vdc.vdc_data[RCR].w && vdc.vdc_data[CR].w & CR_RC ) {
153      vdc.status |= VDC_RR;
174   if ( vdc[which].raster_count == vdc[which].vdc_data[RCR].w && vdc[which].vdc_data[CR].w & CR_RC ) {
175      vdc[which].status |= VDC_RR;
154176      ret = 1;
155177   }
156178
157179   /* handle frame events */
158   if(vdc.curline == 261 && ! vdc.vblank_triggered ) {
180   if(vdc[which].curline == 261 && ! vdc[which].vblank_triggered ) {
159181
160      vdc.vblank_triggered = 1;
161      if(vdc.vdc_data[CR].w & CR_VR) {   /* generate IRQ1 if enabled */
162         vdc.status |= VDC_VD;   /* set vblank flag */
182      vdc[which].vblank_triggered = 1;
183      if(vdc[which].vdc_data[CR].w & CR_VR) {   /* generate IRQ1 if enabled */
184         vdc[which].status |= VDC_VD;   /* set vblank flag */
163185         ret = 1;
164186      }
165187
166188      /* do VRAM > SATB DMA if the enable bit is set or the DVSSR reg. was written to */
167      if ( ( vdc.vdc_data[DCR].w & DCR_DSR ) || vdc.dvssr_write ) {
189      if ( ( vdc[which].vdc_data[DCR].w & DCR_DSR ) || vdc[which].dvssr_write ) {
168190         int i;
169191
170         vdc.dvssr_write = 0;
192         vdc[which].dvssr_write = 0;
171193#ifdef MAME_DEBUG
172         assert(((vdc.vdc_data[DVSSR].w<<1) + 512) <= 0x10000);
194         assert(((vdc[which].vdc_data[DVSSR].w<<1) + 512) <= 0x10000);
173195#endif
174196         for( i = 0; i < 256; i++ ) {
175            vdc.sprite_ram[i] = ( vdc.vram[ ( vdc.vdc_data[DVSSR].w << 1 ) + i * 2 + 1 ] << 8 ) | vdc.vram[ ( vdc.vdc_data[DVSSR].w << 1 ) + i * 2 ];
197            vdc[which].sprite_ram[i] = ( vdc[which].vram[ ( vdc[which].vdc_data[DVSSR].w << 1 ) + i * 2 + 1 ] << 8 ) | vdc[which].vram[ ( vdc[which].vdc_data[DVSSR].w << 1 ) + i * 2 ];
176198         }
177199
178200         /* generate interrupt if needed */
179         if(vdc.vdc_data[DCR].w & DCR_DSC) {
180            vdc.satb_countdown = 4;
201         if(vdc[which].vdc_data[DCR].w & DCR_DSC) {
202            vdc[which].satb_countdown = 4;
181203         }
182204      }
183205   }
r979r980
195217   memset(&vce, 0, sizeof(vce));
196218
197219   /* allocate VRAM */
198   vdc.vram = auto_malloc(0x10000);
199   memset(vdc.vram, 0, 0x10000);
220   vdc[0].vram = auto_malloc(0x10000);
221   vdc[1].vram = auto_malloc(0x10000);
222   memset(vdc[0].vram, 0, 0x10000);
223   memset(vdc[1].vram, 0, 0x10000);
200224
201225   /* create display bitmap */
202226   vce.bmp = auto_bitmap_alloc(machine->screen[0].width, machine->screen[0].height, machine->screen[0].format);
203227
204   vdc.inc = 1;
228   vdc[0].inc = 1;
229   vdc[1].inc = 1;
205230}
206231
207232
r979r980
212237   return 0;
213238}
214239
215void draw_black_line(int line)
240static void draw_black_line(int line)
216241{
217242   int i;
218243
r979r980
223248      line_buffer[i] = get_black_pen( Machine );
224249}
225250
226void draw_overscan_line(int line)
251static void draw_overscan_line(int line)
227252{
228253   int i;
229254
r979r980
238263
239264}
240265
241void vram_write(offs_t offset, UINT8 data)
266static void vram_write(int which, offs_t offset, UINT8 data)
242267{
243268   if(offset & 0x10000)
244269   {
245      logerror("Write to VRAM offset %05X\n", offset);
270      logerror("VDC #%d: Write to VRAM offset %05X\n", which, offset);
246271      return;
247272   }
248273   else
249274   {
250      vdc.vram[offset] = data;
275      vdc[which].vram[offset] = data;
251276   }
252277}
253278
254UINT8 vram_read(offs_t offset)
279static UINT8 vram_read(int which, offs_t offset)
255280{
256281   UINT8 temp;
257282
258283   if(offset & 0x10000)
259284   {
260      temp = vdc.vram[offset & 0xFFFF];
285      temp = vdc[which].vram[offset & 0xFFFF];
261286   }
262287   else
263288   {
264      temp = vdc.vram[offset];
289      temp = vdc[which].vram[offset];
265290   }
266291
267292   return temp;
268293}
269294
270295
271WRITE8_HANDLER ( vdc_w )
296static void vdc_w( int which, offs_t offset, UINT8 data )
272297{
273298   switch(offset&3)
274299   {
275300      case 0x00:   /* VDC register select */
276         vdc.vdc_register = (data & 0x1F);
301         vdc[which].vdc_register = (data & 0x1F);
277302         break;
278303
279304      case 0x02:   /* VDC data (LSB) */
280         vdc.vdc_data[vdc.vdc_register].b.l = data;
281         switch(vdc.vdc_register)
305         vdc[which].vdc_data[vdc[which].vdc_register].b.l = data;
306         switch(vdc[which].vdc_register)
282307         {
283308            case VxR:   /* LSB of data to write to VRAM */
284               vdc.vdc_latch = data;
309               vdc[which].vdc_latch = data;
285310               break;
286311
287312             case BYR:
288               vdc.y_scroll=vdc.vdc_data[BYR].w;
313               vdc[which].y_scroll=vdc[which].vdc_data[BYR].w;
289314               break;
290315
291316            case HDR:
292               vdc.physical_width = ((data & 0x003F) + 1) << 3;
317               vdc[which].physical_width = ((data & 0x003F) + 1) << 3;
293318               break;
294319
295320            case VDW:
296               vdc.physical_height &= 0xFF00;
297               vdc.physical_height |= (data & 0xFF);
298               vdc.physical_height &= 0x01FF;
321               vdc[which].physical_height &= 0xFF00;
322               vdc[which].physical_height |= (data & 0xFF);
323               vdc[which].physical_height &= 0x01FF;
299324               break;
300325
301326            case LENR:
r979r980
311336         break;
312337
313338      case 0x03:   /* VDC data (MSB) */
314         vdc.vdc_data[vdc.vdc_register].b.h = data;
315         switch(vdc.vdc_register)
339         vdc[which].vdc_data[vdc[which].vdc_register].b.h = data;
340         switch(vdc[which].vdc_register)
316341         {
317342            case VxR:   /* MSB of data to write to VRAM */
318               vram_write(vdc.vdc_data[MAWR].w*2+0, vdc.vdc_latch);
319               vram_write(vdc.vdc_data[MAWR].w*2+1, data);
320               vdc.vdc_data[MAWR].w += vdc.inc;
343               vram_write(which, vdc[which].vdc_data[MAWR].w*2+0, vdc[which].vdc_latch);
344               vram_write(which, vdc[which].vdc_data[MAWR].w*2+1, data);
345               vdc[which].vdc_data[MAWR].w += vdc[which].inc;
321346               break;
322347
323348            case CR:
324349               {
325                  static unsigned char inctab[] = {1, 32, 64, 128};
326                  vdc.inc = inctab[(data >> 3) & 3];
350                  static const unsigned char inctab[] = {1, 32, 64, 128};
351                  vdc[which].inc = inctab[(data >> 3) & 3];
327352               }
328353               break;
329354
330355            case VDW:
331               vdc.physical_height &= 0x00FF;
332               vdc.physical_height |= (data << 8);
333               vdc.physical_height &= 0x01FF;
356               vdc[which].physical_height &= 0x00FF;
357               vdc[which].physical_height |= (data << 8);
358               vdc[which].physical_height &= 0x01FF;
334359               break;
335360
336361            case DVSSR:
337362               /* Force VRAM <> SATB DMA for this frame */
338               vdc.dvssr_write = 1;
363               vdc[which].dvssr_write = 1;
339364               break;
340365
341366            case BYR:
342               vdc.y_scroll=vdc.vdc_data[BYR].w;
367               vdc[which].y_scroll=vdc[which].vdc_data[BYR].w;
343368               break;
344369
345370            case LENR:
346               vdc_do_dma();
371               vdc_do_dma( which );
347372               break;
348373            case SOUR:
349374//               logerror("SOUR MSB = %02X\n", data);
r979r980
356381   }
357382}
358383
359
360 READ8_HANDLER ( vdc_r )
384static UINT8 vdc_r( int which, offs_t offset )
361385{
362386   int temp = 0;
363387   switch(offset&3)
364388   {
365389      case 0x00:
366         temp = vdc.status;
367         vdc.status &= ~(VDC_VD | VDC_RR | VDC_CR | VDC_OR | VDC_DS);
390         temp = vdc[which].status;
391         vdc[which].status &= ~(VDC_VD | VDC_RR | VDC_CR | VDC_OR | VDC_DS);
368392         cpunum_set_input_line(0,0,CLEAR_LINE);
369393         break;
370394
371395      case 0x02:
372         temp = vram_read(vdc.vdc_data[MARR].w*2+0);
396         temp = vram_read(which, vdc[which].vdc_data[MARR].w*2+0);
373397         break;
374398
375399      case 0x03:
376         temp = vram_read(vdc.vdc_data[MARR].w*2+1);
377         if ( vdc.vdc_register ==VxR ) {
378            vdc.vdc_data[MARR].w += vdc.inc;
400         temp = vram_read(which, vdc[which].vdc_data[MARR].w*2+1);
401         if ( vdc[which].vdc_register ==VxR ) {
402            vdc[which].vdc_data[MARR].w += vdc[which].inc;
379403         }
380404         break;
381405   }
382406   return (temp);
383407}
384408
409WRITE8_HANDLER( vdc_0_w ) {   vdc_w( 0, offset, data ); }
410WRITE8_HANDLER( vdc_1_w ) {   vdc_w( 1, offset, data ); }
411READ8_HANDLER( vdc_0_r ) {   return vdc_r( 0, offset ); }
412READ8_HANDLER( vdc_1_r ) {   return vdc_r( 1, offset ); }
385413
386414PALETTE_INIT( vce ) {
387415   int i;
r979r980
447475}
448476
449477
450void pce_refresh_line(int bitmap_line, int line)
478static void pce_refresh_line(int which, int bitmap_line, int line, int external_input, UINT8 *drawn)
451479{
452480    static int width_table[4] = {5, 6, 7, 7};
453481
454    int scroll_y = ( vdc.y_scroll & 0x01FF);
455    int scroll_x = (vdc.vdc_data[BXR].w & 0x03FF);
482    int scroll_y = ( vdc[which].y_scroll & 0x01FF);
483    int scroll_x = (vdc[which].vdc_data[BXR].w & 0x03FF);
456484    int nt_index;
457485
458486    /* is virtual map 32 or 64 characters tall ? (256 or 512 pixels) */
459    int v_line = (scroll_y) & (vdc.vdc_data[MWR].w & 0x0040 ? 0x1FF : 0x0FF);
487    int v_line = (scroll_y) & (vdc[which].vdc_data[MWR].w & 0x0040 ? 0x1FF : 0x0FF);
460488
461489    /* row within character */
462490    int v_row = (v_line & 7);
r979r980
465493    int nt_row = (v_line >> 3);
466494
467495    /* virtual X size (# bits to shift) */
468    int v_width =        width_table[(vdc.vdc_data[MWR].w >> 4) & 3];
496    int v_width =        width_table[(vdc[which].vdc_data[MWR].w >> 4) & 3];
469497
470498    /* our line buffer */
471499    UINT16 *line_buffer = BITMAP_ADDR16( vce.bmp, bitmap_line, 86 );
472500
473501    /* pointer to the name table (Background Attribute Table) in VRAM */
474    UINT8 *bat = &(vdc.vram[nt_row << (v_width+1)]);
502    UINT8 *bat = &(vdc[which].vram[nt_row << (v_width+1)]);
475503
476   /* 0 - no sprite and background pixels drawn
477      1 - background pixel drawn
478      otherwise is 2 + sprite# */
479   UINT8 drawn[VDC_WPF];
480
481504   /* Are we in greyscale mode or in color mode? */
482505   int color_base = vce.vce_control & 0x80 ? 512 : 0;
483506
r979r980
487510    int cell_palette;
488511    int x, c, i;
489512
490   /* clear our priority/sprite collision detection buffer. */
491   memset(drawn, 0, VDC_WPF);
492
493513    /* character blanking bit */
494    if(!(vdc.vdc_data[CR].w & CR_BB))
514    if(!(vdc[which].vdc_data[CR].w & CR_BB))
495515    {
496516     draw_black_line(bitmap_line);
497517    }
r979r980
500520      int   pixel = 0;
501521      int phys_x = - ( scroll_x & 0x07 );
502522
503      /* First fill line with overscan colour */
504      for ( i = -86; i < VDC_WPF - 86; i++ )
505         line_buffer[i] = Machine->pens[color_base + vce.vce_data[0x100].w];
506
507      for(i=0;i<(vdc.physical_width >> 3) + 1;i++)
523      for(i=0;i<(vdc[which].physical_width >> 3) + 1;i++)
508524      {
509525         nt_index = (i + (scroll_x >> 3)) & ((2 << (v_width-1))-1);
510526         nt_index *= 2;
r979r980
520536         /* byte-offset within the VRAM space                     */
521537         cell_pattern_index = ( ( ( bat[nt_index + 1] << 8 ) | bat[nt_index] ) & 0x0FFF) << 5;
522538
523         b0 = vram_read((cell_pattern_index) + (v_row << 1) + 0x00);
524         b1 = vram_read((cell_pattern_index) + (v_row << 1) + 0x01);
525         b2 = vram_read((cell_pattern_index) + (v_row << 1) + 0x10);
526         b3 = vram_read((cell_pattern_index) + (v_row << 1) + 0x11);
539         b0 = vram_read(which, (cell_pattern_index) + (v_row << 1) + 0x00);
540         b1 = vram_read(which, (cell_pattern_index) + (v_row << 1) + 0x01);
541         b2 = vram_read(which, (cell_pattern_index) + (v_row << 1) + 0x10);
542         b3 = vram_read(which, (cell_pattern_index) + (v_row << 1) + 0x11);
527543
528544         for(x=0;x<8;x++)
529545         {
r979r980
537553            if ( ! ( c & 0x0F ) )
538554               c &= 0x0F;
539555
540            if ( phys_x >= 0 && phys_x < vdc.physical_width ) {
556            if ( phys_x >= 0 && phys_x < vdc[which].physical_width ) {
541557               drawn[ phys_x ] = c ? 1 : 0;
542               line_buffer[ pixel ] = Machine->pens[color_base + vce.vce_data[c].w];
558               if ( c || ! external_input )
559                  line_buffer[ pixel ] = Machine->pens[color_base + vce.vce_data[c].w];
543560               pixel++;
544               if ( vdc.physical_width != 512 ) {
545                  if ( pixel < ( ( ( phys_x + 1 ) * 512 ) / vdc.physical_width ) ) {
546                     line_buffer[ pixel ] = Machine->pens[color_base + vce.vce_data[c].w];
561               if ( vdc[which].physical_width != 512 ) {
562                  if ( pixel < ( ( ( phys_x + 1 ) * 512 ) / vdc[which].physical_width ) ) {
563                     if ( c || ! external_input )
564                        line_buffer[ pixel ] = Machine->pens[color_base + vce.vce_data[c].w];
547565                     pixel++;
548566                  }
549567               }
r979r980
552570         }
553571      }
554572   }
555   /* Sprite rendering is independant of BG drawing! */
556   if(vdc.vdc_data[CR].w & CR_SB)
557   {
558      pce_refresh_sprites(bitmap_line, line, drawn);
559   }
560573}
561574
562575
563576
564static void conv_obj(int i, int l, int hf, int vf, char *buf)
577static void conv_obj(int which, int i, int l, int hf, int vf, char *buf)
565578{
566579   int b0, b1, b2, b3, i0, i1, i2, i3, x;
567580   int xi;
r979r980
572585
573586   tmp = l + ( i << 5);
574587
575   b0 = vram_read((tmp + 0x00)<<1);
576   b0 |= vram_read(((tmp + 0x00)<<1)+1)<<8;
577   b1 = vram_read((tmp + 0x10)<<1);
578   b1 |= vram_read(((tmp + 0x10)<<1)+1)<<8;
579   b2 = vram_read((tmp + 0x20)<<1);
580   b2 |= vram_read(((tmp + 0x20)<<1)+1)<<8;
581   b3 = vram_read((tmp + 0x30)<<1);
582   b3 |= vram_read(((tmp + 0x30)<<1)+1)<<8;
588   b0 = vram_read(which, (tmp + 0x00)<<1);
589   b0 |= vram_read(which, ((tmp + 0x00)<<1)+1)<<8;
590   b1 = vram_read(which, (tmp + 0x10)<<1);
591   b1 |= vram_read(which, ((tmp + 0x10)<<1)+1)<<8;
592   b2 = vram_read(which, (tmp + 0x20)<<1);
593   b2 |= vram_read(which, ((tmp + 0x20)<<1)+1)<<8;
594   b3 = vram_read(which, (tmp + 0x30)<<1);
595   b3 |= vram_read(which, ((tmp + 0x30)<<1)+1)<<8;
583596
584597   for(x=0;x<16;x++)
585598   {
r979r980
592605   }
593606}
594607
595void pce_refresh_sprites(int bitmap_line, int line, UINT8 *drawn)
608static void pce_refresh_sprites(int which, int bitmap_line, int line, UINT8 *drawn)
596609{
597610    int i;
598611   UINT8 sprites_drawn=0;
r979r980
606619   {
607620      static const int cgy_table[] = {16, 32, 64, 64};
608621
609      int obj_y = (vdc.sprite_ram[(i<<2)+0] & 0x03FF) - 64;
610      int obj_x = (vdc.sprite_ram[(i<<2)+1] & 0x03FF) - 32;
611      int obj_i = (vdc.sprite_ram[(i<<2)+2] & 0x07FE);
612      int obj_a = (vdc.sprite_ram[(i<<2)+3]);
622      int obj_y = (vdc[which].sprite_ram[(i<<2)+0] & 0x03FF) - 64;
623      int obj_x = (vdc[which].sprite_ram[(i<<2)+1] & 0x03FF) - 32;
624      int obj_i = (vdc[which].sprite_ram[(i<<2)+2] & 0x07FE);
625      int obj_a = (vdc[which].sprite_ram[(i<<2)+3]);
613626      int cgx   = (obj_a >> 8) & 1;   /* sprite width */
614627      int cgy   = (obj_a >> 12) & 3;  /* sprite height */
615628      int hf    = (obj_a >> 11) & 1;  /* horizontal flip */
r979r980
622635      char buf[16];
623636
624637      if ((obj_y == -64) || (obj_y > line)) continue;
625      if ((obj_x == -32) || (obj_x >= vdc.physical_width)) continue;
638      if ((obj_x == -32) || (obj_x >= vdc[which].physical_width)) continue;
626639
627640      /* no need to draw an object that's ABOVE where we are. */
628641      if((obj_y + obj_h)<line) continue;
r979r980
642655      sprites_drawn++;
643656      if(sprites_drawn > 16)
644657      {
645         vdc.status |= VDC_OR;
646         if(vdc.vdc_data[CR].w&CR_OV)
658         vdc[which].status |= VDC_OR;
659         if(vdc[which].vdc_data[CR].w&CR_OV)
647660            cpunum_set_input_line(0, 0, ASSERT_LINE);
648661         continue;  /* Should cause an interrupt */
649662      }
r979r980
656669         if(cgx == 0)
657670         {
658671            int x;
659            int pixel_x = ( ( obj_x * 512 ) / vdc.physical_width );
672            int pixel_x = ( ( obj_x * 512 ) / vdc[which].physical_width );
660673
661            conv_obj(obj_i + (cgypos << 2), obj_l, hf, vf, buf);
674            conv_obj(which, obj_i + (cgypos << 2), obj_l, hf, vf, buf);
662675
663676            for(x=0;x<16;x++)
664677            {
665               if(((obj_x + x)<(vdc.physical_width))&&((obj_x + x)>=0))
678               if(((obj_x + x)<(vdc[which].physical_width))&&((obj_x + x)>=0))
666679               {
667680                  if ( buf[x] ) {
668681                     if( drawn[obj_x+x] < 2 ) {
669682                        if(priority || drawn[obj_x+x] == 0 ) {
670683                           line_buffer[pixel_x] = Machine->pens[color_base + vce.vce_data[0x100 + (palette << 4) + buf[x]].w];
671                           if ( vdc.physical_width != 512 ) {
672                              if ( pixel_x + 1 < ( ( ( obj_x + x + 1 ) * 512 ) / vdc.physical_width ) ) {
684                           if ( vdc[which].physical_width != 512 ) {
685                              if ( pixel_x + 1 < ( ( ( obj_x + x + 1 ) * 512 ) / vdc[which].physical_width ) ) {
673686                                 line_buffer[pixel_x + 1] = Machine->pens[color_base + vce.vce_data[0x100 + (palette << 4) + buf[x]].w];
674687                              }
675688                           }
r979r980
679692                     /* Check for sprite #0 collision */
680693                     else if (drawn[obj_x+x]==2)
681694                     {
682                        if(vdc.vdc_data[CR].w&CR_CC)
695                        if(vdc[which].vdc_data[CR].w&CR_CC)
683696                           cpunum_set_input_line(0, 0, ASSERT_LINE);
684                        vdc.status|=VDC_CR;
697                        vdc[which].status|=VDC_CR;
685698                     }
686699                  }
687700               }
688701               pixel_x += 1;
689               if ( vdc.physical_width != 512 ) {
690                  if ( pixel_x < ( ( ( obj_x + x + 1 ) * 512 ) / vdc.physical_width ) ) {
702               if ( vdc[which].physical_width != 512 ) {
703                  if ( pixel_x < ( ( ( obj_x + x + 1 ) * 512 ) / vdc[which].physical_width ) ) {
691704                     pixel_x += 1;
692705                  }
693706               }
r979r980
696709         else
697710         {
698711            int x;
699            int pixel_x = ( ( obj_x * 512 ) / vdc.physical_width );
712            int pixel_x = ( ( obj_x * 512 ) / vdc[which].physical_width );
700713
701            conv_obj(obj_i + (cgypos << 2) + (hf ? 2 : 0), obj_l, hf, vf, buf);
714            conv_obj(which, obj_i + (cgypos << 2) + (hf ? 2 : 0), obj_l, hf, vf, buf);
702715
703716            for(x=0;x<16;x++)
704717            {
705               if(((obj_x + x)<(vdc.physical_width))&&((obj_x + x)>=0))
718               if(((obj_x + x)<(vdc[which].physical_width))&&((obj_x + x)>=0))
706719               {
707720                  if ( buf[x] ) {
708721                     if( drawn[obj_x+x] < 2 ) {
709722                        if ( priority || drawn[obj_x+x] == 0 ) {
710723                           line_buffer[pixel_x] = Machine->pens[color_base + vce.vce_data[0x100 + (palette << 4) + buf[x]].w];
711                           if ( vdc.physical_width != 512 ) {
712                              if ( pixel_x + 1 < ( ( ( obj_x + x + 1 ) * 512 ) / vdc.physical_width ) ) {
724                           if ( vdc[which].physical_width != 512 ) {
725                              if ( pixel_x + 1 < ( ( ( obj_x + x + 1 ) * 512 ) / vdc[which].physical_width ) ) {
713726                                 line_buffer[pixel_x + 1] = Machine->pens[color_base + vce.vce_data[0x100 + (palette << 4) + buf[x]].w];
714727                              }
715728                           }
r979r980
718731                     }
719732                     /* Check for sprite #0 collision */
720733                     else if ( drawn[obj_x+x] == 2 ) {
721                        if(vdc.vdc_data[CR].w&CR_CC)
734                        if(vdc[which].vdc_data[CR].w&CR_CC)
722735                           cpunum_set_input_line(0, 0, ASSERT_LINE);
723                        vdc.status|=VDC_CR;
736                        vdc[which].status|=VDC_CR;
724737                     }
725738                  }
726739               }
727740               pixel_x += 1;
728               if ( vdc.physical_width != 512 ) {
729                  if ( pixel_x < ( ( ( obj_x + x + 1 ) * 512 ) / vdc.physical_width ) ) {
741               if ( vdc[which].physical_width != 512 ) {
742                  if ( pixel_x < ( ( ( obj_x + x + 1 ) * 512 ) / vdc[which].physical_width ) ) {
730743                     pixel_x += 1;
731744                  }
732745               }
r979r980
737750            */
738751            sprites_drawn++;
739752            if( sprites_drawn > 16 ) {
740               vdc.status |= VDC_OR;
741               if(vdc.vdc_data[CR].w&CR_OV)
753               vdc[which].status |= VDC_OR;
754               if(vdc[which].vdc_data[CR].w&CR_OV)
742755                  cpunum_set_input_line(0, 0, ASSERT_LINE);
743756            } else {
744               conv_obj(obj_i + (cgypos << 2) + (hf ? 0 : 2), obj_l, hf, vf, buf);
757               conv_obj(which, obj_i + (cgypos << 2) + (hf ? 0 : 2), obj_l, hf, vf, buf);
745758               for(x=0;x<16;x++)
746759               {
747                  if(((obj_x + 0x10 + x)<(vdc.physical_width))&&((obj_x + 0x10 + x)>=0))
760                  if(((obj_x + 0x10 + x)<(vdc[which].physical_width))&&((obj_x + 0x10 + x)>=0))
748761                  {
749762                     if ( buf[x] ) {
750763                        if( drawn[obj_x+0x10+x] < 2 ) {
751764                           if( priority || drawn[obj_x+0x10+x] == 0 ) {
752765                              line_buffer[pixel_x] = Machine->pens[color_base + vce.vce_data[0x100 + (palette << 4) + buf[x]].w];
753                              if ( vdc.physical_width != 512 ) {
754                                 if ( pixel_x + 1 < ( ( ( obj_x + x + 17 ) * 512 ) / vdc.physical_width ) ) {
766                              if ( vdc[which].physical_width != 512 ) {
767                                 if ( pixel_x + 1 < ( ( ( obj_x + x + 17 ) * 512 ) / vdc[which].physical_width ) ) {
755768                                    line_buffer[pixel_x + 1] = Machine->pens[color_base + vce.vce_data[0x100 + (palette << 4) + buf[x]].w];
756769                                 }
757770                              }                                   
r979r980
760773                        }
761774                        /* Check for sprite #0 collision */
762775                        else if ( drawn[obj_x+0x10+x]==2 ) {
763                           if(vdc.vdc_data[CR].w&CR_CC)
776                           if(vdc[which].vdc_data[CR].w&CR_CC)
764777                              cpunum_set_input_line(0, 0, ASSERT_LINE);
765                           vdc.status|=VDC_CR;
778                           vdc[which].status|=VDC_CR;
766779                        }
767780                     }
768781                  }
769782                  pixel_x += 1;
770                  if ( vdc.physical_width != 512 ) {
771                     if ( pixel_x < ( ( ( obj_x + x + 17 ) * 512 ) / vdc.physical_width ) ) {
783                  if ( vdc[which].physical_width != 512 ) {
784                     if ( pixel_x < ( ( ( obj_x + x + 17 ) * 512 ) / vdc[which].physical_width ) ) {
772785                        pixel_x += 1;
773786                     }
774787                  }
r979r980
779792   }
780793}
781794
782void vdc_do_dma(void)
795static void vdc_do_dma(int which)
783796{
784   int src = vdc.vdc_data[SOUR].w;
785   int dst = vdc.vdc_data[DESR].w;
786   int len = vdc.vdc_data[LENR].w;
797   int src = vdc[which].vdc_data[SOUR].w;
798   int dst = vdc[which].vdc_data[DESR].w;
799   int len = vdc[which].vdc_data[LENR].w;
787800   
788   int did = (vdc.vdc_data[DCR].w >> 3) & 1;
789   int sid = (vdc.vdc_data[DCR].w >> 2) & 1;
790   int dvc = (vdc.vdc_data[DCR].w >> 1) & 1;
801   int did = (vdc[which].vdc_data[DCR].w >> 3) & 1;
802   int sid = (vdc[which].vdc_data[DCR].w >> 2) & 1;
803   int dvc = (vdc[which].vdc_data[DCR].w >> 1) & 1;
791804   
792805   do {
793806      UINT8 l, h;
794807
795      l = vram_read(src<<1);
796      h = vram_read((src<<1) + 1);
808      l = vram_read(which, src<<1);
809      h = vram_read(which, (src<<1) + 1);
797810
798      vram_write(dst<<1,l);
799      vram_write(1+(dst<<1),h);
811      vram_write(which, dst<<1,l);
812      vram_write(which, 1+(dst<<1),h);
800813
801814      if(sid) src = (src - 1) & 0xFFFF;
802815      else   src = (src + 1) & 0xFFFF;
r979r980
808821     
809822   } while (len != 0xFFFF);
810823   
811   vdc.status |= VDC_DV;
812   vdc.vdc_data[SOUR].w = src;
813   vdc.vdc_data[DESR].w = dst;
814   vdc.vdc_data[LENR].w = len;
824   vdc[which].status |= VDC_DV;
825   vdc[which].vdc_data[SOUR].w = src;
826   vdc[which].vdc_data[DESR].w = dst;
827   vdc[which].vdc_data[LENR].w = len;
815828   if(dvc)
816829   {
817830      cpunum_set_input_line(0, 0, ASSERT_LINE);
src/mess/video/vdc.h
r979r980
44
55VIDEO_START( pce );
66VIDEO_UPDATE( pce );
7WRITE8_HANDLER ( vdc_w );
8 READ8_HANDLER ( vdc_r );
7WRITE8_HANDLER ( vdc_0_w );
8WRITE8_HANDLER ( vdc_1_w );
9 READ8_HANDLER ( vdc_0_r );
10 READ8_HANDLER ( vdc_1_r );
911PALETTE_INIT( vce );
1012 READ8_HANDLER ( vce_r );
1113WRITE8_HANDLER ( vce_w );
src/mess/drivers/pce.c
r979r980
4545   AM_RANGE( 0x100000, 0x1EDFFF) AM_ROMBANK(3)
4646   AM_RANGE( 0x1EE000, 0x1EFFFF) AM_RAM AM_BASE( &pce_nvram )
4747   AM_RANGE( 0x1F0000, 0x1F1FFF) AM_RAM AM_MIRROR(0x6000) AM_BASE( &pce_user_ram )
48   AM_RANGE( 0x1FE000, 0x1FE3FF) AM_READWRITE( vdc_r, vdc_w )
48   AM_RANGE( 0x1FE000, 0x1FE3FF) AM_READWRITE( vdc_0_r, vdc_0_w )
4949   AM_RANGE( 0x1FE400, 0x1FE7FF) AM_READWRITE( vce_r, vce_w )
5050   AM_RANGE( 0x1FE800, 0x1FEBFF) AM_READWRITE( C6280_r, C6280_0_w )
5151   AM_RANGE( 0x1FEC00, 0x1FEFFF) AM_READWRITE( H6280_timer_r, H6280_timer_w )
r979r980
5555ADDRESS_MAP_END
5656
5757ADDRESS_MAP_START( pce_io , ADDRESS_SPACE_IO, 8)
58   AM_RANGE( 0x00, 0x03) AM_READWRITE( vdc_r, vdc_w )
58   AM_RANGE( 0x00, 0x03) AM_READWRITE( vdc_0_r, vdc_0_w )
5959ADDRESS_MAP_END
6060
6161/* todo: alternate forms of input (multitap, mouse, etc.) */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team