Previous 199869 Revisions Next

r36164 Sunday 1st March, 2015 at 14:41:49 UTC by David Haywood
modernize a bit (nw)
[src/mame/drivers]hng64.c
[src/mame/includes]hng64.h
[src/mame/video]hng64.c

trunk/src/mame/drivers/hng64.c
r244675r244676
867867      }
868868
869869      // Send it off to the 3d subsystem.
870      hng64_command3d(machine(), packet3d);
870      hng64_command3d( packet3d);
871871   }
872872#endif
873873}
r244675r244676
892892{
893893   // this handles 3d to fb upload
894894   UINT16 packet3d[16];
895//   printf("dl_upload_w %08x %08x\n", data, mem_mask);
895896
897
896898   for(int packetStart=0;packetStart<0x200/4;packetStart+=8)
897899   {
898900      // Create a 3d packet
r244675r244676
906908      }
907909
908910      // Send it off to the 3d subsystem.
909      hng64_command3d(machine(), packet3d);
911      hng64_command3d( packet3d);
910912   }
911913
912914   machine().scheduler().timer_set(m_maincpu->cycles_to_attotime(0x200*8), timer_expired_delegate(FUNC(hng64_state::hng64_3dfifo_processed),this));
r244675r244676
915917/* Note: Samurai Shodown games never calls bit 1, so it can't be framebuffer clear. It also calls bit 3 at start-up, meaning unknown */
916918WRITE32_MEMBER(hng64_state::dl_control_w) // This handles framebuffers
917919{
920//   printf("dl_control_w %08x %08x\n", data, mem_mask);
921
918922   //if(data & 2) // swap buffers
919923   //{
920924   //  clear3d();
r244675r244676
17371741   GFXDECODE_ENTRY( "textures", 0, hng64_texlayout,     0x0, 0x10 )  /* textures */
17381742GFXDECODE_END
17391743
1740static void hng64_reorder(running_machine &machine, UINT8* gfxregion, size_t gfxregionsize)
1744static void hng64_reorder( UINT8* gfxregion, size_t gfxregionsize)
17411745{
17421746   // by default 2 4bpp tiles are stored in each 8bpp tile, this makes decoding in MAME harder than it needs to be
17431747   // reorder them
r244675r244676
17571761
17581762DRIVER_INIT_MEMBER(hng64_state,hng64_reorder_gfx)
17591763{
1760   hng64_reorder(machine(), memregion("scrtile")->base(), memregion("scrtile")->bytes());
1764   hng64_reorder(memregion("scrtile")->base(), memregion("scrtile")->bytes());
17611765}
17621766
17631767#define HACK_REGION
17641768#ifdef HACK_REGION
1765static void hng64_patch_bios_region(running_machine& machine, int region)
1769void hng64_state::hng64_patch_bios_region(int region)
17661770{
1767   UINT8 *rom = machine.root_device().memregion("user1")->base();
1771   UINT8 *rom = memregion("user1")->base();
17681772
17691773   if ((rom[0x4000]==0xff) && (rom[0x4001] == 0xff))
17701774   {
r244675r244676
17811785   // region hacking, english error messages are more useful to us, but no english bios is dumped...
17821786#ifdef HACK_REGION
17831787// versions according to fatal fury test mode
1784//  hng64_patch_bios_region(machine(), 0); // 'Others Ver' (invalid?)
1785   hng64_patch_bios_region(machine(), 1); // Japan
1786//  hng64_patch_bios_region(machine(), 2); // USA
1787//  hng64_patch_bios_region(machine(), 3); // Korea
1788//  hng64_patch_bios_region(machine(), 4); // 'Others'
1788//  hng64_patch_bios_region( 0); // 'Others Ver' (invalid?)
1789   hng64_patch_bios_region( 1); // Japan
1790//  hng64_patch_bios_region( 2); // USA
1791//  hng64_patch_bios_region( 3); // Korea
1792//  hng64_patch_bios_region( 4); // 'Others'
17891793#endif
17901794
17911795   /* 1 meg of virtual address space for the com cpu */
trunk/src/mame/includes/hng64.h
r244675r244676
1010   BURIKI_MCU
1111};
1212
13enum hng64trans_t
14{
15   HNG64_TILEMAP_NORMAL = 1,
16   HNG64_TILEMAP_ADDITIVE,
17   HNG64_TILEMAP_ALPHA
18};
1319
1420
21struct blit_parameters
22{
23   bitmap_rgb32 *          bitmap;
24   rectangle           cliprect;
25   UINT32              tilemap_priority_code;
26   UINT8               mask;
27   UINT8               value;
28   UINT8               alpha;
29   hng64trans_t        drawformat;
30};
31
32
33
34///////////////////////
35// polygon rendering //
36///////////////////////
37
38struct polygonRasterOptions
39{
40   UINT8 texType;
41   UINT8 texIndex;
42   UINT8 texPageSmall;
43   UINT8 texPageHorizOffset;
44   UINT8 texPageVertOffset;
45   int palOffset;
46   int palPageSize;
47   int debugColor;
48};
49
1550class hng64_state : public driver_device
1651{
1752public:
r244675r244676
4075      m_screen(*this, "screen"),
4176      m_palette(*this, "palette"),
4277      m_generic_paletteram_32(*this, "paletteram")
43      { }
4478
79   { }
80   
4581   required_device<mips3_device> m_maincpu;
4682   required_device<cpu_device> m_audiocpu;
4783   required_device<cpu_device> m_comm;
r244675r244676
70106   required_device<palette_device> m_palette;
71107   required_shared_ptr<UINT32> m_generic_paletteram_32;
72108
109
73110   int m_mcu_type;
74111
75112   UINT16 *m_soundram;
r244675r244676
217254   DECLARE_CUSTOM_INPUT_MEMBER(brake_down_r);
218255   void clear3d();
219256   TIMER_CALLBACK_MEMBER(hng64_3dfifo_processed);
257
258   void FillSmoothTexPCHorizontalLine(
259      const polygonRasterOptions& prOptions,
260      int x_start, int x_end, int y, float z_start, float z_delta,
261      float w_start, float w_delta, float r_start, float r_delta,
262      float g_start, float g_delta, float b_start, float b_delta,
263      float s_start, float s_delta, float t_start, float t_delta);
264
265   void hng64_command3d(const UINT16* packet);
266   void draw_sprites(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
267   void transition_control( bitmap_rgb32 &bitmap, const rectangle &cliprect);
268   void hng64_tilemap_draw_roz_core(screen_device &screen, tilemap_t *tmap, const blit_parameters *blit,
269      UINT32 startx, UINT32 starty, int incxx, int incxy, int incyx, int incyy, int wraparound);
270   void hng64_drawtilemap(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect, int tm);
271   void setCameraTransformation(const UINT16* packet);
272   void setLighting(const UINT16* packet);
273   void set3dFlags(const UINT16* packet);
274   void setCameraProjectionMatrix(const UINT16* packet);
275   void recoverPolygonBlock(const UINT16* packet, struct polygon* polys, int* numPolys);
276   void hng64_mark_all_tiles_dirty(int tilemap);
277   void hng64_mark_tile_dirty(int tilemap, int tile_index);
278
279   void hng64_tilemap_draw_roz(screen_device &screen, bitmap_rgb32 &dest, const rectangle &cliprect, tilemap_t *tmap,
280      UINT32 startx, UINT32 starty, int incxx, int incxy, int incyx, int incyy,
281      int wraparound, UINT32 flags, UINT8 priority, hng64trans_t drawformat);
282
283   void hng64_tilemap_draw_roz_primask(screen_device &screen, bitmap_rgb32 &dest, const rectangle &cliprect, tilemap_t *tmap,
284      UINT32 startx, UINT32 starty, int incxx, int incxy, int incyx, int incyy,
285      int wraparound, UINT32 flags, UINT8 priority, UINT8 priority_mask, hng64trans_t drawformat);
286
287   void RasterizeTriangle_SMOOTH_TEX_PC(
288      float A[4], float B[4], float C[4],
289      float Ca[3], float Cb[3], float Cc[3], // PER-VERTEX RGB COLORS
290      float Ta[2], float Tb[2], float Tc[2], // PER-VERTEX (S,T) TEX-COORDS
291      const polygonRasterOptions& prOptions);
292
293   void drawShaded( struct polygon *p);
294
295   void hng64_patch_bios_region(int region);
296
220297};
221298
222/*----------- defined in video/hng64.c -----------*/
223void hng64_command3d(running_machine& machine, const UINT16* packet);
trunk/src/mame/video/hng64.c
r244675r244676
77
88
99
10static void hng64_mark_all_tiles_dirty( hng64_state *state, int tilemap )
10void hng64_state::hng64_mark_all_tiles_dirty( int tilemap )
1111{
12   state->m_tilemap[tilemap].m_tilemap_8x8->mark_all_dirty();
13   state->m_tilemap[tilemap].m_tilemap_16x16->mark_all_dirty();
14   state->m_tilemap[tilemap].m_tilemap_16x16_alt->mark_all_dirty();
12   m_tilemap[tilemap].m_tilemap_8x8->mark_all_dirty();
13   m_tilemap[tilemap].m_tilemap_16x16->mark_all_dirty();
14   m_tilemap[tilemap].m_tilemap_16x16_alt->mark_all_dirty();
1515}
1616
17static void hng64_mark_tile_dirty( hng64_state *state, int tilemap, int tile_index )
17void hng64_state::hng64_mark_tile_dirty( int tilemap, int tile_index )
1818{
19   state->m_tilemap[tilemap].m_tilemap_8x8->mark_tile_dirty(tile_index);
20   state->m_tilemap[tilemap].m_tilemap_16x16->mark_tile_dirty(tile_index);
21   state->m_tilemap[tilemap].m_tilemap_16x16_alt->mark_tile_dirty(tile_index);
19   m_tilemap[tilemap].m_tilemap_8x8->mark_tile_dirty(tile_index);
20   m_tilemap[tilemap].m_tilemap_16x16->mark_tile_dirty(tile_index);
21   m_tilemap[tilemap].m_tilemap_16x16_alt->mark_tile_dirty(tile_index);
2222}
2323
2424
r244675r244676
6363 * 0x0e0 in Samurai Shodown/Xrally games, 0x1c0 in all the others, zooming factor?
6464 */
6565
66static void draw_sprites(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
66void hng64_state::draw_sprites(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
6767{
68   hng64_state *state = screen.machine().driver_data<hng64_state>();
6968   gfx_element *gfx;
70   UINT32 *source = state->m_spriteram;
71   UINT32 *finish = state->m_spriteram + 0xc000/4;
69   UINT32 *source = m_spriteram;
70   UINT32 *finish = m_spriteram + 0xc000/4;
7271
7372   // global offsets in sprite regs
74   int spriteoffsx = (state->m_spriteregs[1]>>0)&0xffff;
75   int spriteoffsy = (state->m_spriteregs[1]>>16)&0xffff;
73   int spriteoffsx = (m_spriteregs[1]>>0)&0xffff;
74   int spriteoffsy = (m_spriteregs[1]>>16)&0xffff;
7675
7776#if 0
7877   for (int iii = 0; iii < 0x0f; iii++)
79      osd_printf_debug("%.8x ", state->m_videoregs[iii]);
78      osd_printf_debug("%.8x ", m_videoregs[iii]);
8079   osd_printf_debug("\n");
8180#endif
8281
r244675r244676
140139         int zoom_factor;
141140
142141         /* FIXME: regular zoom mode has precision bugs, can be easily seen in Samurai Shodown 64 intro */
143         zoom_factor = (state->m_spriteregs[0] & 0x08000000) ? 0x1000 : 0x100;
142         zoom_factor = (m_spriteregs[0] & 0x08000000) ? 0x1000 : 0x100;
144143         if(!zoomx) zoomx=zoom_factor;
145144         if(!zoomy) zoomy=zoom_factor;
146145
r244675r244676
155154         zoomy += (int)((foomY - floor(foomY)) * (float)0x10000);
156155      }
157156
158      if (state->m_spriteregs[0] & 0x00800000) //bpp switch
157      if (m_spriteregs[0] & 0x00800000) //bpp switch
159158      {
160         gfx= state->m_gfxdecode->gfx(4);
159         gfx= m_gfxdecode->gfx(4);
161160      }
162161      else
163162      {
164         gfx= state->m_gfxdecode->gfx(5);
163         gfx= m_gfxdecode->gfx(5);
165164         tileno>>=1;
166165         pal&=0xf;
167166      }
r244675r244676
220219               tileno=(source[4]&0x0007ffff);
221220               pal =(source[3]&0x00ff0000)>>16;
222221
223               if (state->m_spriteregs[0] & 0x00800000) //bpp switch
222               if (m_spriteregs[0] & 0x00800000) //bpp switch
224223               {
225                  gfx= state->m_gfxdecode->gfx(4);
224                  gfx= m_gfxdecode->gfx(4);
226225               }
227226               else
228227               {
229                  gfx= state->m_gfxdecode->gfx(5);
228                  gfx= m_gfxdecode->gfx(5);
230229                  tileno>>=1;
231230                  pal&=0xf;
232231               }
r244675r244676
286285 */
287286
288287/* this is broken for the 'How to Play' screen in Buriki after attract, disabled for now */
289static void transition_control(running_machine &machine, bitmap_rgb32 &bitmap, const rectangle &cliprect)
288void hng64_state::transition_control( bitmap_rgb32 &bitmap, const rectangle &cliprect)
290289{
291   hng64_state *state = machine.driver_data<hng64_state>();
292   UINT32 *hng64_tcram = state->m_tcram;
290   UINT32 *hng64_tcram = m_tcram;
293291   int i, j;
294292
295293//  float colorScaleR, colorScaleG, colorScaleB;
r244675r244676
506504WRITE32_MEMBER(hng64_state::hng64_videoram_w)
507505{
508506   int realoff;
509   hng64_state *state = machine().driver_data<hng64_state>();
510507   COMBINE_DATA(&m_videoram[offset]);
511508
512509   realoff = offset*4;
513510
514511   if ((realoff>=0) && (realoff<0x10000))
515512   {
516      hng64_mark_tile_dirty(state, 0, offset&0x3fff);
513      hng64_mark_tile_dirty(0, offset&0x3fff);
517514   }
518515   else if ((realoff>=0x10000) && (realoff<0x20000))
519516   {
520      hng64_mark_tile_dirty(state, 1, offset&0x3fff);
517      hng64_mark_tile_dirty(1, offset&0x3fff);
521518   }
522519   else if ((realoff>=0x20000) && (realoff<0x30000))
523520   {
524      hng64_mark_tile_dirty(state, 2, offset&0x3fff);
521      hng64_mark_tile_dirty(2, offset&0x3fff);
525522   }
526523   else if ((realoff>=0x30000) && (realoff<0x40000))
527524   {
528      hng64_mark_tile_dirty(state, 3, offset&0x3fff);
525      hng64_mark_tile_dirty(3, offset&0x3fff);
529526   }
530527
531528//  if ((realoff>=0x40000)) osd_printf_debug("offsw %08x %08x\n",realoff,data);
r244675r244676
534531}
535532
536533/* internal set of transparency states for rendering */
537enum hng64trans_t
538{
539   HNG64_TILEMAP_NORMAL = 1,
540   HNG64_TILEMAP_ADDITIVE,
541   HNG64_TILEMAP_ALPHA
542};
543534
544535
545struct blit_parameters
546{
547   bitmap_rgb32 *          bitmap;
548   rectangle           cliprect;
549   UINT32              tilemap_priority_code;
550   UINT8               mask;
551   UINT8               value;
552   UINT8               alpha;
553   hng64trans_t        drawformat;
554};
555
556
557
558536static void hng64_configure_blit_parameters(blit_parameters *blit, tilemap_t *tmap, bitmap_rgb32 &dest, const rectangle &cliprect, UINT32 flags, UINT8 priority, UINT8 priority_mask, hng64trans_t drawformat)
559537{
560538   /* start with nothing */
r244675r244676
631609      *(UINT32 *)dest = alpha_blend_r32(*(UINT32 *)dest, clut[INPUT_VAL], alpha); \
632610} while (0)
633611
634static void hng64_tilemap_draw_roz_core(screen_device &screen, tilemap_t *tmap, const blit_parameters *blit,
612void hng64_state::hng64_tilemap_draw_roz_core(screen_device &screen, tilemap_t *tmap, const blit_parameters *blit,
635613      UINT32 startx, UINT32 starty, int incxx, int incxy, int incyx, int incyy, int wraparound)
636614{
637   hng64_state *state = screen.machine().driver_data<hng64_state>();
638   const pen_t *clut = &state->m_palette->pen(blit->tilemap_priority_code >> 16);
615   const pen_t *clut = &m_palette->pen(blit->tilemap_priority_code >> 16);
639616   bitmap_ind8 &priority_bitmap = screen.priority();
640617   bitmap_rgb32 &destbitmap = *blit->bitmap;
641618   bitmap_ind16 &srcbitmap = tmap->pixmap();
r244675r244676
809786
810787
811788
812static void hng64_tilemap_draw_roz_primask(screen_device &screen, bitmap_rgb32 &dest, const rectangle &cliprect, tilemap_t *tmap,
789void hng64_state::hng64_tilemap_draw_roz_primask(screen_device &screen, bitmap_rgb32 &dest, const rectangle &cliprect, tilemap_t *tmap,
813790      UINT32 startx, UINT32 starty, int incxx, int incxy, int incyx, int incyy,
814791      int wraparound, UINT32 flags, UINT8 priority, UINT8 priority_mask, hng64trans_t drawformat)
815792{
r244675r244676
837814}
838815
839816
840INLINE void hng64_tilemap_draw_roz(screen_device &screen, bitmap_rgb32 &dest, const rectangle &cliprect, tilemap_t *tmap,
817inline void hng64_state::hng64_tilemap_draw_roz(screen_device &screen, bitmap_rgb32 &dest, const rectangle &cliprect, tilemap_t *tmap,
841818      UINT32 startx, UINT32 starty, int incxx, int incxy, int incyx, int incyy,
842819      int wraparound, UINT32 flags, UINT8 priority, hng64trans_t drawformat)
843820{
r244675r244676
846823
847824
848825
849static void hng64_drawtilemap(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect, int tm )
826void hng64_state::hng64_drawtilemap(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect, int tm )
850827{
851   hng64_state *state = screen.machine().driver_data<hng64_state>();
852   UINT32 *hng64_videoregs = state->m_videoregs;
853   UINT32 *hng64_videoram = state->m_videoram;
828   UINT32 *hng64_videoregs = m_videoregs;
829   UINT32 *hng64_videoram = m_videoram;
854830   tilemap_t* tilemap = 0;
855831   UINT32 scrollbase = 0;
856832   UINT32 tileregs = 0;
r244675r244676
861837
862838   int global_dimensions = (global_tileregs&0x03000000)>>24;
863839
864   if ( (state->m_additive_tilemap_debug&(1 << tm)))
840   if ( (m_additive_tilemap_debug&(1 << tm)))
865841      debug_blend_enabled = 1;
866842
867843   if ((global_dimensions != 0) && (global_dimensions != 3))
r244675r244676
890866
891867   if (global_dimensions==0)
892868   {
893      if (tileregs&0x0200)    tilemap = state->m_tilemap[tm].m_tilemap_16x16;
894      else tilemap = state->m_tilemap[tm].m_tilemap_8x8;
869      if (tileregs&0x0200)    tilemap = m_tilemap[tm].m_tilemap_16x16;
870      else tilemap = m_tilemap[tm].m_tilemap_8x8;
895871   }
896872   else
897873   {
898      if (tileregs&0x0200)    tilemap = state->m_tilemap[tm].m_tilemap_16x16_alt;
899      else tilemap = state->m_tilemap[tm].m_tilemap_8x8; // _alt
874      if (tileregs&0x0200)    tilemap = m_tilemap[tm].m_tilemap_16x16_alt;
875      else tilemap = m_tilemap[tm].m_tilemap_8x8; // _alt
900876   }
901877
902878   // xrally's pink tilemaps make me think this is a tilemap enable bit.
r244675r244676
10511027            bitmap_ind16 &bm = tilemap->pixmap();
10521028            int bmheight = bm.height();
10531029            int bmwidth = bm.width();
1054            const pen_t *paldata = state->m_palette->pens();
1030            const pen_t *paldata = m_palette->pens();
10551031            UINT32* dstptr;
10561032            UINT16* srcptr;
10571033            int xx,yy;
r244675r244676
11471123            bitmap_ind16 &bm = tilemap->pixmap();
11481124            int bmheight = bm.height();
11491125            int bmwidth = bm.width();
1150            const pen_t *paldata = state->m_palette->pens();
1126            const pen_t *paldata = m_palette->pens();
11511127            UINT32* dstptr;
11521128            UINT16* srcptr;
11531129            int xx,yy;
r244675r244676
12931269      {
12941270         if (hng64_videoram[tile_index+(0x00000/4)]&0x200000)
12951271         {
1296            hng64_mark_tile_dirty(this, 0, tile_index);
1272            hng64_mark_tile_dirty(0, tile_index);
12971273         }
12981274         if (hng64_videoram[tile_index+(0x10000/4)]&0x200000)
12991275         {
1300            hng64_mark_tile_dirty(this, 1, tile_index);
1276            hng64_mark_tile_dirty(1, tile_index);
13011277         }
13021278         if (hng64_videoram[tile_index+(0x20000/4)]&0x200000)
13031279         {
1304            hng64_mark_tile_dirty(this, 2, tile_index);
1280            hng64_mark_tile_dirty(2, tile_index);
13051281         }
13061282         if (hng64_videoram[tile_index+(0x30000/4)]&0x200000)
13071283         {
1308            hng64_mark_tile_dirty(this, 3, tile_index);
1284            hng64_mark_tile_dirty(3, tile_index);
13091285         }
13101286      }
13111287
r244675r244676
13171293   {
13181294      if ((m_old_tileflags[i]&IMPORTANT_DIRTY_TILEFLAG_MASK)!=(tileflags[i]&IMPORTANT_DIRTY_TILEFLAG_MASK))
13191295      {
1320         hng64_mark_all_tiles_dirty(this, i);
1296         hng64_mark_all_tiles_dirty(i);
13211297         m_old_tileflags[i] = tileflags[i];
13221298      }
13231299   }
r244675r244676
13541330   draw_sprites(screen, bitmap,cliprect);
13551331
13561332   if(0)
1357      transition_control(machine(), bitmap, cliprect);
1333      transition_control(bitmap, cliprect);
13581334
13591335   if (0)
13601336      popmessage("%08x %08x %08x %08x %08x", m_spriteregs[0], m_spriteregs[1], m_spriteregs[2], m_spriteregs[3], m_spriteregs[4]);
r244675r244676
15281504static void vecmatmul4(float *product, const float *a, const float *b);
15291505static float vecDotProduct(const float *a, const float *b);
15301506static void normalize(float* x);
1531
15321507static void performFrustumClip(struct polygon *p);
1533static void drawShaded(running_machine &machine, struct polygon *p);
1534//static void plot(running_machine &machine, INT32 x, INT32 y, UINT32 color);
1535//static void drawline2d(running_machine &machine, INT32 x0, INT32 y0, INT32 x1, INT32 y1, UINT32 color);
1536//static void DrawWireframe(running_machine &machine, struct polygon *p);
1537
15381508static float uToF(UINT16 input);
15391509
15401510
r244675r244676
15721542
15731543// Operation 0001
15741544// Camera transformation.
1575static void setCameraTransformation(hng64_state *state, const UINT16* packet)
1545void hng64_state::setCameraTransformation(const UINT16* packet)
15761546{
1577   float *cameraMatrix = state->m_cameraMatrix;
1547   float *cameraMatrix = m_cameraMatrix;
15781548
15791549   /*//////////////
15801550   // PACKET FORMAT
r244675r244676
16191589
16201590// Operation 0010
16211591// Lighting information
1622static void setLighting(hng64_state *state, const UINT16* packet)
1592void hng64_state::setLighting(const UINT16* packet)
16231593{
1624   float *lightVector = state->m_lightVector;
1594   float *lightVector = m_lightVector;
16251595
16261596   /*//////////////
16271597   // PACKET FORMAT
r244675r244676
16481618   lightVector[0] = uToF(packet[3]);
16491619   lightVector[1] = uToF(packet[4]);
16501620   lightVector[2] = uToF(packet[5]);
1651   state->m_lightStrength = uToF(packet[9]);
1621   m_lightStrength = uToF(packet[9]);
16521622}
16531623
16541624// Operation 0011
16551625// Palette / Model flags?
1656static void set3dFlags(hng64_state *state, const UINT16* packet)
1626void hng64_state::set3dFlags(const UINT16* packet)
16571627{
16581628   /*//////////////
16591629   // PACKET FORMAT
r244675r244676
16741644   // [14] - ???? ... ? ''  ''
16751645   // [15] - ???? ... ? ''  ''
16761646   ////////////*/
1677   state->m_paletteState3d = (packet[8] & 0xff00) >> 8;
1647   m_paletteState3d = (packet[8] & 0xff00) >> 8;
16781648}
16791649
16801650// Operation 0012
16811651// Projection Matrix.
1682static void setCameraProjectionMatrix(hng64_state *state, const UINT16* packet)
1652void hng64_state::setCameraProjectionMatrix(const UINT16* packet)
16831653{
1684   float *projectionMatrix = state->m_projectionMatrix;
1654   float *projectionMatrix = m_projectionMatrix;
16851655
16861656   /*//////////////
16871657   // PACKET FORMAT
r244675r244676
17371707
17381708// Operation 0100
17391709// Polygon rasterization.
1740static void recoverPolygonBlock(running_machine& machine, const UINT16* packet, struct polygon* polys, int* numPolys)
1710void hng64_state::recoverPolygonBlock(const UINT16* packet, struct polygon* polys, int* numPolys)
17411711{
17421712   /*//////////////
17431713   // PACKET FORMAT
r244675r244676
17741744   // [15] - xxxx ... Transformation matrix
17751745   ////////////*/
17761746
1777   hng64_state *state = machine.driver_data<hng64_state>();
17781747   UINT32 size[4];
17791748   UINT32 address[4];
17801749   UINT32 megaOffset;
r244675r244676
17881757   setIdentity(objectMatrix);
17891758
17901759   struct polygon lastPoly = { 0 };
1791   const rectangle &visarea = machine.first_screen()->visible_area();
1760   const rectangle &visarea = m_screen->visible_area();
17921761
17931762   /////////////////
17941763   // HEADER INFO //
r244675r244676
18441813   //////////////////////////////////////////////*/
18451814
18461815   // 3d ROM Offset
1847   UINT16* threeDRoms = (UINT16*)(machine.root_device().memregion("verts")->base());
1816   UINT16* threeDRoms = (UINT16*)memregion("verts")->base();
18481817   UINT32  threeDOffset = (((UINT32)packet[2]) << 16) | ((UINT32)packet[3]);
18491818   UINT16* threeDPointer = &threeDRoms[threeDOffset * 3];
18501819
1851   if (threeDOffset >= machine.root_device().memregion("verts")->bytes())
1820   if (threeDOffset >= memregion("verts")->bytes())
18521821   {
18531822      printf("Strange geometry packet: (ignoring)\n");
18541823      printPacket(packet, 1);
r244675r244676
19731942         /* FIXME: This isn't correct.
19741943                   Buriki & Xrally need this line.  Roads Edge needs it removed.
19751944                   So instead we're looking for a bit that is on for XRally & Buriki, but noone else. */
1976         if (state->m_3dregs[0x00/4] & 0x2000)
1945         if (m_3dregs[0x00/4] & 0x2000)
19771946         {
1978            if (strcmp(machine.basename(), "roadedge"))
1947            if (strcmp(machine().basename(), "roadedge"))
19791948               polys[*numPolys].palOffset += 0x800;
19801949         }
19811950
r244675r244676
19891958         // Apply the dynamic palette offset if its flag is set, otherwise stick with the fixed one
19901959         if ((packet[1] & 0x0100))
19911960         {
1992            explicitPaletteValue1 = state->m_paletteState3d * 0x80;
1961            explicitPaletteValue1 = m_paletteState3d * 0x80;
19931962            explicitPaletteValue2 = 0;      // This is probably hiding somewhere in operation 0011
19941963         }
19951964
r244675r244676
21832152         ////////////////////////////////////
21842153         // Perform the world transformations...
21852154         // !! Can eliminate this step with a matrix stack (maybe necessary?) !!
2186         setIdentity(state->m_modelViewMatrix);
2187         if (state->m_mcu_type != SAMSHO_MCU)
2155         setIdentity(m_modelViewMatrix);
2156         if (m_mcu_type != SAMSHO_MCU)
21882157         {
21892158            // The sams64 games transform the geometry in front of a stationary camera.
21902159            // This is fine in sams64_2, since it never calls the 'camera transformation' function
21912160            // (thus using the identity matrix for this transform), but sams64 calls the
21922161            // camera transformation function with rotation values.
21932162            // It remains to be seen what those might do...
2194            matmul4(state->m_modelViewMatrix, state->m_modelViewMatrix, state->m_cameraMatrix);
2163            matmul4(m_modelViewMatrix, m_modelViewMatrix, m_cameraMatrix);
21952164         }
2196         matmul4(state->m_modelViewMatrix, state->m_modelViewMatrix, objectMatrix);
2165         matmul4(m_modelViewMatrix, m_modelViewMatrix, objectMatrix);
21972166
21982167         // LIGHTING
2199         if (packet[1] & 0x0008 && state->m_lightStrength > 0.0f)
2168         if (packet[1] & 0x0008 && m_lightStrength > 0.0f)
22002169         {
22012170            for (int v = 0; v < 3; v++)
22022171            {
22032172               float transformedNormal[4];
22042173               vecmatmul4(transformedNormal, objectMatrix, polys[*numPolys].vert[v].normal);
22052174               normalize(transformedNormal);
2206               normalize(state->m_lightVector);
2175               normalize(m_lightVector);
22072176
2208               float intensity = vecDotProduct(transformedNormal, state->m_lightVector) * -1.0f;
2177               float intensity = vecDotProduct(transformedNormal, m_lightVector) * -1.0f;
22092178               intensity = (intensity <= 0.0f) ? (0.0f) : (intensity);
2210               intensity *= state->m_lightStrength * 128.0f;    // Turns 0x0100 into 1.0
2179               intensity *= m_lightStrength * 128.0f;    // Turns 0x0100 into 1.0
22112180               intensity *= 128.0;                     // Maps intensity to the range [0.0, 2.0]
22122181               if (intensity >= 255.0f) intensity = 255.0f;
22132182
r244675r244676
22502219
22512220
22522221         // BEHIND-THE-CAMERA CULL //
2253         vecmatmul4(cullRay, state->m_modelViewMatrix, polys[*numPolys].vert[0].worldCoords);
2222         vecmatmul4(cullRay, m_modelViewMatrix, polys[*numPolys].vert[0].worldCoords);
22542223         if (cullRay[2] > 0.0f)              // Camera is pointing down -Z
22552224         {
22562225            polys[*numPolys].visible = 0;
r244675r244676
22632232            for (int m = 0; m < polys[*numPolys].n; m++)
22642233            {
22652234               // Transform and project the vertex into pre-divided homogeneous coordinates...
2266               vecmatmul4(eyeCoords, state->m_modelViewMatrix, polys[*numPolys].vert[m].worldCoords);
2267               vecmatmul4(polys[*numPolys].vert[m].clipCoords, state->m_projectionMatrix, eyeCoords);
2235               vecmatmul4(eyeCoords, m_modelViewMatrix, polys[*numPolys].vert[m].worldCoords);
2236               vecmatmul4(polys[*numPolys].vert[m].clipCoords, m_projectionMatrix, eyeCoords);
22682237            }
22692238
22702239            if (polys[*numPolys].visible)
r244675r244676
23042273   }
23052274}
23062275
2307void hng64_command3d(running_machine& machine, const UINT16* packet)
2276void hng64_state::hng64_command3d(const UINT16* packet)
23082277{
2309   hng64_state *state = machine.driver_data<hng64_state>();
23102278
23112279   /* A temporary place to put some polygons.  This will optimize away if the compiler's any good. */
23122280   int numPolys = 0;
23132281   dynamic_array<polygon> polys(1024*5);
23142282
2315   //printf("packet type : %04x %04x|%04x %04x|%04x %04x|%04x %04x\n", packet[0],packet[1],packet[2],packet[3],packet[4],packet[5],packet[6],packet[7]);
2283   //printf("packet type : %04x %04x|%04x %04x|%04x %04x|%04x %04x  | %04x %04x %04x %04x %04x %04x %04x %04x\n", packet[0],packet[1],packet[2],packet[3],packet[4],packet[5],packet[6],packet[7],     packet[8], packet[9], packet[10], packet[11], packet[12], packet[13], packet[14], packet[15]);
2284   
23162285   switch (packet[0])
23172286   {
23182287   case 0x0000:    // Appears to be a NOP.
23192288      break;
23202289
23212290   case 0x0001:    // Camera transformation.
2322      setCameraTransformation(state, packet);
2291      setCameraTransformation(packet);
23232292      break;
23242293
23252294   case 0x0010:    // Lighting information.
23262295      //if (packet[9]) printPacket(packet, 1);
2327      setLighting(state, packet);
2296      setLighting(packet);
23282297      break;
23292298
23302299   case 0x0011:    // Palette / Model flags?
23312300      //printPacket(packet, 1); printf("\n");
2332      set3dFlags(state, packet);
2301      set3dFlags(packet);
23332302      break;
23342303
23352304   case 0x0012:    // Projection Matrix
23362305      //printPacket(packet, 1);
2337      setCameraProjectionMatrix(state, packet);
2306      setCameraProjectionMatrix(packet);
23382307      break;
23392308
23402309   case 0x0100:
23412310   case 0x0101:    // Geometry with full transformations
23422311      // HACK.  Masks out a piece of geo bbust2's drawShaded() crashes on.
2343      if (packet[2] == 0x0003 && packet[3] == 0x8f37 && state->m_mcu_type == SHOOT_MCU)
2312      if (packet[2] == 0x0003 && packet[3] == 0x8f37 && m_mcu_type == SHOOT_MCU)
23442313         break;
23452314
2346      recoverPolygonBlock(machine, packet, polys, &numPolys);
2315      recoverPolygonBlock( packet, polys, &numPolys);
23472316      break;
23482317
23492318   case 0x0102:    // Geometry with only translation
r244675r244676
23632332      miniPacket[7] = 0x7fff;
23642333      miniPacket[11] = 0x7fff;
23652334      miniPacket[15] = 0x7fff;
2366      recoverPolygonBlock(machine, miniPacket, polys, &numPolys);
2335      recoverPolygonBlock( miniPacket, polys, &numPolys);
23672336
23682337      memset(miniPacket, 0, sizeof(UINT16)*16);
23692338      for (int i = 0; i < 7; i++) miniPacket[i] = packet[i+8];
2339      for (int i = 0; i < 7; i++) miniPacket[i] = packet[i+8];
23702340      miniPacket[7] = 0x7fff;
23712341      miniPacket[11] = 0x7fff;
23722342      miniPacket[15] = 0x7fff;
2373      recoverPolygonBlock(machine, miniPacket, polys, &numPolys);
2343      recoverPolygonBlock( miniPacket, polys, &numPolys);
23742344      break;
23752345
23762346   case 0x1000:    // Unknown: Some sort of global flags?
r244675r244676
23912361   {
23922362      if (polys[i].visible)
23932363      {
2394         //DrawWireframe(machine, &polys[i]);
2395         drawShaded(machine, &polys[i]);
2364         //DrawWireframe( &polys[i]);
2365         drawShaded( &polys[i]);
23962366      }
23972367   }
23982368}
r244675r244676
26782648// wireframe rendering //
26792649/////////////////////////
26802650#ifdef UNUSED_FUNCTION
2681static void plot(running_machine &machine, INT32 x, INT32 y, UINT32 color)
2651static void plot( INT32 x, INT32 y, UINT32 color)
26822652{
26832653   UINT32* cb = &(colorBuffer3d[(y * machine.first_screen()->visible_area().max_x) + x]);
26842654   *cb = color;
26852655}
26862656
26872657// Stolen from http://en.wikipedia.org/wiki/Bresenham's_line_algorithm (no copyright denoted) - the non-optimized version
2688static void drawline2d(running_machine &machine, INT32 x0, INT32 y0, INT32 x1, INT32 y1, UINT32 color)
2658static void drawline2d( INT32 x0, INT32 y0, INT32 x1, INT32 y1, UINT32 color)
26892659{
26902660#define SWAP(a,b) tmpswap = a; a = b; b = tmpswap;
26912661
r244675r244676
27232693   {
27242694      if (steep)
27252695      {
2726         plot(machine, x0, y0, color);
2696         plot( x0, y0, color);
27272697      }
27282698      else
27292699      {
2730         plot(machine, y0, x0, color);
2700         plot( y0, x0, color);
27312701      }
27322702      while (e >= 0)
27332703      {
r244675r244676
27412711#undef SWAP
27422712}
27432713
2744static void DrawWireframe(running_machine &machine, struct polygon *p)
2714static void DrawWireframe( struct polygon *p)
27452715{
27462716   int j;
27472717   for (j = 0; j < p->n; j++)
r244675r244676
27492719      // osd_printf_debug("now drawing : %f %f %f, %f %f %f\n", p->vert[j].clipCoords[0], p->vert[j].clipCoords[1], p->vert[j].clipCoords[2], p->vert[(j+1)%p->n].clipCoords[0], p->vert[(j+1)%p->n].clipCoords[1], p->vert[(j+1)%p->n].clipCoords[2]);
27502720      // osd_printf_debug("%f %f %f %f\n", p->vert[j].clipCoords[0], p->vert[j].clipCoords[1], p->vert[(j+1)%p->n].clipCoords[0], p->vert[(j+1)%p->n].clipCoords[1]);
27512721      UINT32 color = rgb_t((UINT8)255, (UINT8)255, (UINT8)0, (UINT8)0);
2752      drawline2d(machine, p->vert[j].clipCoords[0], p->vert[j].clipCoords[1], p->vert[(j+1)%p->n].clipCoords[0], p->vert[(j+1)%p->n].clipCoords[1], color);
2722      drawline2d( p->vert[j].clipCoords[0], p->vert[j].clipCoords[1], p->vert[(j+1)%p->n].clipCoords[0], p->vert[(j+1)%p->n].clipCoords[1], color);
27532723   }
27542724
27552725   // SHOWS THE CLIPPING //
r244675r244676
27642734}
27652735#endif
27662736
2767///////////////////////
2768// polygon rendering //
2769///////////////////////
27702737
2771struct polygonRasterOptions
2772{
2773   UINT8 texType;
2774   UINT8 texIndex;
2775   UINT8 texPageSmall;
2776   UINT8 texPageHorizOffset;
2777   UINT8 texPageVertOffset;
2778   int palOffset;
2779   int palPageSize;
2780   int debugColor;
2781};
2782
27832738/*********************************************************************/
27842739/**   FillSmoothTexPCHorizontalLine                                 **/
27852740/**     Input: Color Buffer (framebuffer), depth buffer, width and  **/
r244675r244676
27892744/**                                                                 **/
27902745/**     Output: none                                                **/
27912746/*********************************************************************/
2792INLINE void FillSmoothTexPCHorizontalLine(running_machine &machine,
2747inline void hng64_state::FillSmoothTexPCHorizontalLine(
27932748                                 const polygonRasterOptions& prOptions,
27942749                                 int x_start, int x_end, int y, float z_start, float z_delta,
27952750                                 float w_start, float w_delta, float r_start, float r_delta,
27962751                                 float g_start, float g_delta, float b_start, float b_delta,
27972752                                 float s_start, float s_delta, float t_start, float t_delta)
27982753{
2799   hng64_state *state = machine.driver_data<hng64_state>();
2800   float*  db = &(state->m_depthBuffer3d[(y * machine.first_screen()->visible_area().max_x) + x_start]);
2801   UINT32* cb = &(state->m_colorBuffer3d[(y * machine.first_screen()->visible_area().max_x) + x_start]);
2754   float*  db = &(m_depthBuffer3d[(y * m_screen->visible_area().max_x) + x_start]);
2755   UINT32* cb = &(m_colorBuffer3d[(y * m_screen->visible_area().max_x) + x_start]);
28022756
28032757   UINT8 paletteEntry = 0;
28042758   float t_coord, s_coord;
2805   const UINT8 *gfx = state->memregion("textures")->base();
2759   const UINT8 *gfx = memregion("textures")->base();
28062760   const UINT8 *textureOffset = &gfx[prOptions.texIndex * 1024 * 1024];
28072761
28082762   for (; x_start <= x_end; x_start++)
r244675r244676
28642818            {
28652819               // The color out of the texture
28662820               paletteEntry %= prOptions.palPageSize;
2867               rgb_t color = state->m_palette->pen(prOptions.palOffset + paletteEntry);
2821               rgb_t color = m_palette->pen(prOptions.palOffset + paletteEntry);
28682822
28692823               // Apply the lighting
28702824               float rIntensity = (r_start/w_start) / 255.0f;
r244675r244676
29322886//   nearest and bilinear filtering: Filtering={0,1}
29332887//   replace and modulate application modes: Function={0,1}
29342888//---------------------------------------------------------------------------
2935static void RasterizeTriangle_SMOOTH_TEX_PC(running_machine &machine,
2889void hng64_state::RasterizeTriangle_SMOOTH_TEX_PC(
29362890                                 float A[4], float B[4], float C[4],
29372891                                 float Ca[3], float Cb[3], float Cc[3], // PER-VERTEX RGB COLORS
29382892                                 float Ta[2], float Tb[2], float Tc[2], // PER-VERTEX (S,T) TEX-COORDS
r244675r244676
31263080
31273081      // Pass the horizontal line to the filler, this could be put in the routine
31283082      // then interpolate for the next values of x and z
3129      FillSmoothTexPCHorizontalLine(machine, prOptions,
3083      FillSmoothTexPCHorizontalLine( prOptions,
31303084         x_start, x_end, y_min, z_interp_x, z_delta_x, w_interp_x, w_delta_x,
31313085         r_interp_x, r_delta_x, g_interp_x, g_delta_x, b_interp_x, b_delta_x,
31323086         s_interp_x, s_delta_x, t_interp_x, t_delta_x);
r244675r244676
32053159
32063160      // Pass the horizontal line to the filler, this could be put in the routine
32073161      // then interpolate for the next values of x and z
3208      FillSmoothTexPCHorizontalLine(machine, prOptions,
3162      FillSmoothTexPCHorizontalLine( prOptions,
32093163         x_start, x_end, y_mid, z_interp_x, z_delta_x, w_interp_x, w_delta_x,
32103164         r_interp_x, r_delta_x, g_interp_x, g_delta_x, b_interp_x, b_delta_x,
32113165         s_interp_x, s_delta_x, t_interp_x, t_delta_x);
r244675r244676
32203174   }
32213175}
32223176
3223static void drawShaded(running_machine &machine, struct polygon *p)
3177void hng64_state::drawShaded( struct polygon *p)
32243178{
32253179   // The perspective-correct texture divide...
32263180   // !!! There is a very good chance the HNG64 hardware does not do perspective-correct texture-mapping !!!
r244675r244676
32483202
32493203   for (j = 1; j < p->n-1; j++)
32503204   {
3251      RasterizeTriangle_SMOOTH_TEX_PC(machine,
3205      RasterizeTriangle_SMOOTH_TEX_PC(
32523206                              p->vert[0].clipCoords, p->vert[j].clipCoords, p->vert[j+1].clipCoords,
32533207                              p->vert[0].light,      p->vert[j].light,      p->vert[j+1].light,
32543208                              p->vert[0].texCoords,  p->vert[j].texCoords,  p->vert[j+1].texCoords,


Previous 199869 Revisions Next


© 1997-2024 The MAME Team