Previous 199869 Revisions Next

r21475 Thursday 28th February, 2013 at 00:21:03 UTC by David Haywood
bubble sort instead of zbuffer, fixes most remaining gfx problems so I've removed all flags apart from the imperfect sound.

new working game
----------------
Cool Riders [David Haywood,  Angelo Salese]
[src/mame/drivers]coolridr.c

trunk/src/mame/drivers/coolridr.c
r21474r21475
22
33    System H1 (c) 1994 Sega
44
5    preliminary driver by David Haywood, Angelo Salese and Tomasz Slanina
5    Driver by David Haywood, Angelo Salese and Tomasz Slanina
66    special thanks to Guru for references and HW advices
77
8   This system is interesting in that it makes use of an RLE compression scheme, which
9   is not something common for Sega hardware, there is a patent for it ( 6,141,122 )
10   http://www.google.com/patents/US6141122
11
812    TODO:
9    - decode compressed GFX ROMs for "sprite" blitter (6,141,122 is the patent number)
10     http://www.google.com/patents/US6141122
11    - DMA is still a bit of a mystery;
12    - video emulation is pratically non-existant;
13    - SCSP;
14    - Many SH-1 ports needs investigations;
13   - walk the dog
14   - improve sound emulation
1515    - i8237 purpose is unknown, might even not be at the right place ...
16    - IRQ generation
17    - Understand & remove the hacks at the bottom;
18    - IC1/IC10 are currently unused, might contain sprite data / music data for the SCSP / chars for the
19      text tilemap/blitter;
16   - verify zooming etc. our current algorithm is a bit ugly for text
2017
18
19
2120=======================================================================================================
2221
2322Cool Riders
r21474r21475
274273read a 160-bit word at once. Regardless both addresses are restricted
275274to the same bank as defined through A20.
276275
277From looking at the ROMs there seem to be structures that may be
278tables. A table would be needed to associate a tile number with RLE
279data in ROM, so that would be a likely function of tables in the ROM.
280It may be that the split address design allows the chip to read table
281data from one 80-bit port while reading in graphics data from the
282other.
283
284Now this next bit is just an interpretation of what's in the patent,
285so you probably already know it:
286
287The primitive unit of graphics data is a 10-bit word (hence all the
288multiples of 10 listed above, e.g. 80 and 160-bit words) The top two
289bits define the type:
290
2910,x : $000 : Type A (3-bit color code, 5-bit run length, 1 bit "cell" flag)
2921,x : $800 : Type B (7-bit color code, 2-bit run length)
2931,1 : $C00 : Type C (8-bit color code)
294
295Because the top two bits (which identify the type) are shared with the
296color code, this limits the range of colors somewhat. E.g. one of the
297patent diagrams shows the upper 4 bits of a Type A pixel moved into
298the bottom four bits of the color RAM index, but for type A the most
299significant bit is always zero. So that 4-bit quantity is always 0-7
300which is why type A has a limit of 8 colors.
301
302This is why one of the later diagrams shows the Type B pixel ANDed
303with 7F and the Type C pixel ANDed with 3FF, to indicate the two
304indicator bits are being stripped out and the remaining value is
305somewhat truncated.
306
307We figured due to the colorful graphics in the game there would be a
308large groups of Type C pixels, but we could never find an
309rearrangement of data and address bits that yielded a large number of
310words with bits 9,8 set. Some of the data looks like it's linear, and
311some of it looks like bitplanes. Perhaps tables are linear and
312graphics are planar.
313
314We tried the usual stuff; assuming the 16-bit words from each ROM was
315a 160-pixel wide array of 10-bit elements (linear), or assuming each
316bit from each ROM was a single bit of a 10-bit word so 16 bits defined
31716 10-bit words in parallel (planar), and never got useful output.
318
319There may be some weird data/address scrambling done to put data in an
320order easiest for the hardware to process, which would be
321non-intuitive.
322
323Also the two indicator bits may have different polarities, maybe 0,0
324is Type C instead of 1,1.
325
326--- CORRECTION from Charles 20/02/13
327
328I was just playing around with decoding this morning, and now I feel
329certain the ordering is to take the 16-bit output of each of the 10
330ROMs at a given address and divide that 160-bit word into sixteen
33110-bit words.
332
333When you do this, you get some kind of animation at 0x3898E0 which is
334eight sequential frames of an object with a solid color fill in the
335background. Because the size is constant it may be all Type C pixels
336(e.g. no run-length) so that could be a good place to start with
337shuffling bits/addresses to see how to get a lot of $3xx pixels.
338
339There's a similar animation at 0x73CEC0, smaller object, 32 frames.
340
341I think the 'background' data behind the object in both cases might be
342a pen number that continuously increases, maybe for flashing effect as
343you cycle through the animation. Otherwise you'd expect the background
344pixels to be the same in each frame.
345
346I also wonder if a pixel value of 0000 (type A with run length=0)
347indicates a single dot since there are a lot of 0000 words.
348
349There may be some bit/byte/address swapping needed to still get valid
350output. And the tables may be encoded differently, there's a large one
351at 0xDE60.
352
353
354
355276*/
356277
357278
r21474r21475
400321      m_io_an7(*this, "AN7"),
401322      m_io_config(*this, "CONFIG")
402323   {
403      m_work_queue[0] = osd_work_queue_alloc(WORK_QUEUE_FLAG_HIGH_FREQ);
404      m_work_queue[1] = osd_work_queue_alloc(WORK_QUEUE_FLAG_HIGH_FREQ);
405      decode[0].current_object = 0;
406      decode[1].current_object = 0;
407      debug_randompal = 9;
324
408325   }
409326
410327   // Blitter state
r21474r21475
450367
451368   bitmap_ind16 m_temp_bitmap_sprites;
452369   bitmap_ind16 m_temp_bitmap_sprites2;
453   bitmap_ind16 m_zbuffer_bitmap;
454   bitmap_ind16 m_zbuffer_bitmap2;
370   //bitmap_ind16 m_zbuffer_bitmap;
371   //bitmap_ind16 m_zbuffer_bitmap2;
455372
456373   bitmap_ind16 m_bg_bitmap;
457374   bitmap_ind16 m_bg_bitmap2;
r21474r21475
543460      UINT32* indirect_zoom;
544461      UINT32 spriteblit[12];
545462      bitmap_ind16* drawbitmap;
546      bitmap_ind16* zbitmap;
463      //bitmap_ind16* zbitmap;
547464      UINT16 zpri;
548465      UINT8 blittype;
549466      coolridr_state* state;
r21474r21475
645562
646563   machine().primary_screen->register_screen_bitmap(m_temp_bitmap_sprites);
647564   machine().primary_screen->register_screen_bitmap(m_temp_bitmap_sprites2);
648   machine().primary_screen->register_screen_bitmap(m_zbuffer_bitmap);
649   machine().primary_screen->register_screen_bitmap(m_zbuffer_bitmap2);
565   //machine().primary_screen->register_screen_bitmap(m_zbuffer_bitmap);
566   //machine().primary_screen->register_screen_bitmap(m_zbuffer_bitmap2);
650567   machine().primary_screen->register_screen_bitmap(m_bg_bitmap);
651568   machine().primary_screen->register_screen_bitmap(m_bg_bitmap2);
652569
r21474r21475
12661183      if (drawy>clipmaxY) { break; }; \
12671184      if (drawy<clipminY) { drawy++; continue; }; \
12681185      line = &drawbitmap->pix16(drawy); \
1269      zline = &object->zbitmap->pix16(drawy); \
1186      /* zline = &object->zbitmap->pix16(drawy); */ \
12701187      int blockwide = pixelOffsetnextX-pixelOffsetX; \
12711188      if (pixelOffsetX+blockwide <clipminX) { drawy++; continue; } \
12721189      if (pixelOffsetX>clipmaxX)  { drawy++; continue; } \
r21474r21475
13051222      const int drawy = pixelOffsetY+y; \
13061223      if ((drawy>clipmaxY) || (drawy<clipminY)) continue; \
13071224      line = &drawbitmap->pix16(drawy); \
1308      zline = &object->zbitmap->pix16(drawy); \
1225      /* zline = &object->zbitmap->pix16(drawy); */ \
13091226      int drawx = pixelOffsetX; \
13101227      for (int x = 0; x < blockwide; x++) \
13111228      { \
r21474r21475
13241241      const int drawy = pixelOffsetY+realy; \
13251242      if ((drawy>clipmaxY) || (drawy<clipminY)) continue; \
13261243      line = &drawbitmap->pix16(drawy); \
1327      zline = &object->zbitmap->pix16(drawy); \
1244      /* zline = &object->zbitmap->pix16(drawy); */ \
13281245      int drawx = pixelOffsetX; \
13291246      for (int realx = 0; realx < 16; realx++) \
13301247      { \
r21474r21475
13541271   /* values < 0x8000 have no alpha effect to them */ \
13551272   if (pix < 0x8000) \
13561273   { \
1357      if (object->zpri < zline[drawx]) \
1274      /*if (object->zpri < zline[drawx])*/ \
13581275      { \
13591276         { \
13601277            line[drawx] = pix&0x7fff; \
1361            zline[drawx] = object->zpri; \
1278            /*zline[drawx] = object->zpri;*/ \
13621279         } \
13631280      } \
13641281   } \
r21474r21475
13661283   else if (pix > 0x8000) \
13671284   { \
13681285      /* a blend level of 0x8 (real register value 0x7 but we added one so we can shift instead of divide in code below) seems to be the same as solid, it is set on most parts of the road and during the 'lovemachine' animation in attract when the heart should be hidden */ \
1369      if (object->zpri < zline[drawx]) \
1286      /* if (object->zpri < zline[drawx]) */ \
13701287      { \
13711288         if (blit4blendlevelinv==0x0) \
13721289         { \
13731290            line[drawx] = pix&0x7fff; \
1374            zline[drawx] = object->zpri; \
1291            /* zline[drawx] = object->zpri; */ \
13751292         } \
13761293         else \
13771294         { \
r21474r21475
13831300           int dest_g = ((pix>>5)&0x1f)  * blit4blendlevel; \
13841301           int dest_b = ((pix>>0)&0x1f)  * blit4blendlevel; \
13851302           line[drawx] = (((src_r+dest_r)>>3)<<10) | (((src_g+dest_g)>>3)<<5) | (((src_b+dest_b)>>3)<<0); \
1386           zline[drawx] = object->zpri; \
1303           /* zline[drawx] = object->zpri; */ \
13871304         } \
13881305      } \
13891306   } \
r21474r21475
20992016
21002017         // DEBUG: Draw 16x16 block
21012018         UINT16* line;
2102         UINT16* zline;
2019         //UINT16* zline;
21032020
21042021
21052022         if (indirect_zoom_enable)
r21474r21475
24142331   if (m_blitterMode == 0x30 || m_blitterMode == 0x40 || m_blitterMode == 0x4f || m_blitterMode == 0x50 || m_blitterMode == 0x60)
24152332   {
24162333      testobject->drawbitmap = &m_temp_bitmap_sprites;
2417      testobject->zbitmap = &m_zbuffer_bitmap;
2334      /* testobject->zbitmap = &m_zbuffer_bitmap; */
24182335      // pass these from the type 1 writes
24192336      testobject->clipvals[0] = m_clipvals[0][0];
24202337      testobject->clipvals[1] = m_clipvals[0][1];
r21474r21475
24272344   else // 0x90, 0xa0, 0xaf, 0xb0, 0xc0
24282345   {
24292346      testobject->drawbitmap = &m_temp_bitmap_sprites2;
2430      testobject->zbitmap = &m_zbuffer_bitmap2;
2347      /* testobject->zbitmap = &m_zbuffer_bitmap2; */
24312348      // pass these from the type 1 writes
24322349      testobject->clipvals[0] = m_clipvals[1][0];
24332350      testobject->clipvals[1] = m_clipvals[1][1];
r21474r21475
27002617            // render the tilemap to the backbuffer, ready for having sprites drawn on it
27012618            draw_bg_coolridr(m_temp_bitmap_sprites, visarea, 0);
27022619            // wipe the z-buffer ready for the sprites           
2703            m_zbuffer_bitmap.fill(0xffff, visarea);
2620            /* m_zbuffer_bitmap.fill(0xffff, visarea); */
27042621            // almost certainly wrong
27052622            m_clipvals[0][0] = 0;
27062623            m_clipvals[0][1] = 0;
27072624            m_clipvals[0][2] = 0;
27082625            m_clipblitterMode[0] = 0xff;
27092626         
2710            //qsort(m_cool_render_object_list1, m_listcount1, sizeof(struct cool_render_object *), comp_sprite_z);
2627            /* bubble sort, might be something better to use instead */
2628            for (int pass = 0 ; pass < ( m_listcount1 - 1 ); pass++)
2629            {
2630               for (int elem2 = 0 ; elem2 < m_listcount1 - pass - 1; elem2++)
2631               {
2632                  if (m_cool_render_object_list1[elem2]->zpri > m_cool_render_object_list1[elem2+1]->zpri)
2633                  {
2634                     cool_render_object* temp = m_cool_render_object_list1[elem2];
2635                     m_cool_render_object_list1[elem2]   = m_cool_render_object_list1[elem2+1];
2636                     m_cool_render_object_list1[elem2+1] = temp;
2637                  }
2638               }
2639            }
27112640
2712            for (int i=0;i<m_listcount1;i++)
2641            for (int i=m_listcount1-1;i>=0;i--)
27132642            {
27142643               if (m_usethreads)
27152644               {
r21474r21475
27402669            // render the tilemap to the backbuffer, ready for having sprites drawn on it
27412670            draw_bg_coolridr(m_temp_bitmap_sprites2, visarea, 1);
27422671            // wipe the z-buffer ready for the sprites           
2743            m_zbuffer_bitmap2.fill(0xffff, visarea);
2672            /* m_zbuffer_bitmap2.fill(0xffff, visarea); */
27442673            // almost certainly wrong
27452674            m_clipvals[1][0] = 0;
27462675            m_clipvals[1][1] = 0;
27472676            m_clipvals[1][2] = 0;
27482677            m_clipblitterMode[1] = 0xff;
27492678   
2750            //qsort(m_cool_render_object_list2, m_listcount2, sizeof(struct cool_render_object *), comp_sprite_z);
2679               /* bubble sort, might be something better to use instead */
2680            for (int pass = 0 ; pass < ( m_listcount2 - 1 ); pass++)
2681            {
2682               for (int elem2 = 0 ; elem2 < m_listcount2 - pass - 1; elem2++)
2683               {
2684                  if (m_cool_render_object_list2[elem2]->zpri > m_cool_render_object_list2[elem2+1]->zpri)
2685                  {
2686                     cool_render_object* temp = m_cool_render_object_list2[elem2];
2687                     m_cool_render_object_list2[elem2]   = m_cool_render_object_list2[elem2+1];
2688                     m_cool_render_object_list2[elem2+1] = temp;
2689                  }
2690               }
2691            }
27512692
2752            for (int i=0;i<m_listcount2;i++)
2693            for (int i=m_listcount2-1;i>=0;i--)
27532694            {
27542695               if (m_usethreads)
27552696               {
r21474r21475
36333574   m_cool_render_object_list2 = auto_alloc_array_clear(machine(), struct cool_render_object*, 1000000);
36343575   m_listcount2 = 0;
36353576
3577   m_work_queue[0] = osd_work_queue_alloc(WORK_QUEUE_FLAG_HIGH_FREQ);
3578   m_work_queue[1] = osd_work_queue_alloc(WORK_QUEUE_FLAG_HIGH_FREQ);
3579   decode[0].current_object = 0;
3580   decode[1].current_object = 0;
3581   debug_randompal = 9;
36363582
36373583   save_pointer(NAME(m_h1_vram), VRAM_SIZE);
36383584   save_pointer(NAME(m_h1_pcg), VRAM_SIZE);
r21474r21475
38643810   sh2drc_set_options(machine().device("sub"), SH2DRC_FASTEST_OPTIONS);
38653811}
38663812
3867GAME( 1995, coolridr,    0, coolridr,    coolridr, coolridr_state,    coolridr, ROT0,  "Sega", "Cool Riders",GAME_NOT_WORKING|GAME_IMPERFECT_SOUND|GAME_IMPERFECT_GRAPHICS ) // region is set in test mode, this set is for Japan, USA and Export (all regions)
3813GAME( 1995, coolridr,    0, coolridr,    coolridr, coolridr_state,    coolridr, ROT0,  "Sega", "Cool Riders",GAME_IMPERFECT_SOUND) // region is set in test mode, this set is for Japan, USA and Export (all regions)
38683814

Previous 199869 Revisions Next


© 1997-2024 The MAME Team