Previous 15994 Revisions Next

r1811 Friday 29th February, 2008 at 17:42:58 UTC by Wilbert Pol
[ODYSSEY2] Redid the video code.
[src/mess/drivers]odyssey2.c
[src/mess/includes]odyssey2.h
[src/mess/machine]odyssey2.c
[src/mess/video]odyssey2.c

src/mess/includes/odyssey2.h
r1810r1811
2222
2323#define VDC_CONTROL_REG_STROBE_XY (0x02)
2424
25#define COLLISION_SPRITE_0        (0x01)
26#define COLLISION_SPRITE_1        (0x02)
27#define COLLISION_SPRITE_2        (0x04)
28#define COLLISION_SPRITE_3        (0x08)
29#define COLLISION_VERTICAL_GRID   (0x10)
30#define COLLISION_HORIZ_GRID_DOTS (0x20)
31#define COLLISION_EXTERNAL_UNUSED (0x40)
32#define COLLISION_CHARACTERS      (0x80)
25#define I824X_START_ACTIVE_SCAN         6
26#define I824X_END_ACTIVE_SCAN         (6 + 160)
27#define I824X_START_Y               1
28#define I824X_SCREEN_HEIGHT            243
29#define I824X_LINE_CLOCKS            228
3330
34#define COLLISION_SPRITE_0_IND        (1)
35#define COLLISION_SPRITE_1_IND        (2)
36#define COLLISION_SPRITE_2_IND        (3)
37#define COLLISION_SPRITE_3_IND        (4)
38#define COLLISION_VERTICAL_GRID_IND   (5)
39#define COLLISION_HORIZ_GRID_DOTS_IND (6)
40#define COLLISION_EXTERNAL_UNUSED_IND (7)
41#define COLLISION_CHARACTERS_IND      (8)
42
43
4431/*----------- defined in video/odyssey2.c -----------*/
4532
4633extern int odyssey2_vh_hpos;
r1810r1811
5138VIDEO_UPDATE( odyssey2 );
5239PALETTE_INIT( odyssey2 );
5340READ8_HANDLER ( odyssey2_t1_r );
54INTERRUPT_GEN( odyssey2_line );
5541READ8_HANDLER ( odyssey2_video_r );
5642WRITE8_HANDLER ( odyssey2_video_w );
5743
r1810r1811
8369READ8_HANDLER( odyssey2_getbus );
8470WRITE8_HANDLER ( odyssey2_putbus );
8571
72READ8_HANDLER ( g7400_bus_r );
73WRITE8_HANDLER ( g7400_bus_w );
74void ef9341_w( int command, int b, UINT8 data );
75UINT8 ef9341_r( int command, int b );
76
8677int odyssey2_cart_verify(const UINT8 *cartdata, size_t size);
8778
8879
src/mess/video/odyssey2.c
r1810r1811
1111#include "cpu/i8039/i8039.h"
1212#include "includes/odyssey2.h"
1313
14
15#define COLLISION_SPRITE_0         0x01
16#define COLLISION_SPRITE_1         0x02
17#define COLLISION_SPRITE_2         0x04
18#define COLLISION_SPRITE_3         0x08
19#define COLLISION_VERTICAL_GRID      0x10
20#define COLLISION_HORIZ_GRID_DOTS   0x20
21#define COLLISION_EXTERNAL_UNUSED   0x40
22#define COLLISION_CHARACTERS      0x80
23
1424/* character sprite colors
1525   dark grey, red, green, orange, blue, violet, light grey, white
1626   dark back / grid colors
r1810r1811
150160    } s;
151161} o2_vdc= { { 0 } };
152162
153static UINT8 collision[8];    /* only 7 used but easier to index */
154static int line;
155static attotime line_time;
156static UINT32 o2_snd_shift[2];
157static UINT8 x_beam_pos;
158static UINT8 y_beam_pos;
163static UINT32      o2_snd_shift[2];
164static UINT8      x_beam_pos;
165static UINT8      y_beam_pos;
166static UINT8      control_status;
167static UINT8      collision_status;
168static int         iff;
169static emu_timer   *i824x_line_timer;
170static emu_timer   *i824x_hblank_timer;
171static bitmap_t      *tmp_bitmap;
172static int         start_vpos;
173static int         start_vblank;
159174
160/***************************************************************************
161175
162  Start the video hardware emulation.
163
164***************************************************************************/
165
166VIDEO_START( odyssey2 )
167{
168   o2_snd_shift[0] = machine->sample_rate / 983;
169   o2_snd_shift[1] = machine->sample_rate / 3933;
170
171   odyssey2_vh_hpos = 0;
172   odyssey2_display = (UINT8 *) auto_malloc(8 * 8 * 256);
173   memset(odyssey2_display, 0, 8 * 8 * 256);
174}
175
176INLINE int get_horiz_clock_beam_pos( void )
177{
178    int h;
179    h = attotime_mul(attotime_sub(timer_get_time(), line_time), cpunum_get_clock(0) * 8).seconds;
180
181    return h;
182}
183
184INLINE int get_horiz_clock( void )
185{
186    int h;
187    h = attotime_mul(attotime_sub(timer_get_time(), line_time), cpunum_get_clock(0)).seconds;
188
189    return h;
190}
191
192INLINE int horiz_scan_active( void )
193{
194    int h;
195    h = get_horiz_clock();
196
197    if ( h > 15 )
198        return 1;
199
200    return 0;
201}
202
203INLINE int in_vblank( void )
204{
205    if ((line > 239) && (line < 262))
206        return 1;
207
208    return 0;
209}
210
211176PALETTE_INIT( odyssey2 )
212177{
213178   palette_set_colors_rgb(machine, 0, odyssey2_colors, sizeof(odyssey2_colors) / 3);
214179}
215180
216extern READ8_HANDLER( odyssey2_video_r )
181READ8_HANDLER( odyssey2_video_r )
217182{
218183    UINT8 data = 0;
219    int bit, i;
220184
221185    switch (offset)
222186    {
223187        case 0xa1:
188         data = control_status;
189         iff = 0;
190         cpunum_set_input_line(Machine, 0, 0, CLEAR_LINE);
191         control_status &= ~ 0x08;
192         if ( video_screen_get_hpos( 0 ) < I824X_START_ACTIVE_SCAN || video_screen_get_hpos( 0 ) > I824X_END_ACTIVE_SCAN ) {
193            data |= 1;
194         }
224195
225            if (horiz_scan_active())
226                data |= 1;
227
228            if (in_vblank())
229                data |= 8;
230
231196            break;
232197
233198        case 0xa2:
199         data = collision_status;
200         collision_status = 0;
234201
235            bit = 0x01;
236
237            for (i = 0; i < 8; i++)
238            {
239                /* o2_vdc.s.collision at this point has the requested bit(s)
240                 * to test the current collisions against.  TODO: Sometimes
241                 * $A2 has more than one bit set.  What are the correct semantics
242                 * of that when reading back?  For now having an entire byte
243                 * for each graphics object that can collide is working.
244                 */
245
246                if (bit & o2_vdc.s.collision)
247                    data |= (collision[i] & ~bit);
248
249                bit <<= 1;
250            }
251
252202            break;
253203
254204        case 0xa4:
255205
256206            if ((o2_vdc.s.control & VDC_CONTROL_REG_STROBE_XY))
257                y_beam_pos = line;
207                y_beam_pos = video_screen_get_vpos( 0 ) - start_vpos;
258208
259209            data = y_beam_pos;
260210
r1810r1811
263213
264214        case 0xa5:
265215
266            if ((o2_vdc.s.control & VDC_CONTROL_REG_STROBE_XY))
267                x_beam_pos = get_horiz_clock_beam_pos();
216            if ((o2_vdc.s.control & VDC_CONTROL_REG_STROBE_XY)) {
217                x_beam_pos = video_screen_get_hpos( 0 );
218            if ( x_beam_pos < I824X_START_ACTIVE_SCAN ) {
219               x_beam_pos = x_beam_pos - I824X_START_ACTIVE_SCAN + I824X_LINE_CLOCKS;
220            } else {
221               x_beam_pos = x_beam_pos - I824X_START_ACTIVE_SCAN;
222            }
223         }
268224
269225            data = x_beam_pos;
270226
r1810r1811
277233    return data;
278234}
279235
280extern WRITE8_HANDLER( odyssey2_video_w )
236WRITE8_HANDLER( odyssey2_video_w )
281237{
282238   /* Update the sound */
283239   if( offset >= 0xa7 && offset <= 0xaa )
r1810r1811
289245             && !(data & VDC_CONTROL_REG_STROBE_XY))
290246        {
291247            /* Toggling strobe bit, tuck away values */
292            x_beam_pos = get_horiz_clock_beam_pos();
293            y_beam_pos = line;
248            x_beam_pos = video_screen_get_hpos( 0 );
249         if ( x_beam_pos < I824X_START_ACTIVE_SCAN ) {
250            x_beam_pos = x_beam_pos - I824X_START_ACTIVE_SCAN + 228;
251         } else {
252            x_beam_pos = x_beam_pos - I824X_START_ACTIVE_SCAN;
253         }
294254
255            y_beam_pos = video_screen_get_vpos( 0 ) - start_vpos;
256
295257            /* This is wrong but more games work with it, TODO: Figure
296258             * out correct change.  Maybe update the screen here??
297259             * It seems what happens is 0x0 is written to $A0 just before
r1810r1811
305267    o2_vdc.reg[offset] = data;
306268}
307269
308extern READ8_HANDLER( odyssey2_t1_r )
270READ8_HANDLER( odyssey2_t1_r )
309271{
310    static int t = FALSE;
311
312    t = !t;
313    return t;
272   if ( video_screen_get_vpos( 0 ) > start_vpos && video_screen_get_vpos( 0 ) < start_vblank ) {
273      if ( video_screen_get_hpos( 0 ) >= I824X_START_ACTIVE_SCAN && video_screen_get_hpos( 0 ) < I824X_END_ACTIVE_SCAN ) {
274         return 1;
275      }
276   }
277   return 0;
314278}
315279
316INTERRUPT_GEN( odyssey2_line )
317{
318    line_time = timer_get_time();
319    line = (line + 1) % 262;
280static TIMER_CALLBACK( i824x_scanline_callback ) {
281   UINT8   collision_map[160];
282   int      vpos = video_screen_get_vpos( 0 );
320283
321    switch (line)
322    {
323        case 252:
324            cpunum_set_input_line(machine, 0, 0, ASSERT_LINE); /* vsync?? */
325            break;
326        case 253:
327            cpunum_set_input_line(machine, 0, 0, CLEAR_LINE); /* vsync?? */
328            break;
329    }
330}
284   if ( vpos < start_vpos )
285      return;
331286
332INLINE void odyssey2_draw_box(UINT8 bg[][320], int x, int y, int width, int height, UINT8 collision_id)
333{
334    int x1,y1;
335    for (y1 = 0; y1 < height; y1++)
336   {
337      for (x1 = 0; x1 < width; x1++)
338         bg[y+y1][x+x1] |= collision_id;
339    }
340}
287   if ( vpos == start_vpos ) {
288      control_status &= ~0x08;
289   }
341290
342INLINE void odyssey2_draw(bitmap_t *bitmap, UINT8 bg[][320], UINT8 code, int x, int y, int scale_x, int scale_y, UINT8 collision_id, UINT32 col)
343{
344    int m,x1,y1;
345    for (m=0x80; m>0; m>>=1, x+=scale_x)
346   {
347      if (code & m)
348      {
349         for (y1=0; y1<scale_y; y1++)
350         {
351            for (x1 = 0; x1 < scale_x; x1++)
352            {
353               bg[y+y1][x+x1] |= collision_id;
354               *BITMAP_ADDR16(bitmap, y+y1, x+x1) = col;
291   if ( vpos < start_vblank ) {
292      rectangle rect;
293      int   sprite_width[4] = { 8, 8, 8, 8 };
294      int i;
295
296      control_status &= ~ 0x01;
297
298      /* Draw a line */
299      rect.min_y = rect.max_y = vpos;
300      rect.min_x = I824X_START_ACTIVE_SCAN;
301      rect.max_x = I824X_END_ACTIVE_SCAN - 1;
302      fillbitmap( tmp_bitmap, machine->pens[(o2_vdc.s.color >> 3) & 0x7], &rect );
303
304      /* Clear collision map */
305      memset( collision_map, 0, sizeof( collision_map ) );
306
307      /* Display grid if enabled */
308      if ( o2_vdc.s.control & 0x08 ) {
309         UINT16   color = machine->pens[ ( o2_vdc.s.color & 7 ) | ( ( o2_vdc.s.color >> 3 ) & 0x08 ) ];
310         int      x_grid_offset = 8;
311         int    y_grid_offset = 24;
312         int      width = 16;
313         int      height = 24;
314         int      w = ( o2_vdc.s.control & 0x80 ) ? width : 2;
315         int      j, k, y;
316
317         /* Draw horizontal part of grid */
318         for ( j = 1, y = 0; y < 9; y++, j <<= 1 ) {
319            if ( y_grid_offset + y * height <= ( vpos - start_vpos ) && ( vpos - start_vpos ) < y_grid_offset + y * height + 3 ) {
320               for ( i = 0; i < 9; i++ ) {
321                  if ( ( o2_vdc.s.hgrid[0][i] & j ) || ( o2_vdc.s.hgrid[1][i] & ( j >> 8 ) ) ) {
322                     for ( k = 0; k < width + 2; k++ ) {
323                        int px = x_grid_offset + i * width + k;
324                        collision_map[ px ] |= COLLISION_HORIZ_GRID_DOTS;
325                        *BITMAP_ADDR16( tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + px ) = color;
326                     }
327                  }
328               }
355329            }
356330         }
357      }
358    }
359}
360331
361// different bit ordering, maybe I should change rom
362INLINE void odyssey2_draw_sprite(bitmap_t *bitmap, UINT8 bg[][320], UINT8 code, int x, int y, int scale_x, int scale_y, UINT8 collision_id, UINT32 col)
363{
364    int m,x1,y1;
332         /* Draw vertical part of grid */
333         for( j = 1, y = 0; y < 8; y++, j <<= 1 ) {
334            if ( y_grid_offset + y * height <= ( vpos - start_vpos ) && ( vpos - start_vpos ) < y_grid_offset + ( y + 1 ) * height ) {
335               for ( i = 0; i < 10; i++ ) {
336                  if ( o2_vdc.s.vgrid[i] & j ) {
337                     for ( k = 0; k < w; k++ ) {
338                        int px = x_grid_offset + i * width + k;
365339
366    for (m=1; m<=0x80; m<<=1, x+=scale_x)
367   {
368      if (code & m)
369      {
370         for (y1=0; y1<scale_y; y1++)
371         {
372            for (x1 = 0; x1 < scale_x; x1++)
373            {
374               bg[y+y1][x+x1] |= collision_id;
375               *BITMAP_ADDR16(bitmap, y+y1, x+x1) = col;
340                        /* Check if we collide with an already drawn source object */
341                        if ( collision_map[ px ] & o2_vdc.s.collision ) {
342                           collision_status |= COLLISION_VERTICAL_GRID;
343                        }
344                        /* Check if an already drawn object would collide with us */
345                        if ( COLLISION_VERTICAL_GRID & o2_vdc.s.collision && collision_map[ px ] ) {
346                           collision_status |= collision_map[ px ];
347                        }
348                        collision_map[ px ] |= COLLISION_VERTICAL_GRID;
349                        *BITMAP_ADDR16( tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + px ) = color;
350                     }
351                  }
352               }
376353            }
377354         }
378355      }
379    }
380}
381356
382INLINE void odyssey2_draw_grid( bitmap_t* bitmap, UINT8 bg[][320] )
383{
384    int width  = 16;
385    int height = 24;
386   int i, j, x, y;
387   int color;
388    int w = 2;
389    int x_grid_offset = 8;
390    int y_grid_offset = 24;
357      /* Display objects if enabled */
358      if ( o2_vdc.s.control & 0x20 ) {
359         /* Regular foreground objects */
360         for ( i = 0; i < ARRAY_LENGTH( o2_vdc.s.foreground ); i++ ) {
361            int   y = o2_vdc.s.foreground[i].y;
362            int   height = 8;
391363
392    color  = o2_vdc.s.color & 7;
393    color |= (o2_vdc.s.color >> 3) & 8;
364            if ( y <= ( vpos - start_vpos ) && ( vpos - start_vpos ) < y + height * 2 ) {
365               UINT16   color = machine->pens[ 16 + ( ( o2_vdc.s.foreground[i].color & 0x0E ) >> 1 ) ];
366               int      offset = ( o2_vdc.s.foreground[i].ptr | ( ( o2_vdc.s.foreground[i].color & 0x01 ) << 8 ) ) + ( ( vpos - start_vpos ) >> 1 );
367               UINT8   chr = ((char*)o2_shape)[ offset & 0x1FF ];
368               int      x = o2_vdc.s.foreground[i].x;
369               UINT8   m;
394370
395    for (i=0, x=0; x<9; x++, i++)
396    {
397        for (j=1, y=0; y<9; y++, j<<=1)
398        {
399            if ( ((j<=0x80)&&(o2_vdc.s.hgrid[0][i]&j))
400                    ||((j>0x80)&&(o2_vdc.s.hgrid[1][i]&1)) )
401            {
402                odyssey2_draw_box(bg, x_grid_offset + x * width, y_grid_offset + y * height, width + 2, 3, COLLISION_HORIZ_GRID_DOTS);
403                plot_box(bitmap, x_grid_offset + x * width, y_grid_offset + y * height, width + 2, 3, Machine->pens[color]);
404            }
405        }
406    }
371               for ( m = 0x80; m > 0; m >>= 1, x++ ) {
372                  if ( chr & m ) {
373                     if ( x >= 0 && x < 160 ) {
374                        /* Check if we collide with an already drawn source object */
375                        if ( collision_map[ x ] & o2_vdc.s.collision ) {
376                           collision_status |= COLLISION_CHARACTERS;
377                        }
378                        /* Check if an already drawn object would collide with us */
379                        if ( COLLISION_CHARACTERS & o2_vdc.s.collision && collision_map[ x ] ) {
380                           collision_status |= collision_map[ x ];
381                        }
382                        collision_map[ x ] |= COLLISION_CHARACTERS;
383                        *BITMAP_ADDR16( tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x ) = color;
384                     }
385                  }
386               }
387            }
388         }
407389
408    if (o2_vdc.s.control & 0x80)        /* fill solid to end of next vert line */
409        w=width;
390         /* Quad objects */
391         for ( i = 0; i < ARRAY_LENGTH( o2_vdc.s.quad ); i++ ) {
392            int y = o2_vdc.s.quad[i].single[0].y;
393            int height = 8;
410394
411    for (i=0, x=0; x<10; x++, i++)
412    {
413        for (j=1, y=0; y<8; y++, j<<=1)
414        {
415            if (o2_vdc.s.vgrid[i] & j)
416            {
417                odyssey2_draw_box(bg, x_grid_offset + x * width, y_grid_offset + y * height, w, height, COLLISION_VERTICAL_GRID);
418                plot_box(bitmap, x_grid_offset + x * width, y_grid_offset + y * height, w, height, Machine->pens[color]);
419            }
420        }
421    }
422}
395            if ( y <= ( vpos - start_vpos ) && ( vpos - start_vpos ) < y + height * 2 ) {
396               int   x = o2_vdc.s.quad[i].single[0].x;
397               int j;
423398
424INLINE void odyssey2_draw_char(bitmap_t *bitmap, UINT8 bg[][320], int x, int y, int ptr, int color)
425{
426    int n, i;
427    int offset = ptr | ((color & 1) << 8);
428   UINT32 col = Machine->pens[16 + ( ( color & 0xe ) >> 1 )];
399               for ( j = 0; j < ARRAY_LENGTH( o2_vdc.s.quad[0].single ); j++, x += 8 ) {
400                  UINT16 color = machine->pens[ 16 + ( ( o2_vdc.s.quad[i].single[j].color & 0x0E ) >> 1 ) ];
401                  int   offset = ( o2_vdc.s.quad[i].single[j].ptr | ( ( o2_vdc.s.quad[i].single[j].color & 0x01 ) << 8 ) ) + ( ( vpos - start_vpos ) >> 1 );
402                  UINT8   chr = ((char*)o2_shape)[ offset & 0x1FF ];
403                  UINT8   m;
429404
430    offset=(offset + (y >> 1)) & 0x1ff;
405                  for ( m = 0x80; m > 0; m >>= 1, x++ ) {
406                     if ( chr & m ) {
407                        if ( x >= 0 && x < 160 ) {
408                           /* Check if we collide with an already drawn source object */
409                           if ( collision_map[ x ] & o2_vdc.s.collision ) {
410                              collision_status |= COLLISION_CHARACTERS;
411                           }
412                           /* Check if an already drawn object would collide with us */
413                           if ( COLLISION_CHARACTERS & o2_vdc.s.collision && collision_map[ x ] ) {
414                              collision_status |= collision_map[ x ];
415                           }
416                           collision_map[ x ] |= COLLISION_CHARACTERS;
417                           *BITMAP_ADDR16( tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x ) = color;
418                        }
419                     }
420                  }
421               }
422            }
423         }
431424
432    // don't ask me about the technical background, but also this height thingy is needed
433    // invaders aliens (!) and shoot (-)
434    n = 8 - (ptr & 7) - ((y >> 1) & 7);
425         /* Sprites */
426         for ( i = 0; i < ARRAY_LENGTH( o2_vdc.s.sprites ); i++ ) {
427            int y = o2_vdc.s.sprites[i].y;
428            int height = 8;
429            if ( o2_vdc.s.sprites[i].color & 4 ) {
430               /* Zoomed sprite */
431               sprite_width[i] = 16;
432               if ( y <= ( vpos - start_vpos ) && ( vpos - start_vpos ) < y + height * 4 ) {
433                  UINT16 color = machine->pens[ 16 + ( ( o2_vdc.s.sprites[i].color >> 3 ) & 0x07 ) ];
434                  UINT8   chr = o2_vdc.s.shape[i][ ( ( vpos - start_vpos - y ) >> 2 ) ];
435                  int      x = o2_vdc.s.sprites[i].x;
436                  UINT8   m;
435437
436    if (n < 3)
437        n += 7;
438                  for ( m = 0x01; m > 0; m <<= 1, x += 2 ) {
439                     if ( chr & m ) {
440                        if ( x >= 0 && x < 160 ) {
441                           /* Check if we collide with an already drawn source object */
442                           if ( collision_map[ x ] & o2_vdc.s.collision ) {
443                              collision_status |= ( 1 << i );
444                           }
445                           /* Check if an already drawn object would collide with us */
446                           if ( ( 1 << i ) & o2_vdc.s.collision && collision_map[ x ] ) {
447                              collision_status |= collision_map[ x ];
448                           }
449                           collision_map[ x ] |= ( 1 << i );
450                           *BITMAP_ADDR16( tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x ) = color;
451                        }
452                        if ( x >= -1 && x < 159 ) {
453                           /* Check if we collide with an already drawn source object */
454                           if ( collision_map[ x ] & o2_vdc.s.collision ) {
455                              collision_status |= ( 1 << i );
456                           }
457                           /* Check if an already drawn object would collide with us */
458                           if ( ( 1 << i ) & o2_vdc.s.collision && collision_map[ x ] ) {
459                              collision_status |= collision_map[ x ];
460                           }
461                           collision_map[ x ] |= ( 1 << i );
462                           *BITMAP_ADDR16( tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x + 1 ) = color;
463                        }
464                     }
465                  }
466               }
467            } else {
468               /* Regular sprite */
469               if ( y <= ( vpos - start_vpos ) && ( vpos - start_vpos ) < y + height * 2 ) {
470                  UINT16 color = machine->pens[ 16 + ( ( o2_vdc.s.sprites[i].color >> 3 ) & 0x07 ) ];
471                  UINT8   chr = o2_vdc.s.shape[i][ ( ( vpos - start_vpos - y ) >> 1 ) ];
472                  int      x = o2_vdc.s.sprites[i].x;
473                  UINT8   m;
438474
439    for (i=0; i<n; i++)
440    {
441        if (y + i * 2 >= bitmap->height )
442            break;
475                  for ( m = 0x01; m > 0; m <<= 1, x++ ) {
476                     if ( chr & m ) {
477                        if ( x >= 0 && x < 160 ) {
478                           /* Check if we collide with an already drawn source object */
479                           if ( collision_map[ x ] & o2_vdc.s.collision ) {
480                              collision_status |= ( 1 << i );
481                           }
482                           /* Check if an already drawn object would collide with us */
483                           if ( ( 1 << i ) & o2_vdc.s.collision && collision_map[ x ] ) {
484                              collision_status |= collision_map[ x ];
485                           }
486                           collision_map[ x ] |= ( 1 << i );
487                           *BITMAP_ADDR16( tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x ) = color;
488                        }
489                     }
490                  }
491               }
492            }
493         }
494      }
495   }
443496
444      odyssey2_draw(bitmap, bg, ((char*)o2_shape)[offset], x, y+i*2, 1, 2, COLLISION_CHARACTERS, col);
445        offset=(offset+1) & 0x1ff;
446    }
497   /* Check for start of VBlank */
498   if ( vpos == start_vblank ) {
499      control_status |= 0x08;
500      if ( ! iff ) {
501         cpunum_set_input_line(machine, 0, 0, ASSERT_LINE);
502         iff = 1;
503      }
504   }
447505}
448506
507static TIMER_CALLBACK( i824x_hblank_callback ) {
508   int vpos = video_screen_get_vpos( 0 );
509
510   if ( vpos < start_vpos - 1 )
511      return;
512
513   if ( vpos < start_vblank - 1 ) {
514      control_status |= 0x01;
515   }
516}
517
449518/***************************************************************************
450519
451  Refresh the video screen
520  Start the video hardware emulation.
452521
453522***************************************************************************/
454523
455VIDEO_UPDATE( odyssey2 )
524VIDEO_START( odyssey2 )
456525{
457   int i, j, x, y;
458   UINT8 bg[313][320]= { { 0 } };
526   o2_snd_shift[0] = machine->sample_rate / 983;
527   o2_snd_shift[1] = machine->sample_rate / 3933;
459528
460   assert(bitmap->width<=ARRAY_LENGTH(bg[0]) && bitmap->height<=ARRAY_LENGTH(bg));
529   odyssey2_vh_hpos = 0;
530   odyssey2_display = (UINT8 *) auto_malloc(8 * 8 * 256);
531   memset(odyssey2_display, 0, 8 * 8 * 256);
461532
462   plot_box( bitmap, 0, 0, bitmap->width, bitmap->height, machine->pens[(o2_vdc.s.color >> 3) & 0x7] );
533   start_vpos = I824X_START_Y;
534   start_vblank = I824X_START_Y + I824X_SCREEN_HEIGHT;
535   control_status = 0;
536   iff = 0;
463537
464   if (o2_vdc.s.control & 0x08)        /* show grid */
465        odyssey2_draw_grid(bitmap, bg);
538   tmp_bitmap = auto_bitmap_alloc( machine->screen[0].width, machine->screen[0].height, machine->screen[0].format );
466539
467    if (o2_vdc.s.control & 0x20)        /* show foreground objects */
468   {
469      for (i=0; i<ARRAY_LENGTH(o2_vdc.s.foreground); i++)
470        {
471         odyssey2_draw_char(bitmap, bg,
472            o2_vdc.s.foreground[i].x, o2_vdc.s.foreground[i].y,
473            o2_vdc.s.foreground[i].ptr, o2_vdc.s.foreground[i].color);
474      }
540   i824x_line_timer = timer_alloc( i824x_scanline_callback, NULL );
541   timer_adjust_periodic( i824x_line_timer, video_screen_get_time_until_pos( 0, 1, I824X_START_ACTIVE_SCAN ), 0, video_screen_get_scan_period( 0 ) );
475542
476      for (i=0; i<ARRAY_LENGTH(o2_vdc.s.quad); i++)
477      {
478         x=o2_vdc.s.quad[i].single[0].x;
479         for (j=0; j<ARRAY_LENGTH(o2_vdc.s.quad[0].single); j++, x+=2*8)
480         {
481            odyssey2_draw_char(bitmap, bg,
482               x, y=o2_vdc.s.quad[i].single[0].y,
483               o2_vdc.s.quad[i].single[j].ptr, o2_vdc.s.quad[i].single[j].color);
484         }
485      }
543   i824x_hblank_timer = timer_alloc( i824x_hblank_callback, NULL );
544   timer_adjust_periodic( i824x_hblank_timer, video_screen_get_time_until_pos( 0, 1, I824X_END_ACTIVE_SCAN + 18 ), 0, video_screen_get_scan_period( 0 ) );
545}
486546
487      for (i=0; i<ARRAY_LENGTH(o2_vdc.s.sprites); i++)
488      {
489         UINT32 col = machine->pens[16+((o2_vdc.s.sprites[i].color>>3)&7)];
547/***************************************************************************
490548
491         y=o2_vdc.s.sprites[i].y;
492         x=o2_vdc.s.sprites[i].x;
549  Refresh the video screen
493550
494         for (j=0; j<8; j++)
495         {
496            if (o2_vdc.s.sprites[i].color & 4)
497            {
498               if (y+4*j>=bitmap->height)
499                        break;
500               odyssey2_draw_sprite(bitmap, bg, o2_vdc.s.shape[i][j], x, y+j*4, 2, 4, 1<<i, col);    /* 1 << i is sprite collision index */
501            }
551***************************************************************************/
502552
503            else
504            {
505               if (y+j*2>=bitmap->height)
506                        break;
507               odyssey2_draw_sprite(bitmap, bg, o2_vdc.s.shape[i][j], x, y+j*2, 1, 2, 1<<i, col);    /* 1 << i is sprite collision index */
508            }
509         }
510      }
511   }
553VIDEO_UPDATE( odyssey2 )
554{
555   copybitmap( bitmap, tmp_bitmap, 0, 0, 0, 0, cliprect );
512556
513   memset( collision, 0, sizeof( collision ) );
514
515   for (y=0; y<300; y++)
516   {
517      for (x=0; x<320; x++)
518      {
519         switch (bg[y][x])
520            {
521                case 0: case 1: case 2: case 4: case 8:
522                case 0x10: case 0x20: case 0x80:
523                    /* Only one collidable entity in this spot, no collision to mark */
524                    break;
525
526                default:
527                    {
528                        int bit = 0x01;
529                        for (i = 0; i < 8; i++)
530                        {
531                        if (bit & o2_vdc.s.collision && bit & bg[y][x])
532                                collision[i] |= bg[y][x] & ~bit;
533
534                            bit <<= 1;
535                        }
536                    break;
537         }
538      }
539   }
540   }
541
542557   return 0;
543558}
544559
r1810r1811
590605         *buffer = 0;
591606   }
592607}
608
609/*
610   Thomson EF9340/EF9341 extra chips in the g7400
611 */
612
613static struct {
614   UINT8   X;
615   UINT8   Y;
616   UINT8   Y0;
617   UINT8   R;
618   UINT8   M;
619   UINT8   TA;
620   UINT8   TB;
621   UINT8   busy;
622   UINT8   ram[1024];
623} ef9341;
624
625INLINE UINT16 ef9341_get_c_addr( void ) {
626   if ( ( ef9341.Y & 0x0C ) == 0x0C ) {
627      return 0x318 | ( ( ef9341.X & 0x38 ) << 2 ) | ( ef9341.X & 0x07 );
628   }
629   if ( ef9341.X & 0x20 ) {
630      return 0x300 | ( ( ef9341.Y & 0x07 ) << 5 ) | ( ef9341.Y & 0x18 ) | ( ef9341.X & 0x07 );
631   }
632   return ( ef9341.Y << 5 ) | ef9341.X;
633}
634
635INLINE void ef9341_inc_c( void ) {
636   ef9341.X++;
637   if ( ef9341.X >= 40 ) {
638      ef9341.Y = ( ef9341.Y + 1 ) % 24;
639   }
640}
641
642void ef9341_w( int command, int b, UINT8 data ) {
643   logerror("ef9341 %s write, t%s, data %02X\n", command ? "command" : "data", b ? "B" : "A", data );
644
645   if ( command ) {
646      if ( b ) {
647         ef9341.TB = data;
648         ef9341.busy = 0x80;
649         switch( ef9341.TB & 0xE0 ) {
650         case 0x00:   /* Begin row */
651            ef9341.X = 0;
652            ef9341.Y = ef9341.TA & 0x1F;
653            break;
654         case 0x20:   /* Load Y */
655            ef9341.Y = ef9341.TA & 0x1F;
656            break;
657         case 0x40:   /* Load X */
658            ef9341.X = ef9341.TA & 0x3F;
659            break;
660         case 0x60:   /* INC C */
661            ef9341_inc_c();
662            break;
663         case 0x80:   /* Load M */
664            ef9341.M = ef9341.TA;
665            break;
666         case 0xA0:   /* Load R */
667            ef9341.R = ef9341.TA;
668            break;
669         case 0xC0:   /* Load Y0 */
670            ef9341.Y0 = ef9341.TA & 0x3F;
671            break;
672         }
673         ef9341.busy = 0;
674      } else {
675         ef9341.TA = data;
676      }
677   } else {
678      if ( b ) {
679         ef9341.TB = data;
680         ef9341.busy = 0x80;
681         switch ( ef9341.M & 0xE0 ) {
682         case 0x00:   /* Write */
683            ef9341.ram[ ef9341_get_c_addr() ] = ef9341.TB;
684            ef9341_inc_c();
685            break;
686         case 0x20:   /* Read */
687            logerror("ef9341 unimplemented data action %02X\n", ef9341.M & 0xE0 );
688            ef9341_inc_c();
689            break;
690         case 0x40:   /* Write without increment */
691         case 0x60:   /* Read without increment */
692         case 0x80:   /* Write slice */
693         case 0xA0:   /* Read slice */
694            logerror("ef9341 unimplemented data action %02X\n", ef9341.M & 0xE0 );
695            break;
696         }
697         ef9341.busy = 0;
698      } else {
699         ef9341.TA = data;
700      }
701   }
702}
703
704UINT8 ef9341_r( int command, int b ) {
705   UINT8   data = 0xFF;
706
707   logerror("ef9341 %s read, t%s\n", command ? "command" : "data", b ? "B" : "A" );
708   if ( command ) {
709      if ( b ) {
710         data = 0xFF;
711      } else {
712         data = ef9341.busy;
713      }
714   } else {
715      if ( b ) {
716         data = ef9341.TB;
717         ef9341.busy = 0x80;
718      } else {
719         data = ef9341.TA;
720      }
721   }
722   return data;
723}
724
src/mess/machine/odyssey2.c
r1810r1811
5959      odyssey2_video_w(offset, data);
6060}
6161
62READ8_HANDLER( g7400_bus_r )
63{
64   if ((p1 & (P1_VDC_COPY_MODE_ENABLE | P1_VDC_ENABLE)) == 0) {
65      return odyssey2_video_r(offset); /* seems to have higher priority than ram??? */
66   }
67   else if (!(p1 & P1_EXT_RAM_ENABLE)) {
68      return ram[offset];
69   } else {
70//      return ef9341_r( offset & 0x02, offset & 0x01 );
71   }
72
73   return 0;
74}
75
76WRITE8_HANDLER( g7400_bus_w )
77{
78   if ((p1 & (P1_EXT_RAM_ENABLE | P1_VDC_COPY_MODE_ENABLE)) == 0x00) {
79      ram[offset] = data;
80   }
81   else if (!(p1 & P1_VDC_ENABLE)) {
82      odyssey2_video_w(offset, data);
83   } else {
84//      ef9341_w( offset & 0x02, offset & 0x01, data );
85   }
86}
87
6288/***** 8048 Ports ************************/
6389
6490READ8_HANDLER( odyssey2_getp1 )
src/mess/drivers/odyssey2.c
r1810r1811
2525   AM_RANGE( I8039_t1,  I8039_t1)   AM_READ( odyssey2_t1_r )
2626ADDRESS_MAP_END
2727
28static ADDRESS_MAP_START( g7400_io , ADDRESS_SPACE_IO, 8)
29   AM_RANGE( 0x00,      0xff)      AM_READWRITE( g7400_bus_r, g7400_bus_w)
30   AM_RANGE( I8039_p1,  I8039_p1)  AM_READWRITE( odyssey2_getp1, odyssey2_putp1 )
31   AM_RANGE( I8039_p2,  I8039_p2)  AM_READWRITE( odyssey2_getp2, odyssey2_putp2 )
32   AM_RANGE( I8039_bus, I8039_bus) AM_READWRITE( odyssey2_getbus, odyssey2_putbus )
33   AM_RANGE( I8039_t1,  I8039_t1)  AM_READ( odyssey2_t1_r )
34ADDRESS_MAP_END
35
2836static INPUT_PORTS_START( odyssey2 )
2937   PORT_START      /* IN0 */
3038   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_0) PORT_CHAR('0')
r1810r1811
144152   MDRV_CPU_ADD(I8048, ( ( XTAL_7_15909MHz * 3 ) / 4 ) )
145153   MDRV_CPU_PROGRAM_MAP(odyssey2_mem, 0)
146154   MDRV_CPU_IO_MAP(odyssey2_io, 0)
147   MDRV_CPU_VBLANK_INT(odyssey2_line, 262)
148155   MDRV_INTERLEAVE(1)
149156
150157   MDRV_MACHINE_RESET( odyssey2 )
r1810r1811
152159    /* video hardware */
153160   MDRV_SCREEN_ADD("main", RASTER)
154161   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
155   MDRV_SCREEN_RAW_PARAMS( XTAL_7_15909MHz/2, 227, 0, 160, 263, 0, 240 )
162   MDRV_SCREEN_RAW_PARAMS( XTAL_7_15909MHz/2, I824X_LINE_CLOCKS, I824X_START_ACTIVE_SCAN, I824X_END_ACTIVE_SCAN, 262, I824X_START_Y, I824X_START_Y + I824X_SCREEN_HEIGHT )
156163
157164   MDRV_GFXDECODE( odyssey2 )
158165   MDRV_PALETTE_LENGTH(24)
r1810r1811
173180   MDRV_CPU_ADD(I8048, ( XTAL_17_73447MHz / 3 ) )
174181   MDRV_CPU_PROGRAM_MAP(odyssey2_mem, 0)
175182   MDRV_CPU_IO_MAP(odyssey2_io, 0)
176   MDRV_CPU_VBLANK_INT(odyssey2_line, 262)
177183   MDRV_INTERLEAVE(1)
178184
179185   MDRV_MACHINE_RESET( odyssey2 )
r1810r1811
181187   /* video hardware */
182188   MDRV_SCREEN_ADD("main", RASTER)
183189   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
184   MDRV_SCREEN_RAW_PARAMS( XTAL_17_73447MHz/5, 227, 0, 160, 313, 0, 240 )
190   MDRV_SCREEN_RAW_PARAMS( XTAL_17_73447MHz/5, I824X_LINE_CLOCKS, I824X_START_ACTIVE_SCAN, I824X_END_ACTIVE_SCAN, 312, I824X_START_Y, I824X_START_Y + I824X_SCREEN_HEIGHT )
185191
186192   MDRV_GFXDECODE( odyssey2 )
187193   MDRV_PALETTE_LENGTH(24)
r1810r1811
201207   /* basic machine hardware */
202208   MDRV_CPU_ADD(I8048, 5911000 )
203209   MDRV_CPU_PROGRAM_MAP(odyssey2_mem, 0)
204   MDRV_CPU_IO_MAP(odyssey2_io, 0)
205   MDRV_CPU_VBLANK_INT(odyssey2_line, 262)
210   MDRV_CPU_IO_MAP(g7400_io, 0)
206211   MDRV_INTERLEAVE(1)
207212
208213   MDRV_MACHINE_RESET( odyssey2 )
r1810r1811
210215   /* video hardware */
211216   MDRV_SCREEN_ADD("main", RASTER)
212217   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
213   MDRV_SCREEN_RAW_PARAMS( 3547000*2, 448, 96, 416, 312, 39, 289 )   /* EF9340 operates doubles the input clock into dot clocks internally */
218   MDRV_SCREEN_RAW_PARAMS( 3547000*2, 448, 96, 416, 312, 39, 289 )   /* EF9340 doubles the input clock into dot clocks internally */
214219
215220   MDRV_GFXDECODE( odyssey2 )
216221   MDRV_PALETTE_LENGTH(24)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team