From d1b0f47a4893883baeb6ebeeb096d0ae04ed9d78 Mon Sep 17 00:00:00 2001 From: Angelo Salese Date: Wed, 11 Nov 2009 17:45:53 +0000 Subject: [PATCH] (There are a bunch of things that I want to check on it, I'll do them after a clean compile...) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -----Messaggio originale----- Da: David Haywood [mailto:neohaze@nildram.co.uk] Inviato: mercoledì 11 novembre 2009 13.38 Cc: Angelo Salese Oggetto: Re: Slam Dunk 2 Improved video offsets for these games (they're not perfect, I think in reality they depend on layers enabled etc. but they're much improved) apply after previous. David Haywood wrote: > with this I think you can mark it as working > > - added a workaround for it not enabling the display (tied to the > type4/rushing heroes hack we already have) > - fixed rom loading for other sets (also swapped the data roms on > vsnet around so that the load positions match up with the working > games) > - moved most of machine/konamigx.c to video/konamigx.c (mixer code > etc.) left the protection related code in machine/konamigx.c > > note, you'll need to DELETE machine/konamigx.h from svn and ADD > includes/konamigx.h to it. > --- .gitattributes | 2 +- src/mame/drivers/konamigq.c | 2 +- src/mame/drivers/konamigx.c | 52 +- src/mame/drivers/mystwarr.c | 2 +- src/mame/{machine => includes}/konamigx.h | 6 +- src/mame/machine/konamigx.c | 1725 +------------------- src/mame/video/bishi.c | 2 +- src/mame/video/konamigx.c | 1772 ++++++++++++++++++++- src/mame/video/mystwarr.c | 2 +- 9 files changed, 1800 insertions(+), 1765 deletions(-) rename src/mame/{machine => includes}/konamigx.h (98%) diff --git a/.gitattributes b/.gitattributes index 397e02d92c7..fd42817456d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2432,6 +2432,7 @@ src/mame/includes/jpmimpct.h svneol=native#text/plain src/mame/includes/kaneko16.h svneol=native#text/plain src/mame/includes/kangaroo.h svneol=native#text/plain src/mame/includes/klax.h svneol=native#text/plain +src/mame/includes/konamigx.h svneol=native#text/plain src/mame/includes/konamipt.h svneol=native#text/plain src/mame/includes/kyugo.h svneol=native#text/plain src/mame/includes/lasso.h svneol=native#text/plain @@ -2805,7 +2806,6 @@ src/mame/machine/kanekotb.h svneol=native#text/plain src/mame/machine/konami1.c svneol=native#text/plain src/mame/machine/konami1.h svneol=native#text/plain src/mame/machine/konamigx.c svneol=native#text/plain -src/mame/machine/konamigx.h svneol=native#text/plain src/mame/machine/konamiic.c svneol=native#text/plain src/mame/machine/konamiic.h svneol=native#text/plain src/mame/machine/konppc.c svneol=native#text/plain diff --git a/src/mame/drivers/konamigq.c b/src/mame/drivers/konamigq.c index 4e9bb56d4ce..c88287cb55a 100644 --- a/src/mame/drivers/konamigq.c +++ b/src/mame/drivers/konamigq.c @@ -49,7 +49,7 @@ #include "cpu/m68000/m68000.h" #include "cpu/mips/psx.h" #include "includes/psx.h" -#include "machine/konamigx.h" +#include "konamigx.h" #include "machine/eeprom.h" #include "machine/am53cf96.h" #include "harddisk.h" diff --git a/src/mame/drivers/konamigx.c b/src/mame/drivers/konamigx.c index 571521fb35b..4bb1586ada1 100644 --- a/src/mame/drivers/konamigx.c +++ b/src/mame/drivers/konamigx.c @@ -103,7 +103,7 @@ #include "cpu/tms57002/tms57002.h" #include "machine/eeprom.h" #include "sound/k054539.h" -#include "machine/konamigx.h" +#include "konamigx.h" #include "machine/adc083x.h" #define GX_DEBUG 0 @@ -113,6 +113,7 @@ VIDEO_START(konamigx_6bpp); VIDEO_START(konamigx_6bpp_2); VIDEO_START(konamigx_type3); VIDEO_START(konamigx_type4); +VIDEO_START(konamigx_type4_sd2); VIDEO_START(le2); VIDEO_START(dragoonj); VIDEO_START(winspike); @@ -1600,6 +1601,13 @@ static MACHINE_DRIVER_START( gxtype4vsnet ) MDRV_SCREEN_VISIBLE_AREA(0, 576-1, 16, 32*8-1-16) MACHINE_DRIVER_END +static MACHINE_DRIVER_START( gxtype4sd2 ) + MDRV_IMPORT_FROM(gxtype4) + + MDRV_VIDEO_START(konamigx_type4_sd2) +MACHINE_DRIVER_END + + static MACHINE_DRIVER_START( winspike ) MDRV_IMPORT_FROM(konamigx) @@ -2196,8 +2204,8 @@ ROM_START( rungun2 ) /* main program */ ROM_REGION( 0x800000, "maincpu", 0 ) GX_BIOS - ROM_LOAD32_WORD_SWAP( "505uaa02.31b", 0x200002, 512*1024, CRC(cfca23f7) SHA1(dfea871f0aaf6b2db6d924ddfd4174e7a14333e8)) ROM_LOAD32_WORD_SWAP( "505uaa03.27b", 0x200000, 512*1024, CRC(ad7f9ded) SHA1(824448daeb6109b822667e54baa1c73484642ac9)) + ROM_LOAD32_WORD_SWAP( "505uaa02.31b", 0x200002, 512*1024, CRC(cfca23f7) SHA1(dfea871f0aaf6b2db6d924ddfd4174e7a14333e8)) /* data roms */ ROM_LOAD32_WORD_SWAP( "505a05.29r", 0x400000, 1024*1024, CRC(5da5d695) SHA1(02bfbfa4ba0213a23819828a9be02923740dccd6) ) @@ -2218,12 +2226,12 @@ ROM_START( rungun2 ) _48_WORD_ROM_LOAD( "505a19.14r", 0x0000000, 2*1024*1024, CRC(ffde4f17) SHA1(df93853f7bd3c775a15836b0ca9042f75eb65630) ) _48_WORD_ROM_LOAD( "505a15.18r", 0x0000002, 2*1024*1024, CRC(d9ab1e6c) SHA1(748a61d939bd335c1b50f440e819303552b3d5a1) ) _48_WORD_ROM_LOAD( "505a11.23r", 0x0000004, 2*1024*1024, CRC(75c13df0) SHA1(6680f75a67ca510fac29b65bce32fef64e844695) ) - _48_WORD_ROM_LOAD( "505a18.18m", 0x0600000, 2*1024*1024, CRC(c12bacfe) SHA1(5b5f4dd9a51c7a305dd4de1354cd1df2ce75c932) ) - _48_WORD_ROM_LOAD( "505a14.14m", 0x0600002, 2*1024*1024, CRC(356a75b0) SHA1(5f8b7a9d06d4207f19ed0f7c89513226488afde1) ) - _48_WORD_ROM_LOAD( "505a10.23m", 0x0600004, 2*1024*1024, CRC(fc315ee0) SHA1(4dab661e0bd8e5386e52d514a1511ceba6e5b7bd) ) - _48_WORD_ROM_LOAD( "505a17.16r", 0x0c00000, 2*1024*1024, CRC(8176f2f5) SHA1(d7944314b35bcd5301bbfba8a5b1ed6b35b9b888) ) - _48_WORD_ROM_LOAD( "505a13.21r", 0x0c00002, 2*1024*1024, CRC(e60c5191) SHA1(02a8af81682838800489aa1123a453045d70acd8) ) - _48_WORD_ROM_LOAD( "505a09.25r", 0x0c00004, 2*1024*1024, CRC(3e1d5a15) SHA1(ec4d46c2f2cc57e6193865357ffb3d62a9eecd4f) ) + _48_WORD_ROM_LOAD( "505a17.16r", 0x0600000, 2*1024*1024, CRC(8176f2f5) SHA1(d7944314b35bcd5301bbfba8a5b1ed6b35b9b888) ) + _48_WORD_ROM_LOAD( "505a13.21r", 0x0600002, 2*1024*1024, CRC(e60c5191) SHA1(02a8af81682838800489aa1123a453045d70acd8) ) + _48_WORD_ROM_LOAD( "505a09.25r", 0x0600004, 2*1024*1024, CRC(3e1d5a15) SHA1(ec4d46c2f2cc57e6193865357ffb3d62a9eecd4f) ) + _48_WORD_ROM_LOAD( "505a18.18m", 0x0c00000, 2*1024*1024, CRC(c12bacfe) SHA1(5b5f4dd9a51c7a305dd4de1354cd1df2ce75c932) ) + _48_WORD_ROM_LOAD( "505a14.14m", 0x0c00002, 2*1024*1024, CRC(356a75b0) SHA1(5f8b7a9d06d4207f19ed0f7c89513226488afde1) ) + _48_WORD_ROM_LOAD( "505a10.23m", 0x0c00004, 2*1024*1024, CRC(fc315ee0) SHA1(4dab661e0bd8e5386e52d514a1511ceba6e5b7bd) ) _48_WORD_ROM_LOAD( "505a16.16m", 0x1200000, 2*1024*1024, CRC(ca9c2193) SHA1(cc3fb558b834e0b7914879ab47c3750170d257f4) ) _48_WORD_ROM_LOAD( "505a12.21m", 0x1200002, 2*1024*1024, CRC(421d5034) SHA1(f7a85b7e41f3ddf9ddbdc6f8b6d3dbf8ba40d61b) ) _48_WORD_ROM_LOAD( "505a08.25m", 0x1200004, 2*1024*1024, CRC(442ed3ec) SHA1(d44e1c4e9f8c63a8f754f8d20064cec15ae0b6d6) ) @@ -2243,8 +2251,8 @@ ROM_START( slamdnk2 ) /* main program */ ROM_REGION( 0x800000, "maincpu", 0 ) GX_BIOS - ROM_LOAD32_WORD_SWAP( "505jaa02.31m", 0x200002, 512*1024, CRC(9f72d48e) SHA1(6dd0520d0f0312e46f21ad4f6c41e47f3b5cb16b) ) ROM_LOAD32_WORD_SWAP( "505jaa03.29m", 0x200000, 512*1024, CRC(52513794) SHA1(8a8fadb0eb582db53163620982dd53d1e5f8ca4c) ) + ROM_LOAD32_WORD_SWAP( "505jaa02.31m", 0x200002, 512*1024, CRC(9f72d48e) SHA1(6dd0520d0f0312e46f21ad4f6c41e47f3b5cb16b) ) /* data roms */ ROM_LOAD32_WORD_SWAP( "505a05.29r", 0x400000, 1024*1024, CRC(5da5d695) SHA1(02bfbfa4ba0213a23819828a9be02923740dccd6) ) @@ -2291,8 +2299,8 @@ ROM_START( rushhero ) /* main program */ ROM_REGION( 0x800000, "maincpu", 0 ) GX_BIOS - ROM_LOAD32_WORD_SWAP( "605b02.31m", 0x200002, 512*1024, CRC(94c3d835) SHA1(f48d34987fa6575a2c41d3ca3359e9e2cbc817e0) ) ROM_LOAD32_WORD_SWAP( "605b03.29m", 0x200000, 512*1024, CRC(c5b8d31d) SHA1(6c5b359e1fcf511c50d6a876946631fc38a6dade) ) + ROM_LOAD32_WORD_SWAP( "605b02.31m", 0x200002, 512*1024, CRC(94c3d835) SHA1(f48d34987fa6575a2c41d3ca3359e9e2cbc817e0) ) /* data roms */ ROM_LOAD32_WORD_SWAP( "605a05.29r", 0x400000, 1024*1024, CRC(9bca4297) SHA1(c20be1ffcee8bd56f69d4fcc19d0035b3f74b8f2)) @@ -2789,8 +2797,8 @@ ROM_START( vsnetscr ) ROM_LOAD32_WORD_SWAP( "627ead02.31m", 0x200002, 0x080000, CRC(01ab336a) SHA1(6e7ab03a82548cc5bd17938df0baf47381dd86aa) ) /* data roms */ - ROM_LOAD32_WORD_SWAP( "627a05.31r", 0x400000, 1024*1024, CRC(be4e7b3c) SHA1(f44e7b1913aa54f759bd31bb86fdedbb9747b2d5) ) - ROM_LOAD32_WORD_SWAP( "627a04.29r", 0x400002, 1024*1024, CRC(17334e9a) SHA1(82cdba016c29160550c43feee7a4feff6e1184aa) ) + ROM_LOAD32_WORD_SWAP( "627a04.29r", 0x400000, 1024*1024, CRC(17334e9a) SHA1(82cdba016c29160550c43feee7a4feff6e1184aa) ) + ROM_LOAD32_WORD_SWAP( "627a05.31r", 0x400002, 1024*1024, CRC(be4e7b3c) SHA1(f44e7b1913aa54f759bd31bb86fdedbb9747b2d5) ) /* sound program */ ROM_REGION( 0x40000, "soundcpu", 0 ) @@ -2829,8 +2837,8 @@ ROM_START( vsnetscreb ) ROM_LOAD32_WORD_SWAP( "627eab02.31m", 0x200002, 0x080000, CRC(cc76bce8) SHA1(54a4047412a98a5c4f64a8bc2fd3cda9c07e58b3) ) /* data roms */ - ROM_LOAD32_WORD_SWAP( "627a05.31r", 0x400000, 1024*1024, CRC(be4e7b3c) SHA1(f44e7b1913aa54f759bd31bb86fdedbb9747b2d5) ) - ROM_LOAD32_WORD_SWAP( "627a04.29r", 0x400002, 1024*1024, CRC(17334e9a) SHA1(82cdba016c29160550c43feee7a4feff6e1184aa) ) + ROM_LOAD32_WORD_SWAP( "627a04.29r", 0x400000, 1024*1024, CRC(17334e9a) SHA1(82cdba016c29160550c43feee7a4feff6e1184aa) ) + ROM_LOAD32_WORD_SWAP( "627a05.31r", 0x400002, 1024*1024, CRC(be4e7b3c) SHA1(f44e7b1913aa54f759bd31bb86fdedbb9747b2d5) ) /* sound program */ ROM_REGION( 0x40000, "soundcpu", 0 ) @@ -2869,8 +2877,8 @@ ROM_START( vsnetscru ) ROM_LOAD32_WORD_SWAP( "627uab02.31m", 0x200002, 512*1024, CRC(c352cc6f) SHA1(d8d0d802eb6bd0910e35dcc6b81b7ac9036e32ea) ) /* data roms */ - ROM_LOAD32_WORD_SWAP( "627a05.31r", 0x400000, 1024*1024, CRC(be4e7b3c) SHA1(f44e7b1913aa54f759bd31bb86fdedbb9747b2d5) ) - ROM_LOAD32_WORD_SWAP( "627a04.29r", 0x400002, 1024*1024, CRC(17334e9a) SHA1(82cdba016c29160550c43feee7a4feff6e1184aa) ) + ROM_LOAD32_WORD_SWAP( "627a04.29r", 0x400000, 1024*1024, CRC(17334e9a) SHA1(82cdba016c29160550c43feee7a4feff6e1184aa) ) + ROM_LOAD32_WORD_SWAP( "627a05.31r", 0x400002, 1024*1024, CRC(be4e7b3c) SHA1(f44e7b1913aa54f759bd31bb86fdedbb9747b2d5) ) /* sound program */ ROM_REGION( 0x40000, "soundcpu", 0 ) @@ -3035,8 +3043,8 @@ ROM_START( vsnetscrj ) ROM_LOAD32_WORD_SWAP( "627jab02.31m", 0x200002, 512*1024, CRC(f10929d7) SHA1(304001d44ed762682a4606a849305a9352e9bec3) ) /* data roms */ - ROM_LOAD32_WORD_SWAP( "627a05.31r", 0x400000, 1024*1024, CRC(be4e7b3c) SHA1(f44e7b1913aa54f759bd31bb86fdedbb9747b2d5) ) - ROM_LOAD32_WORD_SWAP( "627a04.29r", 0x400002, 1024*1024, CRC(17334e9a) SHA1(82cdba016c29160550c43feee7a4feff6e1184aa) ) + ROM_LOAD32_WORD_SWAP( "627a04.29r", 0x400000, 1024*1024, CRC(17334e9a) SHA1(82cdba016c29160550c43feee7a4feff6e1184aa) ) + ROM_LOAD32_WORD_SWAP( "627a05.31r", 0x400002, 1024*1024, CRC(be4e7b3c) SHA1(f44e7b1913aa54f759bd31bb86fdedbb9747b2d5) ) /* sound program */ ROM_REGION( 0x40000, "soundcpu", 0 ) @@ -3075,8 +3083,8 @@ ROM_START( vsnetscra ) ROM_LOAD32_WORD_SWAP( "627aaa02.31m", 0x200002, 0x080000, CRC(e3d21afe) SHA1(28c213106087da425f85bb7f3398aca98964ea38) ) /* data roms */ - ROM_LOAD32_WORD_SWAP( "627a05.31r", 0x400000, 1024*1024, CRC(be4e7b3c) SHA1(f44e7b1913aa54f759bd31bb86fdedbb9747b2d5) ) - ROM_LOAD32_WORD_SWAP( "627a04.29r", 0x400002, 1024*1024, CRC(17334e9a) SHA1(82cdba016c29160550c43feee7a4feff6e1184aa) ) + ROM_LOAD32_WORD_SWAP( "627a04.29r", 0x400000, 1024*1024, CRC(17334e9a) SHA1(82cdba016c29160550c43feee7a4feff6e1184aa) ) + ROM_LOAD32_WORD_SWAP( "627a05.31r", 0x400002, 1024*1024, CRC(be4e7b3c) SHA1(f44e7b1913aa54f759bd31bb86fdedbb9747b2d5) ) /* sound program */ ROM_REGION( 0x40000, "soundcpu", 0 ) @@ -3746,6 +3754,6 @@ GAME( 1996, vsnetscreb,vsnetscr, gxtype4vsnet, type3, konamigx, ROT0, "Konami", GAME( 1996, vsnetscru, vsnetscr, gxtype4vsnet, type3, konamigx, ROT0, "Konami", "Versus Net Soccer (ver UAB)", GAME_NOT_WORKING|GAME_UNEMULATED_PROTECTION ) GAME( 1996, vsnetscra, vsnetscr, gxtype4vsnet, type3, konamigx, ROT0, "Konami", "Versus Net Soccer (ver AAA)", GAME_NOT_WORKING|GAME_UNEMULATED_PROTECTION ) GAME( 1996, vsnetscrj, vsnetscr, gxtype4vsnet, type3, konamigx, ROT0, "Konami", "Versus Net Soccer (ver JAB)", GAME_NOT_WORKING|GAME_UNEMULATED_PROTECTION ) -GAME( 1996, rungun2, konamigx, gxtype4, type3, konamigx, ROT0, "Konami", "Run and Gun 2 (ver UAA)", GAME_NOT_WORKING|GAME_UNEMULATED_PROTECTION ) -GAME( 1996, slamdnk2, rungun2, gxtype4, type3, konamigx, ROT0, "Konami", "Slam Dunk 2 (ver JAA)", GAME_NOT_WORKING|GAME_UNEMULATED_PROTECTION ) +GAME( 1996, rungun2, konamigx, gxtype4sd2, type3, konamigx, ROT0, "Konami", "Run and Gun 2 (ver UAA)", GAME_NOT_WORKING|GAME_UNEMULATED_PROTECTION ) +GAME( 1996, slamdnk2, rungun2, gxtype4sd2, type3, konamigx, ROT0, "Konami", "Slam Dunk 2 (ver JAA)", GAME_IMPERFECT_GRAPHICS ) GAME( 1996, rushhero, konamigx, gxtype4, type3, konamigx, ROT0, "Konami", "Rushing Heroes (ver UAB)", GAME_IMPERFECT_GRAPHICS ) diff --git a/src/mame/drivers/mystwarr.c b/src/mame/drivers/mystwarr.c index 1fe350f049d..c6796ceb4bc 100644 --- a/src/mame/drivers/mystwarr.c +++ b/src/mame/drivers/mystwarr.c @@ -25,7 +25,7 @@ #include "deprecat.h" #include "video/konamiic.h" -#include "machine/konamigx.h" +#include "konamigx.h" #include "cpu/m68000/m68000.h" #include "cpu/z80/z80.h" #include "machine/eeprom.h" diff --git a/src/mame/machine/konamigx.h b/src/mame/includes/konamigx.h similarity index 98% rename from src/mame/machine/konamigx.h rename to src/mame/includes/konamigx.h index b71d7e8e42a..c20f565725e 100644 --- a/src/mame/machine/konamigx.h +++ b/src/mame/includes/konamigx.h @@ -1,5 +1,3 @@ -#ifndef __MACH_KONAMIGX_H -#define __MACH_KONAMIGX_H // 2nd-Tier GX/MW Hardware Functions void K053247GP_set_SpriteOffset(int offsx, int offsy); @@ -80,7 +78,6 @@ void konamigx_mixer_primode(int mode); void konamigx_objdma(void); - // K055550/K053990/ESC protection devices handlers READ16_HANDLER ( K055550_word_r ); WRITE16_HANDLER( K055550_word_w ); @@ -90,4 +87,5 @@ void konamigx_esc_alert(UINT32 *srcbase, int srcoffs, int count, int mode); void fantjour_dma_install(running_machine *machine); WRITE32_HANDLER(fantjour_dma_w); -#endif +extern UINT16 *K053247_ram; + diff --git a/src/mame/machine/konamigx.c b/src/mame/machine/konamigx.c index 7b918dfe5e2..8d75ee9bbb6 100644 --- a/src/mame/machine/konamigx.c +++ b/src/mame/machine/konamigx.c @@ -6,1730 +6,7 @@ #include "driver.h" #include "video/konamiic.h" -#include "machine/konamigx.h" - -#define GX_DEBUG 0 - -/***************************************************************************/ -/* */ -/* 2nd-Tier GX/MW Graphics Functions */ -/* */ -/***************************************************************************/ - -#if GX_DEBUG - #define GX_ZBUFW 512 - #define GX_ZBUFH 384 - #define GX_ZPAGESIZE 0x300000 - #define GX_ZBUFSIZE 0x600000 -#else - #define GX_ZBUFW 576 - #define GX_ZBUFH 224 - #define GX_ZPAGESIZE (GX_ZBUFW*GX_ZBUFH) - #define GX_ZBUFSIZE ((GX_ZBUFW*GX_ZBUFH)*2) -#endif - -static UINT8 *gx_objzbuf, *gx_shdzbuf; - - -// Localized K053936/ROZ+ -#define K053936_MAX_CHIPS 2 - -static rectangle K053936_cliprect[K053936_MAX_CHIPS] = {{0,0,0,0},{0,0,0,0}}; -static int K053936_offset[K053936_MAX_CHIPS][2] = {{0,0},{0,0}}; -static int K053936_clip_enabled[K053936_MAX_CHIPS] = {0,0}; - - -void K053936GP_set_offset(int chip, int xoffs, int yoffs) { K053936_offset[chip][0] = xoffs; K053936_offset[chip][1] = yoffs; } - -void K053936GP_clip_enable(int chip, int status) { K053936_clip_enabled[chip] = status; } - -void K053936GP_set_cliprect(int chip, int minx, int maxx, int miny, int maxy) -{ - rectangle *cliprect = &K053936_cliprect[chip]; - cliprect->min_x = minx; - cliprect->max_x = maxx; - cliprect->min_y = miny; - cliprect->max_y = maxy; -} - -INLINE void K053936GP_copyroz32clip( running_machine *machine, - bitmap_t *dst_bitmap, bitmap_t *src_bitmap, - const rectangle *dst_cliprect, const rectangle *src_cliprect, - UINT32 _startx,UINT32 _starty,int _incxx,int _incxy,int _incyx,int _incyy, - int tilebpp, int blend, int alpha, int clip ) -{ - static const int colormask[8]={1,3,7,0xf,0x1f,0x3f,0x7f,0xff}; - - int cy, cx; - int ecx; - int src_pitch, incxy, incxx; - int src_minx, src_maxx, src_miny, src_maxy, cmask; - UINT16 *src_base; - size_t src_size; - - const pen_t *pal_base; - UINT32 *dst_ptr; - - int tx, dst_pitch; - UINT32 *dst_base; - int starty, incyy, startx, incyx, ty, sx, sy; - - incxy = _incxy; incxx = _incxx; incyy = _incyy; incyx = _incyx; - starty = _starty; startx = _startx; - - if (src_cliprect && clip) // set source clip range to some extreme values when disabled - { - src_minx = src_cliprect->min_x; - src_maxx = src_cliprect->max_x; - src_miny = src_cliprect->min_y; - src_maxy = src_cliprect->max_y; - } - // this simply isn't safe to do! - else { src_minx = src_miny = -0x10000; src_maxx = src_maxy = 0x10000; } - - if (dst_cliprect) // set target clip range - { - sx = dst_cliprect->min_x; - tx = dst_cliprect->max_x - sx + 1; - sy = dst_cliprect->min_y; - ty = dst_cliprect->max_y - sy + 1; - - startx += sx * incxx + sy * incyx; - starty += sx * incxy + sy * incyy; - } - else { sx = sy = 0; tx = dst_bitmap->width; ty = dst_bitmap->height; } - - // adjust entry points and other loop constants - dst_pitch = dst_bitmap->rowpixels; - dst_base = (UINT32*)dst_bitmap->base + sy * dst_pitch + sx + tx; - ecx = tx = -tx; - - tilebpp = (tilebpp-1) & 7; - pal_base = machine->pens; - cmask = colormask[tilebpp]; - - src_pitch = src_bitmap->rowpixels; - src_base = (UINT16 *)src_bitmap->base; - src_size = src_bitmap->width * src_bitmap->height; - - dst_ptr = dst_base; - cy = starty; - cx = startx; - - if (blend > 0) - { - dst_base += dst_pitch; // draw blended - starty += incyy; - startx += incyx; - - do { - do { - int srcx = (cx >> 16) & 0x1fff; - int srcy = (cy >> 16) & 0x1fff; - int pixel; - UINT32 offs; - offs = srcy * src_pitch + srcx; - - cx += incxx; - cy += incxy; - - if (offs<0 || offs>=src_size) - continue; - - if (srcx < src_minx || srcx > src_maxx || srcy < src_miny || srcy > src_maxy) - continue; - - pixel = src_base[offs]; - if (!(pixel & cmask)) - continue; - - dst_ptr[ecx] = alpha_blend_r32(pal_base[pixel], dst_ptr[ecx], alpha); - } - while (++ecx); - - ecx = tx; - dst_ptr = dst_base; dst_base += dst_pitch; - cy = starty; starty += incyy; - cx = startx; startx += incyx; - } while (--ty); - } - else // draw solid - { - if (blend == 0) - { - dst_base += dst_pitch; - starty += incyy; - startx += incyx; - } - else - { - if ((sy & 1) ^ (blend & 1)) - { - if (ty <= 1) return; - - dst_ptr += dst_pitch; - cy += incyy; - cx += incyx; - } - - if (ty > 1) - { - ty >>= 1; - dst_pitch <<= 1; - incyy <<= 1; - incyx <<= 1; - - dst_base = dst_ptr + dst_pitch; - starty = cy + incyy; - startx = cx + incyx; - } - } - - do { - do { - int srcx = (cx >> 16) & 0x1fff; - int srcy = (cy >> 16) & 0x1fff; - int pixel; - UINT32 offs; - - offs = srcy * src_pitch + srcx; - - cx += incxx; - cy += incxy; - - if (offs<0 || offs>=src_size) - continue; - - if (srcx < src_minx || srcx > src_maxx || srcy < src_miny || srcy > src_maxy) - continue; - - pixel = src_base[offs]; - if (!(pixel & cmask)) - continue; - - dst_ptr[ecx] = pal_base[pixel]; - } - while (++ecx); - - ecx = tx; - dst_ptr = dst_base; dst_base += dst_pitch; - cy = starty; starty += incyy; - cx = startx; startx += incyx; - } while (--ty); - } -} - -// adapted from generic K053936_zoom_draw() -static void K053936GP_zoom_draw(running_machine *machine, - int chip, UINT16 *ctrl, UINT16 *linectrl, - bitmap_t *bitmap, const rectangle *cliprect, tilemap *tmap, - int tilebpp, int blend, int alpha) -{ - bitmap_t *src_bitmap; - rectangle *src_cliprect; - UINT16 *lineaddr; - - rectangle my_clip; - UINT32 startx, starty; - int incxx, incxy, incyx, incyy, y, maxy, clip; - - src_bitmap = tilemap_get_pixmap(tmap); - src_cliprect = &K053936_cliprect[chip]; - clip = K053936_clip_enabled[chip]; - - if (ctrl[0x07] & 0x0040) /* "super" mode */ - { - my_clip.min_x = cliprect->min_x; - my_clip.max_x = cliprect->max_x; - y = cliprect->min_y; - maxy = cliprect->max_y; - - while (y <= maxy) - { - lineaddr = linectrl + ( ((y - K053936_offset[chip][1]) & 0x1ff) << 2); - my_clip.min_y = my_clip.max_y = y; - - startx = (INT16)(lineaddr[0] + ctrl[0x00]) << 8; - starty = (INT16)(lineaddr[1] + ctrl[0x01]) << 8; - incxx = (INT16)(lineaddr[2]); - incxy = (INT16)(lineaddr[3]); - - if (ctrl[0x06] & 0x8000) incxx <<= 8; - if (ctrl[0x06] & 0x0080) incxy <<= 8; - - startx -= K053936_offset[chip][0] * incxx; - starty -= K053936_offset[chip][0] * incxy; - - K053936GP_copyroz32clip(machine, - bitmap, src_bitmap, &my_clip, src_cliprect, - startx<<5, starty<<5, incxx<<5, incxy<<5, 0, 0, - tilebpp, blend, alpha, clip); - y++; - } - } - else /* "simple" mode */ - { - startx = (INT16)(ctrl[0x00]) << 8; - starty = (INT16)(ctrl[0x01]) << 8; - incyx = (INT16)(ctrl[0x02]); - incyy = (INT16)(ctrl[0x03]); - incxx = (INT16)(ctrl[0x04]); - incxy = (INT16)(ctrl[0x05]); - - if (ctrl[0x06] & 0x4000) { incyx <<= 8; incyy <<= 8; } - if (ctrl[0x06] & 0x0040) { incxx <<= 8; incxy <<= 8; } - - startx -= K053936_offset[chip][1] * incyx; - starty -= K053936_offset[chip][1] * incyy; - - startx -= K053936_offset[chip][0] * incxx; - starty -= K053936_offset[chip][0] * incxy; - - K053936GP_copyroz32clip(machine, - bitmap, src_bitmap, cliprect, src_cliprect, - startx<<5, starty<<5, incxx<<5, incxy<<5, incyx<<5, incyy<<5, - tilebpp, blend, alpha, clip); - } -} - -void K053936GP_0_zoom_draw(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, - tilemap *tmap, int tilebpp, int blend, int alpha) -{ - K053936GP_zoom_draw(machine, 0,K053936_0_ctrl,K053936_0_linectrl,bitmap,cliprect,tmap,tilebpp,blend,alpha); -} - -void K053936GP_1_zoom_draw(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, - tilemap *tmap, int tilebpp, int blend, int alpha) -{ - K053936GP_zoom_draw(machine, 1,K053936_1_ctrl,K053936_1_linectrl,bitmap,cliprect,tmap,tilebpp,blend,alpha); -} - - - -/* - Parameter Notes - --------------- - clip : *caller must supply a pointer to target clip rectangle - alpha : 0 = invisible, 255 = solid - drawmode: - 0 = all pens solid - 1 = solid pens only - 2 = all pens solid with alpha blending - 3 = solid pens only with alpha blending - 4 = shadow pens only - 5 = all pens shadow - zcode : 0 = closest, 255 = furthest (pixel z-depth), -1 = disable depth buffers and shadows - pri : 0 = topmost, 255 = backmost (pixel priority) -*/ - - -INLINE void zdrawgfxzoom32GP( - bitmap_t *bitmap, const rectangle *cliprect, const gfx_element *gfx, - UINT32 code, UINT32 color, int flipx, int flipy, int sx, int sy, - int scalex, int scaley, int alpha, int drawmode, int zcode, int pri) -{ -#define FP 19 -#define FPONE (1<color_granularity; - shdpen--; - - if (zcode >= 0) - { - if (drawmode == 5) { drawmode = 4; shdpen = 1; } - } - else - if (drawmode >= 4) return; - - // alpha blend necessary? - if (drawmode & 2) - { - if (alpha <= 0) return; - if (alpha >= 255) drawmode &= ~2; - } - - // fill internal data structure with default values - ozbuf_ptr = gx_objzbuf; - szbuf_ptr = gx_shdzbuf; - - src_pitch = 16; - src_fw = 16; - src_fh = 16; - src_base = gfx_element_get_data(gfx, code % gfx->total_elements); - - pal_base = gfx->machine->pens + gfx->color_base + (color % gfx->total_colors) * granularity; - shd_base = gfx->machine->shadow_table; - - dst_ptr = (UINT32 *)bitmap->base; - dst_pitch = bitmap->rowpixels; - dst_minx = cliprect->min_x; - dst_maxx = cliprect->max_x; - dst_miny = cliprect->min_y; - dst_maxy = cliprect->max_y; - dst_x = sx; - dst_y = sy; - - // cull off-screen objects - if (dst_x > dst_maxx || dst_y > dst_maxy) return; - nozoom = (scalex == 0x10000 && scaley == 0x10000); - if (nozoom) - { - dst_h = dst_w = 16; - src_fdy = src_fdx = 1; - } - else - { - dst_w = ((scalex<<4)+0x8000)>>16; - dst_h = ((scaley<<4)+0x8000)>>16; - if (!dst_w || !dst_h) return; - - src_fw <<= FP; - src_fh <<= FP; - src_fdx = src_fw / dst_w; - src_fdy = src_fh / dst_h; - } - dst_lastx = dst_x + dst_w - 1; - if (dst_lastx < dst_minx) return; - dst_lasty = dst_y + dst_h - 1; - if (dst_lasty < dst_miny) return; - - // clip destination - dst_skipx = 0; - eax = dst_minx; if ((eax -= dst_x) > 0) { dst_skipx = eax; dst_w -= eax; dst_x = dst_minx; } - eax = dst_lastx; if ((eax -= dst_maxx) > 0) dst_w -= eax; - dst_skipy = 0; - eax = dst_miny; if ((eax -= dst_y) > 0) { dst_skipy = eax; dst_h -= eax; dst_y = dst_miny; } - eax = dst_lasty; if ((eax -= dst_maxy) > 0) dst_h -= eax; - - // calculate zoom factors and clip source - if (nozoom) - { - if (!flipx) src_fbx = 0; else { src_fbx = src_fw - 1; src_fdx = -src_fdx; } - if (!flipy) src_fby = 0; else { src_fby = src_fh - 1; src_fdy = -src_fdy; src_pitch = -src_pitch; } - } - else - { - if (!flipx) src_fbx = FPENT; else { src_fbx = src_fw - FPENT - 1; src_fdx = -src_fdx; } - if (!flipy) src_fby = FPENT; else { src_fby = src_fh - FPENT - 1; src_fdy = -src_fdy; } - } - src_fbx += dst_skipx * src_fdx; - src_fby += dst_skipy * src_fdy; - - // adjust insertion points and pre-entry constants - eax = (dst_y - dst_miny) * GX_ZBUFW + (dst_x - dst_minx) + dst_w; - db0 = z8 = (UINT8)zcode; - db1 = p8 = (UINT8)pri; - ozbuf_ptr += eax; - szbuf_ptr += eax << 1; - dst_ptr += dst_y * dst_pitch + dst_x + dst_w; - dst_w = -dst_w; - - if (!nozoom) - { - ecx = src_fby; src_fby += src_fdy; - ecx >>= FP; src_fx = src_fbx; - src_x = src_fbx; src_fx += src_fdx; - ecx <<= 4; src_ptr = src_base; - src_x >>= FP; src_ptr += ecx; - ecx = dst_w; - - if (zcode < 0) // no shadow and z-buffering - { - do { - do { - eax = src_ptr[src_x]; - src_x = src_fx; - src_fx += src_fdx; - src_x >>= FP; - if (!eax || eax >= shdpen) continue; - dst_ptr [ecx] = pal_base[eax]; - } - while (++ecx); - - ecx = src_fby; src_fby += src_fdy; - dst_ptr += dst_pitch; - ecx >>= FP; src_fx = src_fbx; - src_x = src_fbx; src_fx += src_fdx; - ecx <<= 4; src_ptr = src_base; - src_x >>= FP; src_ptr += ecx; - ecx = dst_w; - } - while (--dst_h); - } - else - { - switch (drawmode) - { - case 0: // all pens solid - do { - do { - eax = src_ptr[src_x]; - src_x = src_fx; - src_fx += src_fdx; - src_x >>= FP; - if (!eax || ozbuf_ptr[ecx] < z8) continue; - eax = pal_base[eax]; - ozbuf_ptr[ecx] = z8; - dst_ptr [ecx] = eax; - } - while (++ecx); - - ecx = src_fby; src_fby += src_fdy; - ozbuf_ptr += GX_ZBUFW; - dst_ptr += dst_pitch; - ecx >>= FP; src_fx = src_fbx; - src_x = src_fbx; src_fx += src_fdx; - ecx <<= 4; src_ptr = src_base; - src_x >>= FP; src_ptr += ecx; - ecx = dst_w; - } - while (--dst_h); - break; - - case 1: // solid pens only - do { - do { - eax = src_ptr[src_x]; - src_x = src_fx; - src_fx += src_fdx; - src_x >>= FP; - if (!eax || eax >= shdpen || ozbuf_ptr[ecx] < z8) continue; - eax = pal_base[eax]; - ozbuf_ptr[ecx] = z8; - dst_ptr [ecx] = eax; - } - while (++ecx); - - ecx = src_fby; src_fby += src_fdy; - ozbuf_ptr += GX_ZBUFW; - dst_ptr += dst_pitch; - ecx >>= FP; src_fx = src_fbx; - src_x = src_fbx; src_fx += src_fdx; - ecx <<= 4; src_ptr = src_base; - src_x >>= FP; src_ptr += ecx; - ecx = dst_w; - } - while (--dst_h); - break; - - case 2: // all pens solid with alpha blending - do { - do { - eax = src_ptr[src_x]; - src_x = src_fx; - src_fx += src_fdx; - src_x >>= FP; - if (!eax || ozbuf_ptr[ecx] < z8) continue; - ozbuf_ptr[ecx] = z8; - - dst_ptr[ecx] = alpha_blend_r32(pal_base[eax], dst_ptr[ecx], alpha); - } - while (++ecx); - - ecx = src_fby; src_fby += src_fdy; - ozbuf_ptr += GX_ZBUFW; - dst_ptr += dst_pitch; - ecx >>= FP; src_fx = src_fbx; - src_x = src_fbx; src_fx += src_fdx; - ecx <<= 4; src_ptr = src_base; - src_x >>= FP; src_ptr += ecx; - ecx = dst_w; - } - while (--dst_h); - break; - - case 3: // solid pens only with alpha blending - do { - do { - eax = src_ptr[src_x]; - src_x = src_fx; - src_fx += src_fdx; - src_x >>= FP; - if (!eax || eax >= shdpen || ozbuf_ptr[ecx] < z8) continue; - ozbuf_ptr[ecx] = z8; - - dst_ptr[ecx] = alpha_blend_r32(pal_base[eax], dst_ptr[ecx], alpha); - } - while (++ecx); - - ecx = src_fby; src_fby += src_fdy; - ozbuf_ptr += GX_ZBUFW; - dst_ptr += dst_pitch; - ecx >>= FP; src_fx = src_fbx; - src_x = src_fbx; src_fx += src_fdx; - ecx <<= 4; src_ptr = src_base; - src_x >>= FP; src_ptr += ecx; - ecx = dst_w; - } - while (--dst_h); - break; - - case 4: // shadow pens only - do { - do { - eax = src_ptr[src_x]; - src_x = src_fx; - src_fx += src_fdx; - src_x >>= FP; - if (eax < shdpen || szbuf_ptr[ecx*2] < z8 || szbuf_ptr[ecx*2+1] <= p8) continue; - eax = dst_ptr[ecx]; - szbuf_ptr[ecx*2] = z8; - szbuf_ptr[ecx*2+1] = p8; - - // the shadow tables are 15-bit lookup tables which accept RGB15... lossy, nasty, yuck! - dst_ptr[ecx] = shd_base[rgb_to_rgb15(eax)]; - //dst_ptr[ecx] =(eax>>3&0x001f);lend_r32( eax, 0x00000000, 128); - } - while (++ecx); - - ecx = src_fby; src_fby += src_fdy; - szbuf_ptr += (GX_ZBUFW<<1); - dst_ptr += dst_pitch; - ecx >>= FP; src_fx = src_fbx; - src_x = src_fbx; src_fx += src_fdx; - ecx <<= 4; src_ptr = src_base; - src_x >>= FP; src_ptr += ecx; - ecx = dst_w; - } - while (--dst_h); - break; - } // switch (drawmode) - } // if (zcode < 0) - } // if (!nozoom) - else - { - src_ptr = src_base + (src_fby<<4) + src_fbx; - src_fdy = src_fdx * dst_w + src_pitch; - ecx = dst_w; - - if (zcode < 0) // no shadow and z-buffering - { - do { - do { - eax = *src_ptr; - src_ptr += src_fdx; - if (!eax || eax >= shdpen) continue; - dst_ptr[ecx] = pal_base[eax]; - } - while (++ecx); - - src_ptr += src_fdy; - dst_ptr += dst_pitch; - ecx = dst_w; - } - while (--dst_h); - } - else - { - switch (drawmode) - { - case 0: // all pens solid - do { - do { - eax = *src_ptr; - src_ptr += src_fdx; - if (!eax || ozbuf_ptr[ecx] < z8) continue; - eax = pal_base[eax]; - ozbuf_ptr[ecx] = z8; - dst_ptr[ecx] = eax; - } - while (++ecx); - - src_ptr += src_fdy; - ozbuf_ptr += GX_ZBUFW; - dst_ptr += dst_pitch; - ecx = dst_w; - } - while (--dst_h); - break; - - case 1: // solid pens only - do { - do { - eax = *src_ptr; - src_ptr += src_fdx; - if (!eax || eax >= shdpen || ozbuf_ptr[ecx] < z8) continue; - eax = pal_base[eax]; - ozbuf_ptr[ecx] = z8; - dst_ptr[ecx] = eax; - } - while (++ecx); - - src_ptr += src_fdy; - ozbuf_ptr += GX_ZBUFW; - dst_ptr += dst_pitch; - ecx = dst_w; - } - while (--dst_h); - break; - - case 2: // all pens solid with alpha blending - do { - do { - eax = *src_ptr; - src_ptr += src_fdx; - if (!eax || ozbuf_ptr[ecx] < z8) continue; - ozbuf_ptr[ecx] = z8; - - dst_ptr[ecx] = alpha_blend_r32(pal_base[eax], dst_ptr[ecx], alpha); - } - while (++ecx); - - src_ptr += src_fdy; - ozbuf_ptr += GX_ZBUFW; - dst_ptr += dst_pitch; - ecx = dst_w; - } - while (--dst_h); - break; - - case 3: // solid pens only with alpha blending - do { - do { - eax = *src_ptr; - src_ptr += src_fdx; - if (!eax || eax >= shdpen || ozbuf_ptr[ecx] < z8) continue; - ozbuf_ptr[ecx] = z8; - - dst_ptr[ecx] = alpha_blend_r32(pal_base[eax], dst_ptr[ecx], alpha); - } - while (++ecx); - - src_ptr += src_fdy; - ozbuf_ptr += GX_ZBUFW; - dst_ptr += dst_pitch; - ecx = dst_w; - } - while (--dst_h); - break; - - case 4: // shadow pens only - do { - do { - eax = *src_ptr; - src_ptr += src_fdx; - if (eax < shdpen || szbuf_ptr[ecx*2] < z8 || szbuf_ptr[ecx*2+1] <= p8) continue; - eax = dst_ptr[ecx]; - szbuf_ptr[ecx*2] = z8; - szbuf_ptr[ecx*2+1] = p8; - - // the shadow tables are 15-bit lookup tables which accept RGB15... lossy, nasty, yuck! - dst_ptr[ecx] = shd_base[rgb_to_rgb15(eax)]; - } - while (++ecx); - - src_ptr += src_fdy; - szbuf_ptr += (GX_ZBUFW<<1); - dst_ptr += dst_pitch; - ecx = dst_w; - } - while (--dst_h); - break; - } - } - } -#undef FP -#undef FPONE -#undef FPHALF -#undef FPENT -} - - - -/***************************************************************************/ -/* */ -/* 1st-Tier GX/MW Variables and Functions */ -/* */ -/***************************************************************************/ - -// global system ports access -UINT8 konamigx_wrport1_0, konamigx_wrport1_1; -UINT16 konamigx_wrport2; - -// frequently used registers -static int K053246_objset1; -static int K053247_vrcbk[4]; -static int K053247_coreg, K053247_coregshift, K053247_opset; -static int opri, oinprion; -static int vcblk[6], ocblk; -static int vinmix, vmixon, osinmix, osmixon; - - -static void konamigx_precache_registers(void) -{ - // (see sprite color coding scheme on p.46 & 47) - static const int coregmasks[5] = {0xf,0xe,0xc,0x8,0x0}; - static const int coregshifts[5]= {4,5,6,7,8}; - int i; - - K053246_objset1 = K053246_read_register(5); - - i = K053247_read_register(0x8/2); - K053247_vrcbk[0] = (i & 0x000f) << 14; - K053247_vrcbk[1] = (i & 0x0f00) << 6; - i = K053247_read_register(0xa/2); - K053247_vrcbk[2] = (i & 0x000f) << 14; - K053247_vrcbk[3] = (i & 0x0f00) << 6; - - // COREG == OBJSET2+1C == bit8-11 of OPSET ??? (see p.50 last table, needs p.49 to confirm) - K053247_opset = K053247_read_register(0xc/2); - - i = K053247_opset & 7; if (i > 4) i = 4; - - K053247_coreg = K053247_read_register(0xc/2)>>8 & 0xf; - K053247_coreg =(K053247_coreg & coregmasks[i]) << 12; - - K053247_coregshift = coregshifts[i]; - - opri = K055555_read_register(K55_PRIINP_8); - oinprion = K055555_read_register(K55_OINPRI_ON); - vcblk[0] = K055555_read_register(K55_PALBASE_A); - vcblk[1] = K055555_read_register(K55_PALBASE_B); - vcblk[2] = K055555_read_register(K55_PALBASE_C); - vcblk[3] = K055555_read_register(K55_PALBASE_D); - vcblk[4] = K055555_read_register(K55_PALBASE_SUB1); - vcblk[5] = K055555_read_register(K55_PALBASE_SUB2); - ocblk = K055555_read_register(K55_PALBASE_OBJ); - vinmix = K055555_read_register(K55_BLEND_ENABLES); - vmixon = K055555_read_register(K55_VINMIX_ON); - osinmix = K055555_read_register(K55_OSBLEND_ENABLES); - osmixon = K055555_read_register(K55_OSBLEND_ON); -} - -INLINE int K053247GX_combine_c18(int attrib) // (see p.46) -{ - int c18; - - c18 = (attrib & 0xff)<> K053247_coregshift); -} - -INLINE int K055555GX_decode_inpri(int c18) // (see p.59 7.2.2) -{ - int op = opri; - - c18 >>= 8; - op &= oinprion; - c18 &=~oinprion; - - return(c18 | op); -} - -void konamigx_type2_sprite_callback(int *code, int *color, int *priority) -{ - int num = *code; - int c18 = *color; - - *code = K053247_vrcbk[num>>14] | (num & 0x3fff); - c18 = K053247GX_combine_c18(c18); - *color = K055555GX_decode_objcolor(c18); - *priority = K055555GX_decode_inpri(c18); -} - -void konamigx_dragoonj_sprite_callback(int *code, int *color, int *priority) -{ - int num, op, pri, c18; - - num = *code; - *code = K053247_vrcbk[num>>14] | (num & 0x3fff); - - c18 = pri = *color; - op = opri; - pri = (pri & 0x200) ? 4 : pri>>4 & 0xf; - op &= oinprion; - pri &=~oinprion; - *priority = pri | op; - - c18 = K053247GX_combine_c18(c18); - *color = K055555GX_decode_objcolor(c18); -} - -void konamigx_salmndr2_sprite_callback(int *code, int *color, int *priority) -{ - int num, op, pri, c18; - - num = *code; - *code = K053247_vrcbk[num>>14] | (num & 0x3fff); - - c18 = pri = *color; - op = opri; - pri = pri>>4 & 0x3f; - op &= oinprion; - pri &=~oinprion; - *priority = pri | op; - - c18 = K053247GX_combine_c18(c18); - *color = K055555GX_decode_objcolor(c18); -} - -void konamigx_le2_sprite_callback(int *code, int *color, int *priority) -{ - int num, op, pri; - - num = *code; - *code = K053247_vrcbk[num>>14] | (num & 0x3fff); - - pri = *color; - *color &= 0x1f; - - op = opri; - pri &= 0xf0; - op &= oinprion; - pri &=~oinprion; - *priority = pri | op; -} - -int K055555GX_decode_vmixcolor(int layer, int *color) // (see p.62 7.2.6 and p.27 3.3) -{ - int vcb, shift, pal, vmx, von, pl45, emx; - - vcb = vcblk[layer]<<6; - shift = layer<<1; - pal = *color; - vmx = vinmix>>shift & 3; - von = vmixon>>shift & 3; - emx = pl45 = pal>>4 & 3; - pal &= 0xf; - pl45 &= von; - vmx &= von; - pl45 <<= 4; - emx &= ~von; - pal |= pl45; - emx |= vmx; - pal |= vcb; - - if (von == 3) emx = -1; // invalidate external mix code if all bits are from internal - *color = pal; - - return(emx); -} - -int K055555GX_decode_osmixcolor(int layer, int *color) // (see p.63, p.49-50 and p.27 3.3) -{ - int scb, shift, pal, osmx, oson, pl45, emx; - - shift = layer<<1; - pal = *color; - osmx = osinmix>>shift & 3; - oson = osmixon>>shift & 3; - - if (layer) - { - // layer 1-3 are external tile layers - scb = vcblk[layer+3]<<6; - emx = pl45 = pal>>4 & 3; - pal &= 0xf; - pl45 &= oson; - osmx &= oson; - pl45 <<= 4; - emx &= ~oson; - pal |= pl45; - emx |= osmx; - pal |= scb; - - if (oson == 3) emx = -1; // invalidate external mix code if all bits are from internal - *color = pal; - } - else - { - // layer 0 is the sprite layer with different attributes decode; detail on p.49 (missing) - emx = 0; // K053247_read_register(??)>>? & 3; - osmx &= oson; - emx &=~oson; - emx |= osmx; - } - - return(emx); -} - -static void gx_wipezbuf(running_machine *machine, int noshadow) -{ - const rectangle *visarea = video_screen_get_visible_area(machine->primary_screen); - - int w = visarea->max_x - visarea->min_x + 1; - int h = visarea->max_y - visarea->min_y + 1; - - UINT8 *zptr = gx_objzbuf; - int ecx = h; - - do { memset(zptr, -1, w); zptr += GX_ZBUFW; } while (--ecx); - - if (!noshadow) - { - zptr = gx_shdzbuf; - w <<= 1; - ecx = h; - do { memset(zptr, -1, w); zptr += (GX_ZBUFW<<1); } while (--ecx); - } -} - -/* - * Sprite Format - * ------------------ - * - * Word | Bit(s) | Use - * -----+-fedcba9876543210-+---------------- - * 0 | x--------------- | active (show this sprite) - * 0 | -x-------------- | maintain aspect ratio (when set, zoom y acts on both axis) - * 0 | --x------------- | flip y - * 0 | ---x------------ | flip x - * 0 | ----xxxx-------- | sprite size (see below) - * 0 | --------xxxxxxxx | zcode - * 1 | xxxxxxxxxxxxxxxx | sprite code - * 2 | ------xxxxxxxxxx | y position - * 3 | ------xxxxxxxxxx | x position - * 4 | xxxxxxxxxxxxxxxx | zoom y (0x40 = normal, <0x40 = enlarge, >0x40 = reduce) - * 5 | xxxxxxxxxxxxxxxx | zoom x (0x40 = normal, <0x40 = enlarge, >0x40 = reduce) - * 6 | x--------------- | mirror y (top half is drawn as mirror image of the bottom) - * 6 | -x-------------- | mirror x (right half is drawn as mirror image of the left) - * 6 | --xx------------ | reserved (sprites with these two bits set don't seem to be graphics data at all) - * 6 | ----xx---------- | shadow code: 0=off, 0x400=preset1, 0x800=preset2, 0xc00=preset3 - * 6 | ------xx-------- | effect code: flicker, upper palette, full shadow...etc. (game dependent) - * 6 | --------xxxxxxxx | "color", but depends on external connections (implies priority) - * 7 | xxxxxxxxxxxxxxxx | game dependent - * - * shadow enables transparent shadows. Note that it applies to the last sprite pen ONLY. - * The rest of the sprite remains normal. - */ -#define GX_MAX_SPRITES 512 -#define GX_MAX_LAYERS 6 -#define GX_MAX_OBJECTS (GX_MAX_SPRITES + GX_MAX_LAYERS) - -static struct GX_OBJ { int order, offs, code, color; } *gx_objpool; -static UINT16 *gx_spriteram; -static int gx_objdma, gx_primode; - -// mirrored K053247 and K054338 settings -static UINT16 *K053247_ram; -static gfx_element *K053247_gfx; -static void (*K053247_callback)(int *code,int *color,int *priority); -static int K053247_dx, K053247_dy; - -static int *K054338_shdRGB; - - -void K053247GP_set_SpriteOffset(int offsx, int offsy) -{ - K053247_dx = offsx; - K053247_dy = offsy; -} - -void konamigx_mixer_init(running_machine *machine, int objdma) -{ - gx_objdma = 0; - gx_primode = 0; - - gx_objzbuf = (UINT8 *)machine->priority_bitmap->base; - gx_shdzbuf = auto_alloc_array(machine, UINT8, GX_ZBUFSIZE); - gx_objpool = auto_alloc_array(machine, struct GX_OBJ, GX_MAX_OBJECTS); - - K053247_export_config(&K053247_ram, &K053247_gfx, &K053247_callback, &K053247_dx, &K053247_dy); - K054338_export_config(&K054338_shdRGB); - - if (objdma) - { - gx_spriteram = auto_alloc_array(machine, UINT16, 0x1000/2); - gx_objdma = 1; - } - else - gx_spriteram = K053247_ram; - - palette_set_shadow_dRGB32(machine, 3,-80,-80,-80, 0); - K054338_invert_alpha(1); -} - -void konamigx_mixer_primode(int mode) -{ - gx_primode = mode; -} - -void konamigx_objdma(void) -{ - if (gx_objdma && gx_spriteram && K053247_ram) memcpy(gx_spriteram, K053247_ram, 0x1000); -} - -void konamigx_mixer(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, - tilemap *sub1, int sub1flags, - tilemap *sub2, int sub2flags, - int mixerflags, bitmap_t *extra_bitmap, int rushingheroes_hack) -{ - static const int xoffset[8] = { 0, 1, 4, 5, 16, 17, 20, 21 }; - static const int yoffset[8] = { 0, 2, 8, 10, 32, 34, 40, 42 }; - static int parity = 0; - - int objbuf[GX_MAX_OBJECTS]; - int shadowon[3], shdpri[3], layerid[6], layerpri[6]; - - struct GX_OBJ *objpool, *objptr; - int wrapsize, xwraplim, ywraplim, cltc_shdpri, prflp, disp; - int xa,ya,ox,oy,zw,zh,flipx,flipy,mirrorx,mirrory,zoomx,zoomy,scalex,scaley,nozoom; - int screenwidth, flipscreenx, flipscreeny, offx, offy; - int nobj, i, j, k, l, temp, temp1, temp2, temp3, temp4, count; - int order, offs, code, color, zcode, pri = 0, spri, spri_min, shdprisel, shadow, alpha, drawmode; - - - // abort if object database failed to initialize - objpool = gx_objpool; - if (!objpool) return; - - // clear screen with backcolor and update flicker pulse - K054338_fill_backcolor(machine, bitmap, konamigx_wrport1_0 & 0x20); - parity ^= 1; - - // abort if video has been disabled - disp = K055555_read_register(K55_INPUT_ENABLES); - if (!disp) return; - cltc_shdpri = K054338_read_register(K338_REG_CONTROL); - if (!(cltc_shdpri & K338_CTL_KILL)) return; - - // demote shadows by one layer when this bit is set??? (see p.73 8.6) - cltc_shdpri &= K338_CTL_SHDPRI; - - // wipe z-buffer - if (mixerflags & GXMIX_NOZBUF) - mixerflags |= GXMIX_NOSHADOW; - else - gx_wipezbuf(machine, mixerflags & GXMIX_NOSHADOW); - - // cache global parameters - konamigx_precache_registers(); - - // init OBJSET1 parameters (see p.47 6.2) - flipscreenx = K053246_objset1 & 1; - flipscreeny = K053246_objset1 & 2; - - // get "display window" offsets - offx = (K053246_read_register(0)<<8 | K053246_read_register(1)) & 0x3ff; - offy = (K053246_read_register(2)<<8 | K053246_read_register(3)) & 0x3ff; - - // init OBJSET2 and mixer parameters (see p.51 and chapter 7) - layerid[0] = 0; layerid[1] = 1; layerid[2] = 2; layerid[3] = 3; layerid[4] = 4; layerid[5] = 5; - - if (K053247_opset & 0x40) - { - wrapsize = 512; - xwraplim = 512 - 64; - ywraplim = 512 - 128; - } - else - { - wrapsize = 1024; - xwraplim = 1024 - 384; - ywraplim = 1024 - 512; - } - - // invert layer priority when this flag is set (not used by any GX game?) - prflp = K055555_read_register(K55_CONTROL) & K55_CTL_FLIPPRI; - - layerpri[0] = K055555_read_register(K55_PRIINP_0); - layerpri[1] = K055555_read_register(K55_PRIINP_3); - layerpri[3] = K055555_read_register(K55_PRIINP_7); - layerpri[4] = K055555_read_register(K55_PRIINP_9); - layerpri[5] = K055555_read_register(K55_PRIINP_10); - - if (gx_primode == -1) - { - // Lethal Enforcer hack (requires pixel color comparison) - layerpri[2] = K055555_read_register(K55_PRIINP_3) + 0x20; - shdprisel = 0x3f; - } - else - { - layerpri[2] = K055555_read_register(K55_PRIINP_6); - shdprisel = K055555_read_register(K55_SHD_PRI_SEL); - } - - // SHDPRISEL filters shadows by different priority comparison methods (UNIMPLEMENTED, see detail on p.66) - if (!(shdprisel & 0x03)) shadowon[0] = 0; - if (!(shdprisel & 0x0c)) shadowon[1] = 0; - if (!(shdprisel & 0x30)) shadowon[2] = 0; - - shdpri[0] = K055555_read_register(K55_SHAD1_PRI); - shdpri[1] = K055555_read_register(K55_SHAD2_PRI); - shdpri[2] = K055555_read_register(K55_SHAD3_PRI); - - spri_min = 0; - shadowon[2] = shadowon[1] = shadowon[0] = 0; - - if (!(mixerflags & GXMIX_NOSHADOW)) - { - // only enable shadows beyond a +/-7 RGB threshold - for (j=0,i=0; i<3; j+=3,i++) - { - k = K054338_shdRGB[j ]; if (k < -7 || k > 7) { shadowon[i] = 1; continue; } - k = K054338_shdRGB[j+1]; if (k < -7 || k > 7) { shadowon[i] = 1; continue; } - k = K054338_shdRGB[j+2]; if (k < -7 || k > 7) { shadowon[i] = 1; } - } - - // SHDON specifies layers on which shadows can be projected (see detail on p.65 7.2.8) - temp = K055555_read_register(K55_SHD_ON); - for (i=0; i<4; i++) if (!(temp>>i & 1) && spri_min < layerpri[i]) spri_min = layerpri[i]; // HACK - - // update shadows status - K054338_update_all_shadows(machine, rushingheroes_hack); - } - - // pre-sort layers - for (j=0; j<5; j++) - { - temp1 = layerpri[j]; - for (i=j+1; i<6; i++) - { - temp2 = layerpri[i]; - if ((UINT32)temp1 <= (UINT32)temp2) - { - layerpri[i] = temp1; layerpri[j] = temp1 = temp2; - temp2 = layerid[i]; layerid[i] = layerid[j]; layerid[j] = temp2; - } - } - } - - // build object database and create indices - objptr = objpool; - nobj = 0; - - for (i=5; i>=0; i--) - { - code = layerid[i]; - switch (code) - { - /* - Background layers are represented by negative offset values as follow: - - 0+ : normal sprites - -1 : tile layer A - D - -2 : K053936 ROZ+ layer 1 - -3 : K053936 ROZ+ layer 2 - -4 : K053250 LVC layer 1 - -5 : K053250 LVC layer 2 - */ - case 4 : - offs = -128; - if (sub1flags & 0xf) { if (sub1flags & GXSUB_K053250) offs = -4; else if (sub1) offs = -2; } - break; - case 5 : - offs = -128; - if (sub2flags & 0xf) { if (sub2flags & GXSUB_K053250) offs = -5; else if (sub2) offs = -3; } - if (extra_bitmap) offs = -3; - break; - default: offs = -1; - } - - if (offs != -128) - { - objptr->order = layerpri[i]<<24; - objptr->code = code; - objptr->offs = offs; - objptr++; - - objbuf[nobj] = nobj; - nobj++; - } - } - - i = j = 0xff; - - for (offs=0; offs<0x800; offs+=8) - { - if (!(gx_spriteram[offs] & 0x8000)) continue; - - zcode = gx_spriteram[offs] & 0xff; - - // invert z-order when opset_pri is set (see p.51 OPSET PRI) - if (K053247_opset & 0x10) zcode = 0xff - zcode; - - code = gx_spriteram[offs+1]; - color = k = gx_spriteram[offs+6]; - l = gx_spriteram[offs+7]; - - (*K053247_callback)(&code, &color, &pri); - - /* - shadow = shadow code - spri = shadow priority - temp1 = add solid object - temp2 = solid pens draw mode - temp3 = add shadow object - temp4 = shadow pens draw mode - */ - temp4 = temp3 = temp2 = temp1 = spri = shadow = 0; - - if (color & K055555_FULLSHADOW) - { - shadow = 3; // use default intensity and color - spri = pri; // retain host priority - temp3 = 1; // add shadow - temp4 = 5; // draw full shadow - } - else - { - shadow = k>>10 & 3; - if (shadow) // object has shadow? - { - if (shadow != 1 || K053246_objset1 & 0x20) - { - shadow--; - temp1 = 1; // add solid - temp2 = 1; // draw partial solid - if (shadowon[shadow]) - { - temp3 = 1; // add shadow - temp4 = 4; // draw partial shadow - } - } - else - { - // drop the entire sprite to shadow if its shadow code is 1 and SD0EN is off (see p.48) - shadow = 0; - if (!shadowon[0]) continue; - temp3 = 1; // add shadow - temp4 = 5; // draw full shadow - } - } - else - { - temp1 = 1; // add solid - temp2 = 0; // draw full solid - } - - if (temp1) - { - // tag sprite for alpha blending - if (color>>K055555_MIXSHIFT & 3) temp2 |= 2; - } - - if (temp3) - { - // determine shadow priority - spri = (K053247_opset & 0x20) ? pri : shdpri[shadow]; // (see p.51 OPSET SDSEL) - } - } - - switch (gx_primode & 0xf) - { - // Dadandarn zcode suppression - case 1: - zcode = 0; - break; - - // Daisukiss bad shadow filter - case 4: - if (k & 0x3000 || k == 0x0800) continue; - - // Tokkae shadow masking (INACCURATE) - case 5: - if (spri < spri_min) spri = spri_min; - break; - } - - /* - default sort order: - fedcba9876543210fedcba9876543210 - xxxxxxxx------------------------ (priority) - --------xxxxxxxx---------------- (zcode) - ----------------xxxxxxxx-------- (offset) - ------------------------xxxx---- (shadow mode) - ----------------------------xxxx (shadow code) - */ - if (temp1) - { - // add objects with solid or alpha pens - order = pri<<24 | zcode<<16 | offs<<(8-3) | temp2<<4; - objptr->order = order; - objptr->offs = offs; - objptr->code = code; - objptr->color = color; - objptr++; - - objbuf[nobj] = nobj; - nobj++; - } - - if (temp3 && !(color & K055555_SKIPSHADOW) && !(mixerflags & GXMIX_NOSHADOW)) - { - // add objects with shadows if enabled - order = spri<<24 | zcode<<16 | offs<<(8-3) | temp4<<4 | shadow; - objptr->order = order; - objptr->offs = offs; - objptr->code = code; - objptr->color = color; - objptr++; - - objbuf[nobj] = nobj; - nobj++; - } - } - - // sort objects in decending order (SLOW) - k = nobj; - l = nobj - 1; - - for (j=0; jprimary_screen); - - for (count=0; countorder; - offs = objptr->offs; - code = objptr->code; - color = objptr->color; - - if (offs >= 0) - { - if (!(disp & K55_INP_OBJ)) continue; - } - else - { - i = code<<1; - j = mixerflags>>i & 3; - k = 0; - - switch (offs) - { - case -1: - if (disp & (1<>(i+16); temp3 = 3; } - else - { - temp1 = vinmix; - temp2 = vinmix>>i & 3; - temp3 = vmixon>>i & 3; - } - - /* blend layer only when: - 1) vinmix != 0xff - 2) its internal mix code is set - 3) all mix code bits are internal(overriden until tile blending has been implemented) - 4) 0 > alpha < 255; - */ - if (temp1!=0xff && temp2 /*&& temp3==3*/) - { - temp4 = K054338_set_alpha_level(temp2); - - if (temp4 <= 0) continue; - if (temp4 < 255) k = TILEMAP_DRAW_ALPHA(temp4); - } - - if (mixerflags & 1<<(code+12)) k |= K056382_DRAW_FLAG_FORCE_XYSCROLL; - - K056832_tilemap_draw(machine, bitmap, cliprect, code, k, 0); - } - continue; - case -2: - case -4: - if ((disp & K55_INP_SUB1) || (rushingheroes_hack)) - { - int alpha = 255; - - if (j == GXMIX_BLEND_NONE) { temp1 = 0xff; temp2 = temp3 = 0; } else - if (j == GXMIX_BLEND_FORCE) { temp1 = 0x00; temp2 = mixerflags>>24; temp3 = 3; } - else - { - temp1 = osinmix; - temp2 = osinmix>>2 & 3; - temp3 = osmixon>>2 & 3; - } - - if (temp1!=0xff && temp2 /*&& temp3==3*/) - { - alpha = temp4 = K054338_set_alpha_level(temp2); - - if (temp4 <= 0) continue; - if (temp4 < 255) k = (j == GXMIX_BLEND_FAST) ? ~parity : 1; - } - - l = sub1flags & 0xf; - - if (offs == -2) - { - K053936GP_0_zoom_draw(machine, bitmap, cliprect, sub1, l, k, alpha); - } - else - { - K053250_draw(machine, bitmap, cliprect, 0, vcblk[4]<>26; temp3 = 3; } - else - { - temp1 = osinmix; - temp2 = osinmix>>4 & 3; - temp3 = osmixon>>4 & 3; - } - - if (temp1!=0xff && temp2 /*&& temp3==3*/) - { - alpha = temp4 = K054338_set_alpha_level(temp2); - - if (temp4 <= 0) continue; - if (temp4 < 255) k = (j == GXMIX_BLEND_FAST) ? ~parity : 1; - } - - l = sub2flags & 0xf; - - if (offs == -3) - { - if (extra_bitmap) // soccer superstars roz layer - { - int xx,yy; - int width = video_screen_get_width(machine->primary_screen); - int height = video_screen_get_height(machine->primary_screen); - const pen_t *paldata = machine->pens; - - // the output size of the roz layer has to be doubled horizontally - // so that it aligns with the sprites and normal tilemaps. This appears - // to be done as a post-processing / mixing step effect - for (yy=0;yy>4 & 0xf; - - alpha = 255; - if (drawmode & 2) - { - alpha = color>>K055555_MIXSHIFT & 3; - if (alpha) alpha = K054338_set_alpha_level(alpha); - if (alpha <= 0) continue; - } - color &= K055555_COLORMASK; - - if (drawmode >= 4) palette_set_shadow_mode(machine, order & 0x0f); - - if (!(mixerflags & GXMIX_NOZBUF)) - { - zcode = order>>16 & 0xff; - pri = order>>24 & 0xff; - } - else - zcode = -1; // negative zcode values turn off z-buffering - - xa = ya = 0; - if (code & 0x01) xa += 1; - if (code & 0x02) ya += 1; - if (code & 0x04) xa += 2; - if (code & 0x08) ya += 2; - if (code & 0x10) xa += 4; - if (code & 0x20) ya += 4; - code &= ~0x3f; - - temp4 = gx_spriteram[offs]; - - // mask off the upper 6 bits of coordinate and zoom registers - oy = gx_spriteram[offs+2] & 0x3ff; - ox = gx_spriteram[offs+3] & 0x3ff; - - scaley = zoomy = gx_spriteram[offs+4] & 0x3ff; - if (zoomy) zoomy = (0x400000+(zoomy>>1)) / zoomy; - else zoomy = 0x800000; - if (!(temp4 & 0x4000)) - { - scalex = zoomx = gx_spriteram[offs+5] & 0x3ff; - if (zoomx) zoomx = (0x400000+(zoomx>>1)) / zoomx; - else zoomx = 0x800000; - } - else { zoomx = zoomy; scalex = scaley; } - - nozoom = (scalex == 0x40 && scaley == 0x40); - - flipx = temp4 & 0x1000; - flipy = temp4 & 0x2000; - - temp = gx_spriteram[offs+6]; - mirrorx = temp & 0x4000; - if (mirrorx) flipx = 0; // only applies to x mirror, proven - mirrory = temp & 0x8000; - - // for Escape Kids (GX975) - if ( K053246_objset1 & 8 ) // Check only "Bit #3 is '1'?" - { - zoomx = zoomx>>1; // Fix sprite width to HALF size - ox = (ox>>1) + 1; // Fix sprite draw position - - if (flipscreenx) ox += screenwidth; - } - - if (flipscreenx) { ox = -ox; if (!mirrorx) flipx = !flipx; } - if (flipscreeny) { oy = -oy; if (!mirrory) flipy = !flipy; } - - // apply wrapping and global offsets - temp = wrapsize-1; - - ox += K053247_dx; - oy -= K053247_dy; - ox = ( ox - offx) & temp; - oy = (-oy - offy) & temp; - if (ox >= xwraplim) ox -= wrapsize; - if (oy >= ywraplim) oy -= wrapsize; - - - temp = temp4>>8 & 0x0f; - k = 1 << (temp & 3); - l = 1 << (temp>>2 & 3); - - ox -= (zoomx * k) >> 13; - oy -= (zoomy * l) >> 13; - - // substitutes: i=x, j=y, k=w, l=h, temp=code, temp1=fx, temp2=fy, temp3=sx, temp4=sy; - for (j=0; j> 12); - zh = (oy + ((zoomy * (j+1) + (1<<11)) >> 12)) - temp4; - - for (i=0; i> 12); - zw = (ox + ((zoomx * (i+1) + (1<<11)) >> 12)) - temp3; - temp = code; - - if (mirrorx) - { - if ((!flipx)^((i<<1)=l)) - { - /* mirror top/bottom */ - temp += yoffset[(l-1-j+ya)&7]; - temp2 = 1; - } - else - { - temp += yoffset[(j+ya)&7]; - temp2 = 0; - } - } - else - { - if (flipy) temp += yoffset[(l-1-j+ya)&7]; - else temp += yoffset[(j+ya)&7]; - temp2 = flipy; - } - - if (nozoom) { scaley = scalex = 0x10000; } else { scalex = zw << 12; scaley = zh << 12; }; - - zdrawgfxzoom32GP( - bitmap, cliprect, K053247_gfx, - temp, - color, - temp1,temp2, - temp3,temp4, - scalex, scaley, alpha, drawmode, zcode, pri); - } - } - } -} - - +#include "konamigx.h" /***************************************************************************/ /* */ diff --git a/src/mame/video/bishi.c b/src/mame/video/bishi.c index 23fb2e36f1c..41db3f94be1 100644 --- a/src/mame/video/bishi.c +++ b/src/mame/video/bishi.c @@ -9,7 +9,7 @@ #include "driver.h" #include "video/konamiic.h" -#include "machine/konamigx.h" +#include "konamigx.h" static int layer_colorbase[4], layerpri[4]; diff --git a/src/mame/video/konamigx.c b/src/mame/video/konamigx.c index 15666fa951c..03a65134090 100644 --- a/src/mame/video/konamigx.c +++ b/src/mame/video/konamigx.c @@ -1,14 +1,38 @@ /* - * video/konamigx.c - Konami GX video hardware (here there be dragons) - * + * video/konamigx.c - Konami GX video hardware (here there be dragons, and achocode) + * */ #include "driver.h" #include "video/konamiic.h" -#include "machine/konamigx.h" +#include "konamigx.h" + +#define GX_DEBUG 0 #define VERBOSE 0 +/***************************************************************************/ +/* */ +/* 2nd-Tier GX/MW Graphics Functions */ +/* */ +/***************************************************************************/ + +#if GX_DEBUG + #define GX_ZBUFW 512 + #define GX_ZBUFH 384 + #define GX_ZPAGESIZE 0x300000 + #define GX_ZBUFSIZE 0x600000 +#else + #define GX_ZBUFW 576 + #define GX_ZBUFH 224 + #define GX_ZPAGESIZE (GX_ZBUFW*GX_ZBUFH) + #define GX_ZBUFSIZE ((GX_ZBUFW*GX_ZBUFH)*2) +#endif + + +static UINT8 *gx_objzbuf, *gx_shdzbuf; + + static int layer_colorbase[4]; static INT32 gx_tilebanks[8], gx_oldbanks[8]; static int gx_tilemode, gx_rozenable, psac_colorbase, last_psac_colorbase; @@ -41,6 +65,1712 @@ static rectangle gxtype1_roz_dstbitmapclip; static void (*game_tile_callback)(int layer, int *code, int *color, int *flags); +// Localized K053936/ROZ+ +#define K053936_MAX_CHIPS 2 + +static rectangle K053936_cliprect[K053936_MAX_CHIPS] = {{0,0,0,0},{0,0,0,0}}; +static int K053936_offset[K053936_MAX_CHIPS][2] = {{0,0},{0,0}}; +static int K053936_clip_enabled[K053936_MAX_CHIPS] = {0,0}; + + +void K053936GP_set_offset(int chip, int xoffs, int yoffs) { K053936_offset[chip][0] = xoffs; K053936_offset[chip][1] = yoffs; } + +void K053936GP_clip_enable(int chip, int status) { K053936_clip_enabled[chip] = status; } + +void K053936GP_set_cliprect(int chip, int minx, int maxx, int miny, int maxy) +{ + rectangle *cliprect = &K053936_cliprect[chip]; + cliprect->min_x = minx; + cliprect->max_x = maxx; + cliprect->min_y = miny; + cliprect->max_y = maxy; +} + +INLINE void K053936GP_copyroz32clip( running_machine *machine, + bitmap_t *dst_bitmap, bitmap_t *src_bitmap, + const rectangle *dst_cliprect, const rectangle *src_cliprect, + UINT32 _startx,UINT32 _starty,int _incxx,int _incxy,int _incyx,int _incyy, + int tilebpp, int blend, int alpha, int clip ) +{ + static const int colormask[8]={1,3,7,0xf,0x1f,0x3f,0x7f,0xff}; + + int cy, cx; + int ecx; + int src_pitch, incxy, incxx; + int src_minx, src_maxx, src_miny, src_maxy, cmask; + UINT16 *src_base; + size_t src_size; + + const pen_t *pal_base; + UINT32 *dst_ptr; + + int tx, dst_pitch; + UINT32 *dst_base; + int starty, incyy, startx, incyx, ty, sx, sy; + + incxy = _incxy; incxx = _incxx; incyy = _incyy; incyx = _incyx; + starty = _starty; startx = _startx; + + if (src_cliprect && clip) // set source clip range to some extreme values when disabled + { + src_minx = src_cliprect->min_x; + src_maxx = src_cliprect->max_x; + src_miny = src_cliprect->min_y; + src_maxy = src_cliprect->max_y; + } + // this simply isn't safe to do! + else { src_minx = src_miny = -0x10000; src_maxx = src_maxy = 0x10000; } + + if (dst_cliprect) // set target clip range + { + sx = dst_cliprect->min_x; + tx = dst_cliprect->max_x - sx + 1; + sy = dst_cliprect->min_y; + ty = dst_cliprect->max_y - sy + 1; + + startx += sx * incxx + sy * incyx; + starty += sx * incxy + sy * incyy; + } + else { sx = sy = 0; tx = dst_bitmap->width; ty = dst_bitmap->height; } + + // adjust entry points and other loop constants + dst_pitch = dst_bitmap->rowpixels; + dst_base = (UINT32*)dst_bitmap->base + sy * dst_pitch + sx + tx; + ecx = tx = -tx; + + tilebpp = (tilebpp-1) & 7; + pal_base = machine->pens; + cmask = colormask[tilebpp]; + + src_pitch = src_bitmap->rowpixels; + src_base = (UINT16 *)src_bitmap->base; + src_size = src_bitmap->width * src_bitmap->height; + + dst_ptr = dst_base; + cy = starty; + cx = startx; + + if (blend > 0) + { + dst_base += dst_pitch; // draw blended + starty += incyy; + startx += incyx; + + do { + do { + int srcx = (cx >> 16) & 0x1fff; + int srcy = (cy >> 16) & 0x1fff; + int pixel; + UINT32 offs; + offs = srcy * src_pitch + srcx; + + cx += incxx; + cy += incxy; + + if (offs<0 || offs>=src_size) + continue; + + if (srcx < src_minx || srcx > src_maxx || srcy < src_miny || srcy > src_maxy) + continue; + + pixel = src_base[offs]; + if (!(pixel & cmask)) + continue; + + dst_ptr[ecx] = alpha_blend_r32(pal_base[pixel], dst_ptr[ecx], alpha); + } + while (++ecx); + + ecx = tx; + dst_ptr = dst_base; dst_base += dst_pitch; + cy = starty; starty += incyy; + cx = startx; startx += incyx; + } while (--ty); + } + else // draw solid + { + if (blend == 0) + { + dst_base += dst_pitch; + starty += incyy; + startx += incyx; + } + else + { + if ((sy & 1) ^ (blend & 1)) + { + if (ty <= 1) return; + + dst_ptr += dst_pitch; + cy += incyy; + cx += incyx; + } + + if (ty > 1) + { + ty >>= 1; + dst_pitch <<= 1; + incyy <<= 1; + incyx <<= 1; + + dst_base = dst_ptr + dst_pitch; + starty = cy + incyy; + startx = cx + incyx; + } + } + + do { + do { + int srcx = (cx >> 16) & 0x1fff; + int srcy = (cy >> 16) & 0x1fff; + int pixel; + UINT32 offs; + + offs = srcy * src_pitch + srcx; + + cx += incxx; + cy += incxy; + + if (offs<0 || offs>=src_size) + continue; + + if (srcx < src_minx || srcx > src_maxx || srcy < src_miny || srcy > src_maxy) + continue; + + pixel = src_base[offs]; + if (!(pixel & cmask)) + continue; + + dst_ptr[ecx] = pal_base[pixel]; + } + while (++ecx); + + ecx = tx; + dst_ptr = dst_base; dst_base += dst_pitch; + cy = starty; starty += incyy; + cx = startx; startx += incyx; + } while (--ty); + } +} + +// adapted from generic K053936_zoom_draw() +static void K053936GP_zoom_draw(running_machine *machine, + int chip, UINT16 *ctrl, UINT16 *linectrl, + bitmap_t *bitmap, const rectangle *cliprect, tilemap *tmap, + int tilebpp, int blend, int alpha) +{ + bitmap_t *src_bitmap; + rectangle *src_cliprect; + UINT16 *lineaddr; + + rectangle my_clip; + UINT32 startx, starty; + int incxx, incxy, incyx, incyy, y, maxy, clip; + + src_bitmap = tilemap_get_pixmap(tmap); + src_cliprect = &K053936_cliprect[chip]; + clip = K053936_clip_enabled[chip]; + + if (ctrl[0x07] & 0x0040) /* "super" mode */ + { + my_clip.min_x = cliprect->min_x; + my_clip.max_x = cliprect->max_x; + y = cliprect->min_y; + maxy = cliprect->max_y; + + while (y <= maxy) + { + lineaddr = linectrl + ( ((y - K053936_offset[chip][1]) & 0x1ff) << 2); + my_clip.min_y = my_clip.max_y = y; + + startx = (INT16)(lineaddr[0] + ctrl[0x00]) << 8; + starty = (INT16)(lineaddr[1] + ctrl[0x01]) << 8; + incxx = (INT16)(lineaddr[2]); + incxy = (INT16)(lineaddr[3]); + + if (ctrl[0x06] & 0x8000) incxx <<= 8; + if (ctrl[0x06] & 0x0080) incxy <<= 8; + + startx -= K053936_offset[chip][0] * incxx; + starty -= K053936_offset[chip][0] * incxy; + + K053936GP_copyroz32clip(machine, + bitmap, src_bitmap, &my_clip, src_cliprect, + startx<<5, starty<<5, incxx<<5, incxy<<5, 0, 0, + tilebpp, blend, alpha, clip); + y++; + } + } + else /* "simple" mode */ + { + startx = (INT16)(ctrl[0x00]) << 8; + starty = (INT16)(ctrl[0x01]) << 8; + incyx = (INT16)(ctrl[0x02]); + incyy = (INT16)(ctrl[0x03]); + incxx = (INT16)(ctrl[0x04]); + incxy = (INT16)(ctrl[0x05]); + + if (ctrl[0x06] & 0x4000) { incyx <<= 8; incyy <<= 8; } + if (ctrl[0x06] & 0x0040) { incxx <<= 8; incxy <<= 8; } + + startx -= K053936_offset[chip][1] * incyx; + starty -= K053936_offset[chip][1] * incyy; + + startx -= K053936_offset[chip][0] * incxx; + starty -= K053936_offset[chip][0] * incxy; + + K053936GP_copyroz32clip(machine, + bitmap, src_bitmap, cliprect, src_cliprect, + startx<<5, starty<<5, incxx<<5, incxy<<5, incyx<<5, incyy<<5, + tilebpp, blend, alpha, clip); + } +} + +void K053936GP_0_zoom_draw(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, + tilemap *tmap, int tilebpp, int blend, int alpha) +{ + K053936GP_zoom_draw(machine, 0,K053936_0_ctrl,K053936_0_linectrl,bitmap,cliprect,tmap,tilebpp,blend,alpha); +} + +void K053936GP_1_zoom_draw(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, + tilemap *tmap, int tilebpp, int blend, int alpha) +{ + K053936GP_zoom_draw(machine, 1,K053936_1_ctrl,K053936_1_linectrl,bitmap,cliprect,tmap,tilebpp,blend,alpha); +} + + + +/* + Parameter Notes + --------------- + clip : *caller must supply a pointer to target clip rectangle + alpha : 0 = invisible, 255 = solid + drawmode: + 0 = all pens solid + 1 = solid pens only + 2 = all pens solid with alpha blending + 3 = solid pens only with alpha blending + 4 = shadow pens only + 5 = all pens shadow + zcode : 0 = closest, 255 = furthest (pixel z-depth), -1 = disable depth buffers and shadows + pri : 0 = topmost, 255 = backmost (pixel priority) +*/ + + +INLINE void zdrawgfxzoom32GP( + bitmap_t *bitmap, const rectangle *cliprect, const gfx_element *gfx, + UINT32 code, UINT32 color, int flipx, int flipy, int sx, int sy, + int scalex, int scaley, int alpha, int drawmode, int zcode, int pri) +{ +#define FP 19 +#define FPONE (1<color_granularity; + shdpen--; + + if (zcode >= 0) + { + if (drawmode == 5) { drawmode = 4; shdpen = 1; } + } + else + if (drawmode >= 4) return; + + // alpha blend necessary? + if (drawmode & 2) + { + if (alpha <= 0) return; + if (alpha >= 255) drawmode &= ~2; + } + + // fill internal data structure with default values + ozbuf_ptr = gx_objzbuf; + szbuf_ptr = gx_shdzbuf; + + src_pitch = 16; + src_fw = 16; + src_fh = 16; + src_base = gfx_element_get_data(gfx, code % gfx->total_elements); + + pal_base = gfx->machine->pens + gfx->color_base + (color % gfx->total_colors) * granularity; + shd_base = gfx->machine->shadow_table; + + dst_ptr = (UINT32 *)bitmap->base; + dst_pitch = bitmap->rowpixels; + dst_minx = cliprect->min_x; + dst_maxx = cliprect->max_x; + dst_miny = cliprect->min_y; + dst_maxy = cliprect->max_y; + dst_x = sx; + dst_y = sy; + + // cull off-screen objects + if (dst_x > dst_maxx || dst_y > dst_maxy) return; + nozoom = (scalex == 0x10000 && scaley == 0x10000); + if (nozoom) + { + dst_h = dst_w = 16; + src_fdy = src_fdx = 1; + } + else + { + dst_w = ((scalex<<4)+0x8000)>>16; + dst_h = ((scaley<<4)+0x8000)>>16; + if (!dst_w || !dst_h) return; + + src_fw <<= FP; + src_fh <<= FP; + src_fdx = src_fw / dst_w; + src_fdy = src_fh / dst_h; + } + dst_lastx = dst_x + dst_w - 1; + if (dst_lastx < dst_minx) return; + dst_lasty = dst_y + dst_h - 1; + if (dst_lasty < dst_miny) return; + + // clip destination + dst_skipx = 0; + eax = dst_minx; if ((eax -= dst_x) > 0) { dst_skipx = eax; dst_w -= eax; dst_x = dst_minx; } + eax = dst_lastx; if ((eax -= dst_maxx) > 0) dst_w -= eax; + dst_skipy = 0; + eax = dst_miny; if ((eax -= dst_y) > 0) { dst_skipy = eax; dst_h -= eax; dst_y = dst_miny; } + eax = dst_lasty; if ((eax -= dst_maxy) > 0) dst_h -= eax; + + // calculate zoom factors and clip source + if (nozoom) + { + if (!flipx) src_fbx = 0; else { src_fbx = src_fw - 1; src_fdx = -src_fdx; } + if (!flipy) src_fby = 0; else { src_fby = src_fh - 1; src_fdy = -src_fdy; src_pitch = -src_pitch; } + } + else + { + if (!flipx) src_fbx = FPENT; else { src_fbx = src_fw - FPENT - 1; src_fdx = -src_fdx; } + if (!flipy) src_fby = FPENT; else { src_fby = src_fh - FPENT - 1; src_fdy = -src_fdy; } + } + src_fbx += dst_skipx * src_fdx; + src_fby += dst_skipy * src_fdy; + + // adjust insertion points and pre-entry constants + eax = (dst_y - dst_miny) * GX_ZBUFW + (dst_x - dst_minx) + dst_w; + db0 = z8 = (UINT8)zcode; + db1 = p8 = (UINT8)pri; + ozbuf_ptr += eax; + szbuf_ptr += eax << 1; + dst_ptr += dst_y * dst_pitch + dst_x + dst_w; + dst_w = -dst_w; + + if (!nozoom) + { + ecx = src_fby; src_fby += src_fdy; + ecx >>= FP; src_fx = src_fbx; + src_x = src_fbx; src_fx += src_fdx; + ecx <<= 4; src_ptr = src_base; + src_x >>= FP; src_ptr += ecx; + ecx = dst_w; + + if (zcode < 0) // no shadow and z-buffering + { + do { + do { + eax = src_ptr[src_x]; + src_x = src_fx; + src_fx += src_fdx; + src_x >>= FP; + if (!eax || eax >= shdpen) continue; + dst_ptr [ecx] = pal_base[eax]; + } + while (++ecx); + + ecx = src_fby; src_fby += src_fdy; + dst_ptr += dst_pitch; + ecx >>= FP; src_fx = src_fbx; + src_x = src_fbx; src_fx += src_fdx; + ecx <<= 4; src_ptr = src_base; + src_x >>= FP; src_ptr += ecx; + ecx = dst_w; + } + while (--dst_h); + } + else + { + switch (drawmode) + { + case 0: // all pens solid + do { + do { + eax = src_ptr[src_x]; + src_x = src_fx; + src_fx += src_fdx; + src_x >>= FP; + if (!eax || ozbuf_ptr[ecx] < z8) continue; + eax = pal_base[eax]; + ozbuf_ptr[ecx] = z8; + dst_ptr [ecx] = eax; + } + while (++ecx); + + ecx = src_fby; src_fby += src_fdy; + ozbuf_ptr += GX_ZBUFW; + dst_ptr += dst_pitch; + ecx >>= FP; src_fx = src_fbx; + src_x = src_fbx; src_fx += src_fdx; + ecx <<= 4; src_ptr = src_base; + src_x >>= FP; src_ptr += ecx; + ecx = dst_w; + } + while (--dst_h); + break; + + case 1: // solid pens only + do { + do { + eax = src_ptr[src_x]; + src_x = src_fx; + src_fx += src_fdx; + src_x >>= FP; + if (!eax || eax >= shdpen || ozbuf_ptr[ecx] < z8) continue; + eax = pal_base[eax]; + ozbuf_ptr[ecx] = z8; + dst_ptr [ecx] = eax; + } + while (++ecx); + + ecx = src_fby; src_fby += src_fdy; + ozbuf_ptr += GX_ZBUFW; + dst_ptr += dst_pitch; + ecx >>= FP; src_fx = src_fbx; + src_x = src_fbx; src_fx += src_fdx; + ecx <<= 4; src_ptr = src_base; + src_x >>= FP; src_ptr += ecx; + ecx = dst_w; + } + while (--dst_h); + break; + + case 2: // all pens solid with alpha blending + do { + do { + eax = src_ptr[src_x]; + src_x = src_fx; + src_fx += src_fdx; + src_x >>= FP; + if (!eax || ozbuf_ptr[ecx] < z8) continue; + ozbuf_ptr[ecx] = z8; + + dst_ptr[ecx] = alpha_blend_r32(pal_base[eax], dst_ptr[ecx], alpha); + } + while (++ecx); + + ecx = src_fby; src_fby += src_fdy; + ozbuf_ptr += GX_ZBUFW; + dst_ptr += dst_pitch; + ecx >>= FP; src_fx = src_fbx; + src_x = src_fbx; src_fx += src_fdx; + ecx <<= 4; src_ptr = src_base; + src_x >>= FP; src_ptr += ecx; + ecx = dst_w; + } + while (--dst_h); + break; + + case 3: // solid pens only with alpha blending + do { + do { + eax = src_ptr[src_x]; + src_x = src_fx; + src_fx += src_fdx; + src_x >>= FP; + if (!eax || eax >= shdpen || ozbuf_ptr[ecx] < z8) continue; + ozbuf_ptr[ecx] = z8; + + dst_ptr[ecx] = alpha_blend_r32(pal_base[eax], dst_ptr[ecx], alpha); + } + while (++ecx); + + ecx = src_fby; src_fby += src_fdy; + ozbuf_ptr += GX_ZBUFW; + dst_ptr += dst_pitch; + ecx >>= FP; src_fx = src_fbx; + src_x = src_fbx; src_fx += src_fdx; + ecx <<= 4; src_ptr = src_base; + src_x >>= FP; src_ptr += ecx; + ecx = dst_w; + } + while (--dst_h); + break; + + case 4: // shadow pens only + do { + do { + eax = src_ptr[src_x]; + src_x = src_fx; + src_fx += src_fdx; + src_x >>= FP; + if (eax < shdpen || szbuf_ptr[ecx*2] < z8 || szbuf_ptr[ecx*2+1] <= p8) continue; + eax = dst_ptr[ecx]; + szbuf_ptr[ecx*2] = z8; + szbuf_ptr[ecx*2+1] = p8; + + // the shadow tables are 15-bit lookup tables which accept RGB15... lossy, nasty, yuck! + dst_ptr[ecx] = shd_base[rgb_to_rgb15(eax)]; + //dst_ptr[ecx] =(eax>>3&0x001f);lend_r32( eax, 0x00000000, 128); + } + while (++ecx); + + ecx = src_fby; src_fby += src_fdy; + szbuf_ptr += (GX_ZBUFW<<1); + dst_ptr += dst_pitch; + ecx >>= FP; src_fx = src_fbx; + src_x = src_fbx; src_fx += src_fdx; + ecx <<= 4; src_ptr = src_base; + src_x >>= FP; src_ptr += ecx; + ecx = dst_w; + } + while (--dst_h); + break; + } // switch (drawmode) + } // if (zcode < 0) + } // if (!nozoom) + else + { + src_ptr = src_base + (src_fby<<4) + src_fbx; + src_fdy = src_fdx * dst_w + src_pitch; + ecx = dst_w; + + if (zcode < 0) // no shadow and z-buffering + { + do { + do { + eax = *src_ptr; + src_ptr += src_fdx; + if (!eax || eax >= shdpen) continue; + dst_ptr[ecx] = pal_base[eax]; + } + while (++ecx); + + src_ptr += src_fdy; + dst_ptr += dst_pitch; + ecx = dst_w; + } + while (--dst_h); + } + else + { + switch (drawmode) + { + case 0: // all pens solid + do { + do { + eax = *src_ptr; + src_ptr += src_fdx; + if (!eax || ozbuf_ptr[ecx] < z8) continue; + eax = pal_base[eax]; + ozbuf_ptr[ecx] = z8; + dst_ptr[ecx] = eax; + } + while (++ecx); + + src_ptr += src_fdy; + ozbuf_ptr += GX_ZBUFW; + dst_ptr += dst_pitch; + ecx = dst_w; + } + while (--dst_h); + break; + + case 1: // solid pens only + do { + do { + eax = *src_ptr; + src_ptr += src_fdx; + if (!eax || eax >= shdpen || ozbuf_ptr[ecx] < z8) continue; + eax = pal_base[eax]; + ozbuf_ptr[ecx] = z8; + dst_ptr[ecx] = eax; + } + while (++ecx); + + src_ptr += src_fdy; + ozbuf_ptr += GX_ZBUFW; + dst_ptr += dst_pitch; + ecx = dst_w; + } + while (--dst_h); + break; + + case 2: // all pens solid with alpha blending + do { + do { + eax = *src_ptr; + src_ptr += src_fdx; + if (!eax || ozbuf_ptr[ecx] < z8) continue; + ozbuf_ptr[ecx] = z8; + + dst_ptr[ecx] = alpha_blend_r32(pal_base[eax], dst_ptr[ecx], alpha); + } + while (++ecx); + + src_ptr += src_fdy; + ozbuf_ptr += GX_ZBUFW; + dst_ptr += dst_pitch; + ecx = dst_w; + } + while (--dst_h); + break; + + case 3: // solid pens only with alpha blending + do { + do { + eax = *src_ptr; + src_ptr += src_fdx; + if (!eax || eax >= shdpen || ozbuf_ptr[ecx] < z8) continue; + ozbuf_ptr[ecx] = z8; + + dst_ptr[ecx] = alpha_blend_r32(pal_base[eax], dst_ptr[ecx], alpha); + } + while (++ecx); + + src_ptr += src_fdy; + ozbuf_ptr += GX_ZBUFW; + dst_ptr += dst_pitch; + ecx = dst_w; + } + while (--dst_h); + break; + + case 4: // shadow pens only + do { + do { + eax = *src_ptr; + src_ptr += src_fdx; + if (eax < shdpen || szbuf_ptr[ecx*2] < z8 || szbuf_ptr[ecx*2+1] <= p8) continue; + eax = dst_ptr[ecx]; + szbuf_ptr[ecx*2] = z8; + szbuf_ptr[ecx*2+1] = p8; + + // the shadow tables are 15-bit lookup tables which accept RGB15... lossy, nasty, yuck! + dst_ptr[ecx] = shd_base[rgb_to_rgb15(eax)]; + } + while (++ecx); + + src_ptr += src_fdy; + szbuf_ptr += (GX_ZBUFW<<1); + dst_ptr += dst_pitch; + ecx = dst_w; + } + while (--dst_h); + break; + } + } + } +#undef FP +#undef FPONE +#undef FPHALF +#undef FPENT +} + + + +/***************************************************************************/ +/* */ +/* 1st-Tier GX/MW Variables and Functions */ +/* */ +/***************************************************************************/ + +// global system ports access +UINT8 konamigx_wrport1_0, konamigx_wrport1_1; +UINT16 konamigx_wrport2; + +// frequently used registers +static int K053246_objset1; +static int K053247_vrcbk[4]; +static int K053247_coreg, K053247_coregshift, K053247_opset; +static int opri, oinprion; +static int vcblk[6], ocblk; +static int vinmix, vmixon, osinmix, osmixon; + + +static void konamigx_precache_registers(void) +{ + // (see sprite color coding scheme on p.46 & 47) + static const int coregmasks[5] = {0xf,0xe,0xc,0x8,0x0}; + static const int coregshifts[5]= {4,5,6,7,8}; + int i; + + K053246_objset1 = K053246_read_register(5); + + i = K053247_read_register(0x8/2); + K053247_vrcbk[0] = (i & 0x000f) << 14; + K053247_vrcbk[1] = (i & 0x0f00) << 6; + i = K053247_read_register(0xa/2); + K053247_vrcbk[2] = (i & 0x000f) << 14; + K053247_vrcbk[3] = (i & 0x0f00) << 6; + + // COREG == OBJSET2+1C == bit8-11 of OPSET ??? (see p.50 last table, needs p.49 to confirm) + K053247_opset = K053247_read_register(0xc/2); + + i = K053247_opset & 7; if (i > 4) i = 4; + + K053247_coreg = K053247_read_register(0xc/2)>>8 & 0xf; + K053247_coreg =(K053247_coreg & coregmasks[i]) << 12; + + K053247_coregshift = coregshifts[i]; + + opri = K055555_read_register(K55_PRIINP_8); + oinprion = K055555_read_register(K55_OINPRI_ON); + vcblk[0] = K055555_read_register(K55_PALBASE_A); + vcblk[1] = K055555_read_register(K55_PALBASE_B); + vcblk[2] = K055555_read_register(K55_PALBASE_C); + vcblk[3] = K055555_read_register(K55_PALBASE_D); + vcblk[4] = K055555_read_register(K55_PALBASE_SUB1); + vcblk[5] = K055555_read_register(K55_PALBASE_SUB2); + ocblk = K055555_read_register(K55_PALBASE_OBJ); + vinmix = K055555_read_register(K55_BLEND_ENABLES); + vmixon = K055555_read_register(K55_VINMIX_ON); + osinmix = K055555_read_register(K55_OSBLEND_ENABLES); + osmixon = K055555_read_register(K55_OSBLEND_ON); +} + +INLINE int K053247GX_combine_c18(int attrib) // (see p.46) +{ + int c18; + + c18 = (attrib & 0xff)<> K053247_coregshift); +} + +INLINE int K055555GX_decode_inpri(int c18) // (see p.59 7.2.2) +{ + int op = opri; + + c18 >>= 8; + op &= oinprion; + c18 &=~oinprion; + + return(c18 | op); +} + +void konamigx_type2_sprite_callback(int *code, int *color, int *priority) +{ + int num = *code; + int c18 = *color; + + *code = K053247_vrcbk[num>>14] | (num & 0x3fff); + c18 = K053247GX_combine_c18(c18); + *color = K055555GX_decode_objcolor(c18); + *priority = K055555GX_decode_inpri(c18); +} + +void konamigx_dragoonj_sprite_callback(int *code, int *color, int *priority) +{ + int num, op, pri, c18; + + num = *code; + *code = K053247_vrcbk[num>>14] | (num & 0x3fff); + + c18 = pri = *color; + op = opri; + pri = (pri & 0x200) ? 4 : pri>>4 & 0xf; + op &= oinprion; + pri &=~oinprion; + *priority = pri | op; + + c18 = K053247GX_combine_c18(c18); + *color = K055555GX_decode_objcolor(c18); +} + +void konamigx_salmndr2_sprite_callback(int *code, int *color, int *priority) +{ + int num, op, pri, c18; + + num = *code; + *code = K053247_vrcbk[num>>14] | (num & 0x3fff); + + c18 = pri = *color; + op = opri; + pri = pri>>4 & 0x3f; + op &= oinprion; + pri &=~oinprion; + *priority = pri | op; + + c18 = K053247GX_combine_c18(c18); + *color = K055555GX_decode_objcolor(c18); +} + +void konamigx_le2_sprite_callback(int *code, int *color, int *priority) +{ + int num, op, pri; + + num = *code; + *code = K053247_vrcbk[num>>14] | (num & 0x3fff); + + pri = *color; + *color &= 0x1f; + + op = opri; + pri &= 0xf0; + op &= oinprion; + pri &=~oinprion; + *priority = pri | op; +} + +int K055555GX_decode_vmixcolor(int layer, int *color) // (see p.62 7.2.6 and p.27 3.3) +{ + int vcb, shift, pal, vmx, von, pl45, emx; + + vcb = vcblk[layer]<<6; + shift = layer<<1; + pal = *color; + vmx = vinmix>>shift & 3; + von = vmixon>>shift & 3; + emx = pl45 = pal>>4 & 3; + pal &= 0xf; + pl45 &= von; + vmx &= von; + pl45 <<= 4; + emx &= ~von; + pal |= pl45; + emx |= vmx; + pal |= vcb; + + if (von == 3) emx = -1; // invalidate external mix code if all bits are from internal + *color = pal; + + return(emx); +} + +int K055555GX_decode_osmixcolor(int layer, int *color) // (see p.63, p.49-50 and p.27 3.3) +{ + int scb, shift, pal, osmx, oson, pl45, emx; + + shift = layer<<1; + pal = *color; + osmx = osinmix>>shift & 3; + oson = osmixon>>shift & 3; + + if (layer) + { + // layer 1-3 are external tile layers + scb = vcblk[layer+3]<<6; + emx = pl45 = pal>>4 & 3; + pal &= 0xf; + pl45 &= oson; + osmx &= oson; + pl45 <<= 4; + emx &= ~oson; + pal |= pl45; + emx |= osmx; + pal |= scb; + + if (oson == 3) emx = -1; // invalidate external mix code if all bits are from internal + *color = pal; + } + else + { + // layer 0 is the sprite layer with different attributes decode; detail on p.49 (missing) + emx = 0; // K053247_read_register(??)>>? & 3; + osmx &= oson; + emx &=~oson; + emx |= osmx; + } + + return(emx); +} + +static void gx_wipezbuf(running_machine *machine, int noshadow) +{ + const rectangle *visarea = video_screen_get_visible_area(machine->primary_screen); + + int w = visarea->max_x - visarea->min_x + 1; + int h = visarea->max_y - visarea->min_y + 1; + + UINT8 *zptr = gx_objzbuf; + int ecx = h; + + do { memset(zptr, -1, w); zptr += GX_ZBUFW; } while (--ecx); + + if (!noshadow) + { + zptr = gx_shdzbuf; + w <<= 1; + ecx = h; + do { memset(zptr, -1, w); zptr += (GX_ZBUFW<<1); } while (--ecx); + } +} + +/* + * Sprite Format + * ------------------ + * + * Word | Bit(s) | Use + * -----+-fedcba9876543210-+---------------- + * 0 | x--------------- | active (show this sprite) + * 0 | -x-------------- | maintain aspect ratio (when set, zoom y acts on both axis) + * 0 | --x------------- | flip y + * 0 | ---x------------ | flip x + * 0 | ----xxxx-------- | sprite size (see below) + * 0 | --------xxxxxxxx | zcode + * 1 | xxxxxxxxxxxxxxxx | sprite code + * 2 | ------xxxxxxxxxx | y position + * 3 | ------xxxxxxxxxx | x position + * 4 | xxxxxxxxxxxxxxxx | zoom y (0x40 = normal, <0x40 = enlarge, >0x40 = reduce) + * 5 | xxxxxxxxxxxxxxxx | zoom x (0x40 = normal, <0x40 = enlarge, >0x40 = reduce) + * 6 | x--------------- | mirror y (top half is drawn as mirror image of the bottom) + * 6 | -x-------------- | mirror x (right half is drawn as mirror image of the left) + * 6 | --xx------------ | reserved (sprites with these two bits set don't seem to be graphics data at all) + * 6 | ----xx---------- | shadow code: 0=off, 0x400=preset1, 0x800=preset2, 0xc00=preset3 + * 6 | ------xx-------- | effect code: flicker, upper palette, full shadow...etc. (game dependent) + * 6 | --------xxxxxxxx | "color", but depends on external connections (implies priority) + * 7 | xxxxxxxxxxxxxxxx | game dependent + * + * shadow enables transparent shadows. Note that it applies to the last sprite pen ONLY. + * The rest of the sprite remains normal. + */ +#define GX_MAX_SPRITES 512 +#define GX_MAX_LAYERS 6 +#define GX_MAX_OBJECTS (GX_MAX_SPRITES + GX_MAX_LAYERS) + +static struct GX_OBJ { int order, offs, code, color; } *gx_objpool; +static UINT16 *gx_spriteram; +static int gx_objdma, gx_primode; + +// mirrored K053247 and K054338 settings +UINT16 *K053247_ram; +static gfx_element *K053247_gfx; +static void (*K053247_callback)(int *code,int *color,int *priority); +static int K053247_dx, K053247_dy; + +static int *K054338_shdRGB; + + +void K053247GP_set_SpriteOffset(int offsx, int offsy) +{ + K053247_dx = offsx; + K053247_dy = offsy; +} + +void konamigx_mixer_init(running_machine *machine, int objdma) +{ + gx_objdma = 0; + gx_primode = 0; + + gx_objzbuf = (UINT8 *)machine->priority_bitmap->base; + gx_shdzbuf = auto_alloc_array(machine, UINT8, GX_ZBUFSIZE); + gx_objpool = auto_alloc_array(machine, struct GX_OBJ, GX_MAX_OBJECTS); + + K053247_export_config(&K053247_ram, &K053247_gfx, &K053247_callback, &K053247_dx, &K053247_dy); + K054338_export_config(&K054338_shdRGB); + + if (objdma) + { + gx_spriteram = auto_alloc_array(machine, UINT16, 0x1000/2); + gx_objdma = 1; + } + else + gx_spriteram = K053247_ram; + + palette_set_shadow_dRGB32(machine, 3,-80,-80,-80, 0); + K054338_invert_alpha(1); +} + +void konamigx_mixer_primode(int mode) +{ + gx_primode = mode; +} + +void konamigx_objdma(void) +{ + if (gx_objdma && gx_spriteram && K053247_ram) memcpy(gx_spriteram, K053247_ram, 0x1000); +} + +void konamigx_mixer(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, + tilemap *sub1, int sub1flags, + tilemap *sub2, int sub2flags, + int mixerflags, bitmap_t *extra_bitmap, int rushingheroes_hack) +{ + static const int xoffset[8] = { 0, 1, 4, 5, 16, 17, 20, 21 }; + static const int yoffset[8] = { 0, 2, 8, 10, 32, 34, 40, 42 }; + static int parity = 0; + + int objbuf[GX_MAX_OBJECTS]; + int shadowon[3], shdpri[3], layerid[6], layerpri[6]; + + struct GX_OBJ *objpool, *objptr; + int wrapsize, xwraplim, ywraplim, cltc_shdpri, prflp, disp; + int xa,ya,ox,oy,zw,zh,flipx,flipy,mirrorx,mirrory,zoomx,zoomy,scalex,scaley,nozoom; + int screenwidth, flipscreenx, flipscreeny, offx, offy; + int nobj, i, j, k, l, temp, temp1, temp2, temp3, temp4, count; + int order, offs, code, color, zcode, pri = 0, spri, spri_min, shdprisel, shadow, alpha, drawmode; + + + // abort if object database failed to initialize + objpool = gx_objpool; + if (!objpool) return; + + // clear screen with backcolor and update flicker pulse + K054338_fill_backcolor(machine, bitmap, konamigx_wrport1_0 & 0x20); + parity ^= 1; + + // abort if video has been disabled + disp = K055555_read_register(K55_INPUT_ENABLES); + if (!disp) return; + cltc_shdpri = K054338_read_register(K338_REG_CONTROL); + + if (!rushingheroes_hack) // Slam Dunk 2 never sets this. It's either part of the protection, or type4 doesn't use it + { + if (!(cltc_shdpri & K338_CTL_KILL)) return; + } + + // demote shadows by one layer when this bit is set??? (see p.73 8.6) + cltc_shdpri &= K338_CTL_SHDPRI; + + // wipe z-buffer + if (mixerflags & GXMIX_NOZBUF) + mixerflags |= GXMIX_NOSHADOW; + else + gx_wipezbuf(machine, mixerflags & GXMIX_NOSHADOW); + + // cache global parameters + konamigx_precache_registers(); + + // init OBJSET1 parameters (see p.47 6.2) + flipscreenx = K053246_objset1 & 1; + flipscreeny = K053246_objset1 & 2; + + // get "display window" offsets + offx = (K053246_read_register(0)<<8 | K053246_read_register(1)) & 0x3ff; + offy = (K053246_read_register(2)<<8 | K053246_read_register(3)) & 0x3ff; + + // init OBJSET2 and mixer parameters (see p.51 and chapter 7) + layerid[0] = 0; layerid[1] = 1; layerid[2] = 2; layerid[3] = 3; layerid[4] = 4; layerid[5] = 5; + + if (K053247_opset & 0x40) + { + wrapsize = 512; + xwraplim = 512 - 64; + ywraplim = 512 - 128; + } + else + { + wrapsize = 1024; + xwraplim = 1024 - 384; + ywraplim = 1024 - 512; + } + + // invert layer priority when this flag is set (not used by any GX game?) + prflp = K055555_read_register(K55_CONTROL) & K55_CTL_FLIPPRI; + + layerpri[0] = K055555_read_register(K55_PRIINP_0); + layerpri[1] = K055555_read_register(K55_PRIINP_3); + layerpri[3] = K055555_read_register(K55_PRIINP_7); + layerpri[4] = K055555_read_register(K55_PRIINP_9); + layerpri[5] = K055555_read_register(K55_PRIINP_10); + + if (gx_primode == -1) + { + // Lethal Enforcer hack (requires pixel color comparison) + layerpri[2] = K055555_read_register(K55_PRIINP_3) + 0x20; + shdprisel = 0x3f; + } + else + { + layerpri[2] = K055555_read_register(K55_PRIINP_6); + shdprisel = K055555_read_register(K55_SHD_PRI_SEL); + } + + // SHDPRISEL filters shadows by different priority comparison methods (UNIMPLEMENTED, see detail on p.66) + if (!(shdprisel & 0x03)) shadowon[0] = 0; + if (!(shdprisel & 0x0c)) shadowon[1] = 0; + if (!(shdprisel & 0x30)) shadowon[2] = 0; + + shdpri[0] = K055555_read_register(K55_SHAD1_PRI); + shdpri[1] = K055555_read_register(K55_SHAD2_PRI); + shdpri[2] = K055555_read_register(K55_SHAD3_PRI); + + spri_min = 0; + shadowon[2] = shadowon[1] = shadowon[0] = 0; + + if (!(mixerflags & GXMIX_NOSHADOW)) + { + // only enable shadows beyond a +/-7 RGB threshold + for (j=0,i=0; i<3; j+=3,i++) + { + k = K054338_shdRGB[j ]; if (k < -7 || k > 7) { shadowon[i] = 1; continue; } + k = K054338_shdRGB[j+1]; if (k < -7 || k > 7) { shadowon[i] = 1; continue; } + k = K054338_shdRGB[j+2]; if (k < -7 || k > 7) { shadowon[i] = 1; } + } + + // SHDON specifies layers on which shadows can be projected (see detail on p.65 7.2.8) + temp = K055555_read_register(K55_SHD_ON); + for (i=0; i<4; i++) if (!(temp>>i & 1) && spri_min < layerpri[i]) spri_min = layerpri[i]; // HACK + + // update shadows status + K054338_update_all_shadows(machine, rushingheroes_hack); + } + + // pre-sort layers + for (j=0; j<5; j++) + { + temp1 = layerpri[j]; + for (i=j+1; i<6; i++) + { + temp2 = layerpri[i]; + if ((UINT32)temp1 <= (UINT32)temp2) + { + layerpri[i] = temp1; layerpri[j] = temp1 = temp2; + temp2 = layerid[i]; layerid[i] = layerid[j]; layerid[j] = temp2; + } + } + } + + // build object database and create indices + objptr = objpool; + nobj = 0; + + for (i=5; i>=0; i--) + { + code = layerid[i]; + switch (code) + { + /* + Background layers are represented by negative offset values as follow: + + 0+ : normal sprites + -1 : tile layer A - D + -2 : K053936 ROZ+ layer 1 + -3 : K053936 ROZ+ layer 2 + -4 : K053250 LVC layer 1 + -5 : K053250 LVC layer 2 + */ + case 4 : + offs = -128; + if (sub1flags & 0xf) { if (sub1flags & GXSUB_K053250) offs = -4; else if (sub1) offs = -2; } + break; + case 5 : + offs = -128; + if (sub2flags & 0xf) { if (sub2flags & GXSUB_K053250) offs = -5; else if (sub2) offs = -3; } + if (extra_bitmap) offs = -3; + break; + default: offs = -1; + } + + if (offs != -128) + { + objptr->order = layerpri[i]<<24; + objptr->code = code; + objptr->offs = offs; + objptr++; + + objbuf[nobj] = nobj; + nobj++; + } + } + + i = j = 0xff; + + for (offs=0; offs<0x800; offs+=8) + { + if (!(gx_spriteram[offs] & 0x8000)) continue; + + zcode = gx_spriteram[offs] & 0xff; + + // invert z-order when opset_pri is set (see p.51 OPSET PRI) + if (K053247_opset & 0x10) zcode = 0xff - zcode; + + code = gx_spriteram[offs+1]; + color = k = gx_spriteram[offs+6]; + l = gx_spriteram[offs+7]; + + (*K053247_callback)(&code, &color, &pri); + + /* + shadow = shadow code + spri = shadow priority + temp1 = add solid object + temp2 = solid pens draw mode + temp3 = add shadow object + temp4 = shadow pens draw mode + */ + temp4 = temp3 = temp2 = temp1 = spri = shadow = 0; + + if (color & K055555_FULLSHADOW) + { + shadow = 3; // use default intensity and color + spri = pri; // retain host priority + temp3 = 1; // add shadow + temp4 = 5; // draw full shadow + } + else + { + shadow = k>>10 & 3; + if (shadow) // object has shadow? + { + if (shadow != 1 || K053246_objset1 & 0x20) + { + shadow--; + temp1 = 1; // add solid + temp2 = 1; // draw partial solid + if (shadowon[shadow]) + { + temp3 = 1; // add shadow + temp4 = 4; // draw partial shadow + } + } + else + { + // drop the entire sprite to shadow if its shadow code is 1 and SD0EN is off (see p.48) + shadow = 0; + if (!shadowon[0]) continue; + temp3 = 1; // add shadow + temp4 = 5; // draw full shadow + } + } + else + { + temp1 = 1; // add solid + temp2 = 0; // draw full solid + } + + if (temp1) + { + // tag sprite for alpha blending + if (color>>K055555_MIXSHIFT & 3) temp2 |= 2; + } + + if (temp3) + { + // determine shadow priority + spri = (K053247_opset & 0x20) ? pri : shdpri[shadow]; // (see p.51 OPSET SDSEL) + } + } + + switch (gx_primode & 0xf) + { + // Dadandarn zcode suppression + case 1: + zcode = 0; + break; + + // Daisukiss bad shadow filter + case 4: + if (k & 0x3000 || k == 0x0800) continue; + + // Tokkae shadow masking (INACCURATE) + case 5: + if (spri < spri_min) spri = spri_min; + break; + } + + /* + default sort order: + fedcba9876543210fedcba9876543210 + xxxxxxxx------------------------ (priority) + --------xxxxxxxx---------------- (zcode) + ----------------xxxxxxxx-------- (offset) + ------------------------xxxx---- (shadow mode) + ----------------------------xxxx (shadow code) + */ + if (temp1) + { + // add objects with solid or alpha pens + order = pri<<24 | zcode<<16 | offs<<(8-3) | temp2<<4; + objptr->order = order; + objptr->offs = offs; + objptr->code = code; + objptr->color = color; + objptr++; + + objbuf[nobj] = nobj; + nobj++; + } + + if (temp3 && !(color & K055555_SKIPSHADOW) && !(mixerflags & GXMIX_NOSHADOW)) + { + // add objects with shadows if enabled + order = spri<<24 | zcode<<16 | offs<<(8-3) | temp4<<4 | shadow; + objptr->order = order; + objptr->offs = offs; + objptr->code = code; + objptr->color = color; + objptr++; + + objbuf[nobj] = nobj; + nobj++; + } + } + + // sort objects in decending order (SLOW) + k = nobj; + l = nobj - 1; + + for (j=0; jprimary_screen); + + for (count=0; countorder; + offs = objptr->offs; + code = objptr->code; + color = objptr->color; + + if (offs >= 0) + { + if (!(disp & K55_INP_OBJ)) continue; + } + else + { + i = code<<1; + j = mixerflags>>i & 3; + k = 0; + + switch (offs) + { + case -1: + if (disp & (1<>(i+16); temp3 = 3; } + else + { + temp1 = vinmix; + temp2 = vinmix>>i & 3; + temp3 = vmixon>>i & 3; + } + + /* blend layer only when: + 1) vinmix != 0xff + 2) its internal mix code is set + 3) all mix code bits are internal(overriden until tile blending has been implemented) + 4) 0 > alpha < 255; + */ + if (temp1!=0xff && temp2 /*&& temp3==3*/) + { + temp4 = K054338_set_alpha_level(temp2); + + if (temp4 <= 0) continue; + if (temp4 < 255) k = TILEMAP_DRAW_ALPHA(temp4); + } + + if (mixerflags & 1<<(code+12)) k |= K056382_DRAW_FLAG_FORCE_XYSCROLL; + + K056832_tilemap_draw(machine, bitmap, cliprect, code, k, 0); + } + continue; + case -2: + case -4: + if ((disp & K55_INP_SUB1) || (rushingheroes_hack)) + { + int alpha = 255; + + if (j == GXMIX_BLEND_NONE) { temp1 = 0xff; temp2 = temp3 = 0; } else + if (j == GXMIX_BLEND_FORCE) { temp1 = 0x00; temp2 = mixerflags>>24; temp3 = 3; } + else + { + temp1 = osinmix; + temp2 = osinmix>>2 & 3; + temp3 = osmixon>>2 & 3; + } + + if (temp1!=0xff && temp2 /*&& temp3==3*/) + { + alpha = temp4 = K054338_set_alpha_level(temp2); + + if (temp4 <= 0) continue; + if (temp4 < 255) k = (j == GXMIX_BLEND_FAST) ? ~parity : 1; + } + + l = sub1flags & 0xf; + + if (offs == -2) + { + K053936GP_0_zoom_draw(machine, bitmap, cliprect, sub1, l, k, alpha); + } + else + { + K053250_draw(machine, bitmap, cliprect, 0, vcblk[4]<>26; temp3 = 3; } + else + { + temp1 = osinmix; + temp2 = osinmix>>4 & 3; + temp3 = osmixon>>4 & 3; + } + + if (temp1!=0xff && temp2 /*&& temp3==3*/) + { + alpha = temp4 = K054338_set_alpha_level(temp2); + + if (temp4 <= 0) continue; + if (temp4 < 255) k = (j == GXMIX_BLEND_FAST) ? ~parity : 1; + } + + l = sub2flags & 0xf; + + if (offs == -3) + { + if (extra_bitmap) // soccer superstars roz layer + { + int xx,yy; + int width = video_screen_get_width(machine->primary_screen); + int height = video_screen_get_height(machine->primary_screen); + const pen_t *paldata = machine->pens; + + // the output size of the roz layer has to be doubled horizontally + // so that it aligns with the sprites and normal tilemaps. This appears + // to be done as a post-processing / mixing step effect + for (yy=0;yy>4 & 0xf; + + alpha = 255; + if (drawmode & 2) + { + alpha = color>>K055555_MIXSHIFT & 3; + if (alpha) alpha = K054338_set_alpha_level(alpha); + if (alpha <= 0) continue; + } + color &= K055555_COLORMASK; + + if (drawmode >= 4) palette_set_shadow_mode(machine, order & 0x0f); + + if (!(mixerflags & GXMIX_NOZBUF)) + { + zcode = order>>16 & 0xff; + pri = order>>24 & 0xff; + } + else + zcode = -1; // negative zcode values turn off z-buffering + + xa = ya = 0; + if (code & 0x01) xa += 1; + if (code & 0x02) ya += 1; + if (code & 0x04) xa += 2; + if (code & 0x08) ya += 2; + if (code & 0x10) xa += 4; + if (code & 0x20) ya += 4; + code &= ~0x3f; + + temp4 = gx_spriteram[offs]; + + // mask off the upper 6 bits of coordinate and zoom registers + oy = gx_spriteram[offs+2] & 0x3ff; + ox = gx_spriteram[offs+3] & 0x3ff; + + scaley = zoomy = gx_spriteram[offs+4] & 0x3ff; + if (zoomy) zoomy = (0x400000+(zoomy>>1)) / zoomy; + else zoomy = 0x800000; + if (!(temp4 & 0x4000)) + { + scalex = zoomx = gx_spriteram[offs+5] & 0x3ff; + if (zoomx) zoomx = (0x400000+(zoomx>>1)) / zoomx; + else zoomx = 0x800000; + } + else { zoomx = zoomy; scalex = scaley; } + + nozoom = (scalex == 0x40 && scaley == 0x40); + + flipx = temp4 & 0x1000; + flipy = temp4 & 0x2000; + + temp = gx_spriteram[offs+6]; + mirrorx = temp & 0x4000; + if (mirrorx) flipx = 0; // only applies to x mirror, proven + mirrory = temp & 0x8000; + + // for Escape Kids (GX975) + if ( K053246_objset1 & 8 ) // Check only "Bit #3 is '1'?" + { + zoomx = zoomx>>1; // Fix sprite width to HALF size + ox = (ox>>1) + 1; // Fix sprite draw position + + if (flipscreenx) ox += screenwidth; + } + + if (flipscreenx) { ox = -ox; if (!mirrorx) flipx = !flipx; } + if (flipscreeny) { oy = -oy; if (!mirrory) flipy = !flipy; } + + // apply wrapping and global offsets + temp = wrapsize-1; + + ox += K053247_dx; + oy -= K053247_dy; + ox = ( ox - offx) & temp; + oy = (-oy - offy) & temp; + if (ox >= xwraplim) ox -= wrapsize; + if (oy >= ywraplim) oy -= wrapsize; + + + temp = temp4>>8 & 0x0f; + k = 1 << (temp & 3); + l = 1 << (temp>>2 & 3); + + ox -= (zoomx * k) >> 13; + oy -= (zoomy * l) >> 13; + + // substitutes: i=x, j=y, k=w, l=h, temp=code, temp1=fx, temp2=fy, temp3=sx, temp4=sy; + for (j=0; j> 12); + zh = (oy + ((zoomy * (j+1) + (1<<11)) >> 12)) - temp4; + + for (i=0; i> 12); + zw = (ox + ((zoomx * (i+1) + (1<<11)) >> 12)) - temp3; + temp = code; + + if (mirrorx) + { + if ((!flipx)^((i<<1)=l)) + { + /* mirror top/bottom */ + temp += yoffset[(l-1-j+ya)&7]; + temp2 = 1; + } + else + { + temp += yoffset[(j+ya)&7]; + temp2 = 0; + } + } + else + { + if (flipy) temp += yoffset[(l-1-j+ya)&7]; + else temp += yoffset[(j+ya)&7]; + temp2 = flipy; + } + + if (nozoom) { scaley = scalex = 0x10000; } else { scalex = zw << 12; scaley = zh << 12; }; + + zdrawgfxzoom32GP( + bitmap, cliprect, K053247_gfx, + temp, + color, + temp1,temp2, + temp3,temp4, + scalex, scaley, alpha, drawmode, zcode, pri); + } + } + } +} + + + + + /* Run and Gun 2 / Rushing Heroes */ static TILE_GET_INFO( get_gx_psac_tile_info ) { @@ -375,7 +2105,29 @@ VIDEO_START(konamigx_type3) VIDEO_START(konamigx_type4) { K056832_vh_start(machine, "gfx1", K056832_BPP_8, 0, NULL, konamigx_type2_tile_callback, 0); - K055673_vh_start(machine, "gfx2", K055673_LAYOUT_GX6, -78, -24, konamigx_type2_sprite_callback); + K055673_vh_start(machine, "gfx2", K055673_LAYOUT_GX6, -79, -24, konamigx_type2_sprite_callback); // -23 looks better in intro + + _gxcommoninitnosprites(machine); + + gx_psac_tilemap = tilemap_create(machine, get_gx_psac_tile_info, tilemap_scan_cols, 16, 16, 128, 128); + gx_rozenable = 0; + gx_specialrozenable = 3; + + K056832_set_LayerOffset(0, -27, 0); + K056832_set_LayerOffset(1, -25, 0); + K056832_set_LayerOffset(2, -24, 0); + K056832_set_LayerOffset(3, -22, 0); + + K053936_wraparound_enable(0, 0); + K053936GP_set_offset(0, -36, 1); + + gx_rushingheroes_hack = 1; +} + +VIDEO_START(konamigx_type4_sd2) +{ + K056832_vh_start(machine, "gfx1", K056832_BPP_8, 0, NULL, konamigx_type2_tile_callback, 0); + K055673_vh_start(machine, "gfx2", K055673_LAYOUT_GX6, -81, -23, konamigx_type2_sprite_callback); _gxcommoninitnosprites(machine); @@ -384,19 +2136,19 @@ VIDEO_START(konamigx_type4) gx_specialrozenable = 3; - K056832_set_LayerOffset(0, -22, 0); - K056832_set_LayerOffset(1, -22, 0); - K056832_set_LayerOffset(2, -22, 0); - K056832_set_LayerOffset(3, -22, 0); + K056832_set_LayerOffset(0, -29, -1); + K056832_set_LayerOffset(1, -27, -1); + K056832_set_LayerOffset(2, -26, -1); + K056832_set_LayerOffset(3, -24, -1); K053936_wraparound_enable(0, 0); - K053936GP_set_offset(0, -36, 0); + K053936GP_set_offset(0, -36, -1); gx_rushingheroes_hack = 1; - } + VIDEO_START(konamigx_6bpp_2) { K056832_vh_start(machine, "gfx1", K056832_BPP_6, 1, NULL, konamigx_type2_tile_callback, 0); diff --git a/src/mame/video/mystwarr.c b/src/mame/video/mystwarr.c index 221923afb0b..7d73be4adbd 100644 --- a/src/mame/video/mystwarr.c +++ b/src/mame/video/mystwarr.c @@ -7,7 +7,7 @@ #include "driver.h" #include "video/konamiic.h" -#include "machine/konamigx.h" +#include "konamigx.h" static int layer_colorbase[6]; static int oinprion, cbparam;