From c34df5727c97d02bf019f6f5d824f8c957a7cdbf Mon Sep 17 00:00:00 2001 From: Fabio Priuli Date: Sat, 20 Feb 2010 17:44:46 +0000 Subject: [PATCH] Added driver_data struct and save states to the following drivers: madmotor.c, mazerbla.c, mikie.c, mjsister.c, mogura.c, mole.c and momoko.c --- .gitattributes | 5 +- src/mame/drivers/madmotor.c | 59 +-- src/mame/drivers/mazerbla.c | 710 ++++++++++++++++++++--------------- src/mame/drivers/mikie.c | 138 ++++--- src/mame/drivers/mjsister.c | 412 ++++++++++++++------ src/mame/drivers/mogura.c | 110 ++++-- src/mame/drivers/mole.c | 154 +++++++- src/mame/drivers/momoko.c | 73 ++-- src/mame/includes/madmotor.h | 39 ++ src/mame/includes/mikie.h | 38 ++ src/mame/includes/momoko.h | 46 +++ src/mame/mame.mak | 4 +- src/mame/video/madmotor.c | 167 ++++---- src/mame/video/mikie.c | 57 +-- src/mame/video/mjsister.c | 109 ------ src/mame/video/mole.c | 58 --- src/mame/video/momoko.c | 287 +++++++------- 17 files changed, 1484 insertions(+), 982 deletions(-) create mode 100644 src/mame/includes/madmotor.h create mode 100644 src/mame/includes/mikie.h create mode 100644 src/mame/includes/momoko.h delete mode 100644 src/mame/video/mjsister.c delete mode 100644 src/mame/video/mole.c diff --git a/.gitattributes b/.gitattributes index faa6cd6d94f..1b151ed0f84 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2625,6 +2625,7 @@ src/mame/includes/m79amb.h svneol=native#text/plain src/mame/includes/m92.h svneol=native#text/plain src/mame/includes/macrossp.h svneol=native#text/plain src/mame/includes/madalien.h svneol=native#text/plain +src/mame/includes/madmotor.h svneol=native#text/plain src/mame/includes/mainevt.h svneol=native#text/plain src/mame/includes/malzak.h svneol=native#text/plain src/mame/includes/mappy.h svneol=native#text/plain @@ -2645,11 +2646,13 @@ src/mame/includes/midvunit.h svneol=native#text/plain src/mame/includes/midwunit.h svneol=native#text/plain src/mame/includes/midyunit.h svneol=native#text/plain src/mame/includes/midzeus.h svneol=native#text/plain +src/mame/includes/mikie.h svneol=native#text/plain src/mame/includes/mitchell.h svneol=native#text/plain src/mame/includes/mjkjidai.h svneol=native#text/plain src/mame/includes/model1.h svneol=native#text/plain src/mame/includes/model2.h svneol=native#text/plain src/mame/includes/model3.h svneol=native#text/plain +src/mame/includes/momoko.h svneol=native#text/plain src/mame/includes/moo.h svneol=native#text/plain src/mame/includes/ms32.h svneol=native#text/plain src/mame/includes/mugsmash.h svneol=native#text/plain @@ -3553,12 +3556,10 @@ src/mame/video/midzeus2.c svneol=native#text/plain src/mame/video/mikie.c svneol=native#text/plain src/mame/video/mitchell.c svneol=native#text/plain src/mame/video/mjkjidai.c svneol=native#text/plain -src/mame/video/mjsister.c svneol=native#text/plain src/mame/video/model1.c svneol=native#text/plain src/mame/video/model2.c svneol=native#text/plain src/mame/video/model2rd.c svneol=native#text/plain src/mame/video/model3.c svneol=native#text/plain -src/mame/video/mole.c svneol=native#text/plain src/mame/video/momoko.c svneol=native#text/plain src/mame/video/moo.c svneol=native#text/plain src/mame/video/mosaic.c svneol=native#text/plain diff --git a/src/mame/drivers/madmotor.c b/src/mame/drivers/madmotor.c index 9235766daad..b551bddb9ec 100644 --- a/src/mame/drivers/madmotor.c +++ b/src/mame/drivers/madmotor.c @@ -18,25 +18,18 @@ #include "sound/2203intf.h" #include "sound/2151intf.h" #include "sound/okim6295.h" - -VIDEO_START( madmotor ); -VIDEO_UPDATE( madmotor ); - -WRITE16_HANDLER( madmotor_pf1_data_w ); -WRITE16_HANDLER( madmotor_pf2_data_w ); -WRITE16_HANDLER( madmotor_pf3_data_w ); -extern UINT16 *madmotor_pf1_rowscroll; -extern UINT16 *madmotor_pf1_data,*madmotor_pf2_data,*madmotor_pf3_data; -extern UINT16 *madmotor_pf1_control,*madmotor_pf2_control,*madmotor_pf3_control; +#include "includes/madmotor.h" /******************************************************************************/ static WRITE16_HANDLER( madmotor_sound_w ) { + madmotor_state *state = (madmotor_state *)space->machine->driver_data; + if (ACCESSING_BITS_0_7) { soundlatch_w(space, 0, data & 0xff); - cputag_set_input_line(space->machine, "audiocpu", 0, HOLD_LINE); + cpu_set_input_line(state->audiocpu, 0, HOLD_LINE); } } @@ -45,17 +38,17 @@ static WRITE16_HANDLER( madmotor_sound_w ) static ADDRESS_MAP_START( madmotor_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x000000, 0x07ffff) AM_ROM - AM_RANGE(0x180000, 0x18001f) AM_WRITEONLY AM_BASE(&madmotor_pf1_control) - AM_RANGE(0x184000, 0x1847ff) AM_RAM AM_BASE(&madmotor_pf1_rowscroll) - AM_RANGE(0x188000, 0x189fff) AM_RAM_WRITE(madmotor_pf1_data_w) AM_BASE(&madmotor_pf1_data) + AM_RANGE(0x180000, 0x18001f) AM_WRITEONLY AM_BASE_MEMBER(madmotor_state, pf1_control) + AM_RANGE(0x184000, 0x1847ff) AM_RAM AM_BASE_MEMBER(madmotor_state, pf1_rowscroll) + AM_RANGE(0x188000, 0x189fff) AM_RAM_WRITE(madmotor_pf1_data_w) AM_BASE_MEMBER(madmotor_state, pf1_data) AM_RANGE(0x18c000, 0x18c001) AM_NOP - AM_RANGE(0x190000, 0x19001f) AM_WRITEONLY AM_BASE(&madmotor_pf2_control) - AM_RANGE(0x198000, 0x1987ff) AM_RAM_WRITE(madmotor_pf2_data_w) AM_BASE(&madmotor_pf2_data) + AM_RANGE(0x190000, 0x19001f) AM_WRITEONLY AM_BASE_MEMBER(madmotor_state, pf2_control) + AM_RANGE(0x198000, 0x1987ff) AM_RAM_WRITE(madmotor_pf2_data_w) AM_BASE_MEMBER(madmotor_state, pf2_data) AM_RANGE(0x19c000, 0x19c001) AM_READNOP - AM_RANGE(0x1a0000, 0x1a001f) AM_WRITEONLY AM_BASE(&madmotor_pf3_control) - AM_RANGE(0x1a4000, 0x1a4fff) AM_RAM_WRITE(madmotor_pf3_data_w) AM_BASE(&madmotor_pf3_data) + AM_RANGE(0x1a0000, 0x1a001f) AM_WRITEONLY AM_BASE_MEMBER(madmotor_state, pf3_control) + AM_RANGE(0x1a4000, 0x1a4fff) AM_RAM_WRITE(madmotor_pf3_data_w) AM_BASE_MEMBER(madmotor_state, pf3_data) AM_RANGE(0x3e0000, 0x3e3fff) AM_RAM - AM_RANGE(0x3e8000, 0x3e87ff) AM_RAM AM_BASE_SIZE_GENERIC(spriteram) + AM_RANGE(0x3e8000, 0x3e87ff) AM_RAM AM_BASE_SIZE_MEMBER(madmotor_state, spriteram, spriteram_size) AM_RANGE(0x3f0000, 0x3f07ff) AM_RAM_WRITE(paletteram16_xxxxBBBBGGGGRRRR_word_w) AM_BASE_GENERIC(paletteram) AM_RANGE(0x3f8002, 0x3f8003) AM_READ_PORT("P1_P2") AM_RANGE(0x3f8004, 0x3f8005) AM_READ_PORT("DSW") @@ -221,7 +214,8 @@ GFXDECODE_END static void sound_irq(running_device *device, int state) { - cputag_set_input_line(device->machine, "audiocpu", 1, state); /* IRQ 2 */ + madmotor_state *driver_state = (madmotor_state *)device->machine->driver_data; + cpu_set_input_line(driver_state->audiocpu, 1, state); /* IRQ 2 */ } static const ym2151_interface ym2151_config = @@ -229,8 +223,28 @@ static const ym2151_interface ym2151_config = sound_irq }; +static MACHINE_START( madmotor ) +{ + madmotor_state *state = (madmotor_state *)machine->driver_data; + + state->maincpu = devtag_get_device(machine, "maincpu"); + state->audiocpu = devtag_get_device(machine, "audiocpu"); + + state_save_register_global(machine, state->flipscreen); +} + +static MACHINE_RESET( madmotor ) +{ + madmotor_state *state = (madmotor_state *)machine->driver_data; + + state->flipscreen = 0; +} + static MACHINE_DRIVER_START( madmotor ) + /* driver data */ + MDRV_DRIVER_DATA(madmotor_state) + /* basic machine hardware */ MDRV_CPU_ADD("maincpu", M68000, 12000000) /* Custom chip 59, 24 MHz crystal */ MDRV_CPU_PROGRAM_MAP(madmotor_map) @@ -239,6 +253,9 @@ static MACHINE_DRIVER_START( madmotor ) MDRV_CPU_ADD("audiocpu", H6280, 8053000/2) /* Custom chip 45, Crystal near CPU is 8.053 MHz */ MDRV_CPU_PROGRAM_MAP(sound_map) + MDRV_MACHINE_START(madmotor) + MDRV_MACHINE_RESET(madmotor) + /* video hardware */ MDRV_VIDEO_ATTRIBUTES(VIDEO_UPDATE_BEFORE_VBLANK) @@ -334,4 +351,4 @@ static DRIVER_INIT( madmotor ) /* The title screen is undated, but it's (c) 1989 Data East at 0xefa0 */ -GAME( 1989, madmotor, 0, madmotor, madmotor, madmotor, ROT0, "Mitchell", "Mad Motor", 0 ) +GAME( 1989, madmotor, 0, madmotor, madmotor, madmotor, ROT0, "Mitchell", "Mad Motor", GAME_SUPPORTS_SAVE ) diff --git a/src/mame/drivers/mazerbla.c b/src/mame/drivers/mazerbla.c index 33a4ccbc0e2..32d44d1d36a 100644 --- a/src/mame/drivers/mazerbla.c +++ b/src/mame/drivers/mazerbla.c @@ -43,40 +43,53 @@ TO DO: #define MAZERBLA 0x01 #define GREATGUN 0x02 -static UINT8 game_id = 0; /* hacks per game */ #define MASTER_CLOCK XTAL_4MHz #define SOUND_CLOCK XTAL_14_31818MHz -static UINT8 *cfb_ram; -static UINT8 ls670_0[4]; -static UINT8 ls670_1[4]; +typedef struct _mazerbla_state mazerbla_state; +struct _mazerbla_state +{ + /* memory pointers */ + UINT8 * cfb_ram; + UINT8 * videoram; + size_t videoram_size; -static UINT8 zpu_int_vector; + /* video-related */ + bitmap_t * tmpbitmaps[4]; -static UINT8 bcd_7445 = 0; + UINT8 vcu_video_reg[4]; + UINT32 vcu_gfx_addr; + UINT32 vcu_gfx_param_addr; -static UINT8 vsb_ls273; -static UINT8 soundlatch; + UINT8 bknd_col; + UINT8 port02_status; + UINT8 vbank; /* video page select signal, likely for double buffering ?*/ + UINT32 xpos, ypos, pix_xsize, pix_ysize; + UINT8 color1, color2, mode, plane; + UINT8 lookup_ram[0x100*4]; + UINT32 gfx_rom_bank; /* graphics ROMs are banked */ + double weights_r[2], weights_g[3], weights_b[3]; -/************************************* - * - * Video Hardware - * - *************************************/ + /* misc */ + UINT8 game_id; /* hacks per game */ + UINT8 ls670_0[4]; + UINT8 ls670_1[4]; + + UINT8 zpu_int_vector; + + UINT8 bcd_7445; + + UINT8 vsb_ls273; + UINT8 soundlatch; + + /* devices */ + running_device *maincpu; + running_device *subcpu; +}; -static UINT8 bknd_col; -static UINT8 port02_status = 0; -static UINT8 VCU_video_reg[4]; -static UINT8 vbank = 0; /* video page select signal, likely for double buffering ?*/ -static UINT32 VCU_gfx_addr = 0; -static UINT32 VCU_gfx_param_addr = 0; -static UINT32 xpos=0, ypos=0, pix_xsize=0, pix_ysize=0; -static UINT8 color=0, color2=0, mode=0, plane=0; -static UINT8 lookup_RAM[0x100*4]; -static UINT32 gfx_rom_bank; /* graphics ROMs are banked */ /*************************************************************************** @@ -97,30 +110,32 @@ static UINT32 gfx_rom_bank; /* graphics ROMs are banked */ ***************************************************************************/ -static double weights_r[2], weights_g[3], weights_b[3]; - static PALETTE_INIT( mazerbla ) { + mazerbla_state *state = (mazerbla_state *)machine->driver_data; static const int resistances_r[2] = { 4700, 2200 }; static const int resistances_gb[3] = { 10000, 4700, 2200 }; /* just to calculate coefficients for later use */ compute_resistor_weights(0, 255, -1.0, - 3, resistances_gb, weights_g, 3600, 0, - 3, resistances_gb, weights_b, 3600, 0, - 2, resistances_r, weights_r, 3600, 0); + 3, resistances_gb, state->weights_g, 3600, 0, + 3, resistances_gb, state->weights_b, 3600, 0, + 2, resistances_r, state->weights_r, 3600, 0); } - -static bitmap_t * tmpbitmaps[4]; - static VIDEO_START( mazerbla ) { - tmpbitmaps[0] = video_screen_auto_bitmap_alloc(machine->primary_screen); - tmpbitmaps[1] = video_screen_auto_bitmap_alloc(machine->primary_screen); - tmpbitmaps[2] = video_screen_auto_bitmap_alloc(machine->primary_screen); - tmpbitmaps[3] = video_screen_auto_bitmap_alloc(machine->primary_screen); + mazerbla_state *state = (mazerbla_state *)machine->driver_data; + state->tmpbitmaps[0] = video_screen_auto_bitmap_alloc(machine->primary_screen); + state->tmpbitmaps[1] = video_screen_auto_bitmap_alloc(machine->primary_screen); + state->tmpbitmaps[2] = video_screen_auto_bitmap_alloc(machine->primary_screen); + state->tmpbitmaps[3] = video_screen_auto_bitmap_alloc(machine->primary_screen); + + state_save_register_global_bitmap(machine, state->tmpbitmaps[0]); + state_save_register_global_bitmap(machine, state->tmpbitmaps[1]); + state_save_register_global_bitmap(machine, state->tmpbitmaps[2]); + state_save_register_global_bitmap(machine, state->tmpbitmaps[3]); } #ifdef UNUSED_DEFINITION @@ -134,37 +149,38 @@ static int planes_enabled[4] = {1,1,1,1}; //all enabled VIDEO_UPDATE( test_vcu ) { + mazerbla_state *state = (mazerbla_state *)screen->machine->driver_data; int j; char buf[128]; - UINT32 color_base=0; + UINT32 color_base = 0; - if (game_id==MAZERBLA) + if (state->game_id == MAZERBLA) color_base = 0x80; /* 0x80 constant: matches Mazer Blazer movie */ - if (game_id==GREATGUN) - color_base = 0x0; + if (state->game_id == GREATGUN) + color_base = 0x00; - bitmap_fill(bitmap,NULL,0); + bitmap_fill(bitmap, NULL, 0); // logerror("-->frame\n"); if (planes_enabled[3]) - copybitmap(bitmap,tmpbitmaps[3],0,0,0,0,cliprect); + copybitmap(bitmap, state->tmpbitmaps[3], 0, 0, 0, 0, cliprect); if (planes_enabled[2]) - copybitmap_trans(bitmap,tmpbitmaps[2],0,0,0,0,cliprect,color_base); + copybitmap_trans(bitmap, state->tmpbitmaps[2], 0, 0, 0, 0,cliprect, color_base); - bitmap_fill(tmpbitmaps[2],NULL,color_base); + bitmap_fill(state->tmpbitmaps[2], NULL, color_base); if (planes_enabled[1]) - copybitmap_trans(bitmap,tmpbitmaps[1],0,0,0,0,cliprect,color_base); + copybitmap_trans(bitmap, state->tmpbitmaps[1], 0, 0, 0, 0,cliprect, color_base); - bitmap_fill(tmpbitmaps[1],NULL,color_base); + bitmap_fill(state->tmpbitmaps[1], NULL, color_base); if (planes_enabled[0]) - copybitmap_trans(bitmap,tmpbitmaps[0],0,0,0,0,cliprect,color_base); + copybitmap_trans(bitmap, state->tmpbitmaps[0], 0, 0, 0, 0,cliprect, color_base); - bitmap_fill(tmpbitmaps[0],NULL,color_base); + bitmap_fill(state->tmpbitmaps[0], NULL, color_base); if (input_code_pressed_once(screen->machine, KEYCODE_1)) /* plane 1 */ planes_enabled[0] ^= 1; @@ -191,7 +207,7 @@ VIDEO_UPDATE( test_vcu ) dbg_vbank ^= 1; if (input_code_pressed_once(screen->machine, KEYCODE_L)) /* showlookup ram */ - dbg_lookup = (dbg_lookup+1)%5;//0,1,2,3, 4-off + dbg_lookup = (dbg_lookup + 1) % 5; //0,1,2,3, 4-off if (dbg_info) @@ -210,15 +226,15 @@ VIDEO_UPDATE( test_vcu ) if (dbg_lookup!=4) { int lookup_offs = (dbg_lookup)*256; //=0,1,2,3*256 - int y,x; + int y, x; - for (y=0; y<16; y++) + for (y = 0; y < 16; y++) { - memset(buf,0,128); - sprintf( buf+strlen(buf), "%04x ", lookup_offs+y*16 ); - for (x=0; x<16; x++) + memset(buf, 0, 128); + sprintf(buf + strlen(buf), "%04x ", lookup_offs + y * 16); + for (x = 0; x < 16; x++) { - sprintf( buf+strlen(buf), "%02x ", lookup_RAM[ lookup_offs+x+y*16 ] ); + sprintf(buf + strlen(buf), "%02x ", lookup_ram[lookup_offs + x + y * 16]); } ui_draw_text(buf, 0, (2 + y) * ui_get_line_height()); } @@ -230,70 +246,53 @@ VIDEO_UPDATE( test_vcu ) #endif -/* these two VIDEO_UPDATE()s will be joined one day */ -static VIDEO_UPDATE( greatgun ) -{ - UINT32 color_base=0; - - if (game_id==MAZERBLA) - color_base = 0x80; /* 0x80 constant: matches Mazer Blazer movie */ - - if (game_id==GREATGUN) - color_base = 0x0; - -// bitmap_fill(bitmap,NULL,0); - - copybitmap (bitmap,tmpbitmaps[3],0,0,0,0,cliprect); - copybitmap_trans(bitmap,tmpbitmaps[2],0,0,0,0,cliprect,color_base); - copybitmap_trans(bitmap,tmpbitmaps[1],0,0,0,0,cliprect,color_base); - copybitmap_trans(bitmap,tmpbitmaps[0],0,0,0,0,cliprect,color_base); - return 0; -} - static VIDEO_UPDATE( mazerbla ) { - UINT32 color_base=0; + mazerbla_state *state = (mazerbla_state *)screen->machine->driver_data; + UINT32 color_base = 0; - if (game_id==MAZERBLA) + if (state->game_id == MAZERBLA) color_base = 0x80; /* 0x80 constant: matches Mazer Blazer movie */ - if (game_id==GREATGUN) - color_base = 0x0; + if (state->game_id == GREATGUN) + color_base = 0x00; -// bitmap_fill(bitmap,NULL,0); + // bitmap_fill(bitmap, NULL, 0); - copybitmap (bitmap,tmpbitmaps[3],0,0,0,0,cliprect); //text - copybitmap_trans(bitmap,tmpbitmaps[2],0,0,0,0,cliprect,0); - copybitmap_trans(bitmap,tmpbitmaps[1],0,0,0,0,cliprect,0); //haircross - copybitmap_trans(bitmap,tmpbitmaps[0],0,0,0,0,cliprect,0); //sprites + copybitmap(bitmap, state->tmpbitmaps[3], 0, 0, 0, 0, cliprect); + copybitmap_trans(bitmap, state->tmpbitmaps[2], 0, 0, 0, 0, cliprect, 0); + copybitmap_trans(bitmap, state->tmpbitmaps[1], 0, 0, 0, 0, cliprect, 0); + copybitmap_trans(bitmap, state->tmpbitmaps[0], 0, 0, 0, 0, cliprect, 0); return 0; } static WRITE8_HANDLER( cfb_backgnd_color_w ) { - if (bknd_col != data) - { - int r,g,b, bit0, bit1, bit2; + mazerbla_state *state = (mazerbla_state *)space->machine->driver_data; - bknd_col = data; + if (state->bknd_col != data) + { + int r, g, b, bit0, bit1, bit2; + + state->bknd_col = data; /* red component */ - bit1 = (data >> 7) & 0x01; - bit0 = (data >> 6) & 0x01; - r = combine_2_weights(weights_r, bit0, bit1); + bit1 = BIT(data, 7); + bit0 = BIT(data, 6); + r = combine_2_weights(state->weights_r, bit0, bit1); /* green component */ - bit2 = (data >> 5) & 0x01; - bit1 = (data >> 4) & 0x01; - bit0 = (data >> 3) & 0x01; - g = combine_3_weights(weights_g, bit0, bit1, bit2); + bit2 = BIT(data, 5); + bit1 = BIT(data, 4); + bit0 = BIT(data, 3); + g = combine_3_weights(state->weights_g, bit0, bit1, bit2); /* blue component */ - bit2 = (data >> 2) & 0x01; - bit1 = (data >> 1) & 0x01; - bit0 = (data >> 0) & 0x01; - b = combine_3_weights(weights_b, bit0, bit1, bit2); + bit2 = BIT(data, 2); + bit1 = BIT(data, 1); + bit0 = BIT(data, 0); + b = combine_3_weights(state->weights_b, bit0, bit1, bit2); palette_set_color(space->machine, 255, MAKE_RGB(r, g, b)); //logerror("background color (port 01) write=%02x\n",data); @@ -301,100 +300,111 @@ static WRITE8_HANDLER( cfb_backgnd_color_w ) } -static WRITE8_HANDLER(cfb_vbank_w) +static WRITE8_HANDLER( cfb_vbank_w ) { + mazerbla_state *state = (mazerbla_state *)space->machine->driver_data; + /* only bit 6 connected */ - vbank = (data & 0x40)>>6; + state->vbank = BIT(data, 6); } -static WRITE8_HANDLER(cfb_rom_bank_sel_w) /* mazer blazer */ +static WRITE8_HANDLER( cfb_rom_bank_sel_w ) /* mazer blazer */ { - gfx_rom_bank = data; + mazerbla_state *state = (mazerbla_state *)space->machine->driver_data; + state->gfx_rom_bank = data; - memory_set_bankptr(space->machine, "bank1", memory_region(space->machine, "sub2") + (gfx_rom_bank * 0x2000) + 0x10000 ); + memory_set_bankptr(space->machine, "bank1", memory_region(space->machine, "sub2") + (state->gfx_rom_bank * 0x2000) + 0x10000); } -static WRITE8_HANDLER(cfb_rom_bank_sel_w_gg) /* great guns */ +static WRITE8_HANDLER( cfb_rom_bank_sel_w_gg ) /* great guns */ { - gfx_rom_bank = data>>1; + mazerbla_state *state = (mazerbla_state *)space->machine->driver_data; + state->gfx_rom_bank = data >> 1; - memory_set_bankptr(space->machine, "bank1", memory_region(space->machine, "sub2") + (gfx_rom_bank * 0x2000) + 0x10000 ); + memory_set_bankptr(space->machine, "bank1", memory_region(space->machine, "sub2") + (state->gfx_rom_bank * 0x2000) + 0x10000); } /* VCU status? */ static READ8_HANDLER( cfb_port_02_r ) { - port02_status ^= 0xff; - return (port02_status); + mazerbla_state *state = (mazerbla_state *)space->machine->driver_data; + state->port02_status ^= 0xff; + return state->port02_status; } -static WRITE8_HANDLER( VCU_video_reg_w ) +static WRITE8_HANDLER( vcu_video_reg_w ) { - if (VCU_video_reg[offset] != data) + mazerbla_state *state = (mazerbla_state *)space->machine->driver_data; + if (state->vcu_video_reg[offset] != data) { - VCU_video_reg[offset] = data; - //popmessage("video_reg= %02x %02x %02x %02x", VCU_video_reg[0], VCU_video_reg[1], VCU_video_reg[2], VCU_video_reg[3] ); - //logerror("video_reg= %02x %02x %02x %02x\n", VCU_video_reg[0], VCU_video_reg[1], VCU_video_reg[2], VCU_video_reg[3] ); + state->vcu_video_reg[offset] = data; + //popmessage("video_reg= %02x %02x %02x %02x", state->vcu_video_reg[0], state->vcu_video_reg[1], state->vcu_video_reg[2], state->vcu_video_reg[3]); + //logerror("video_reg= %02x %02x %02x %02x\n", state->vcu_video_reg[0], state->vcu_video_reg[1], state->vcu_video_reg[2], state->vcu_video_reg[3]); } } -static READ8_HANDLER( VCU_set_cmd_param_r ) +static READ8_HANDLER( vcu_set_cmd_param_r ) { - VCU_gfx_param_addr = offset; + mazerbla_state *state = (mazerbla_state *)space->machine->driver_data; + state->vcu_gfx_param_addr = offset; /* offset = 0 is not known */ - xpos = cfb_ram[VCU_gfx_param_addr + 1] | (cfb_ram[VCU_gfx_param_addr + 2]<<8); - ypos = cfb_ram[VCU_gfx_param_addr + 3] | (cfb_ram[VCU_gfx_param_addr + 4]<<8); - color = cfb_ram[VCU_gfx_param_addr + 5]; - color2 = cfb_ram[VCU_gfx_param_addr + 6]; - mode = cfb_ram[VCU_gfx_param_addr + 7]; - pix_xsize = cfb_ram[VCU_gfx_param_addr + 8]; - pix_ysize = cfb_ram[VCU_gfx_param_addr + 9]; + state->xpos = state->cfb_ram[state->vcu_gfx_param_addr + 1] | (state->cfb_ram[state->vcu_gfx_param_addr + 2]<<8); + state->ypos = state->cfb_ram[state->vcu_gfx_param_addr + 3] | (state->cfb_ram[state->vcu_gfx_param_addr + 4]<<8); + state->color1 = state->cfb_ram[state->vcu_gfx_param_addr + 5]; + state->color2 = state->cfb_ram[state->vcu_gfx_param_addr + 6]; + state->mode = state->cfb_ram[state->vcu_gfx_param_addr + 7]; + state->pix_xsize = state->cfb_ram[state->vcu_gfx_param_addr + 8]; + state->pix_ysize = state->cfb_ram[state->vcu_gfx_param_addr + 9]; - plane = mode & 3; + state->plane = state->mode & 3; return 0; } -static READ8_HANDLER( VCU_set_gfx_addr_r ) +static READ8_HANDLER( vcu_set_gfx_addr_r ) { + mazerbla_state *state = (mazerbla_state *)space->machine->driver_data; + UINT8 * rom = memory_region(space->machine, "sub2") + (state->gfx_rom_bank * 0x2000) + 0x10000; int offs; - int x,y; + int x, y; int bits = 0; + UINT8 color_base; - UINT8 color_base=0; - - UINT8 * rom = memory_region(space->machine, "sub2") + (gfx_rom_bank * 0x2000) + 0x10000; + if (state->game_id == MAZERBLA) + color_base = 0x80; /* 0x80 - good for Mazer Blazer: (only in game, CRT test mode is bad) */ + if (state->game_id == GREATGUN) + color_base = 0x00; /* 0x00 - good for Great Guns: (both in game and CRT test mode) */ /* - if ((mode<=0x07) || (mode>=0x10)) + if ((mode <= 0x07) || (mode >= 0x10)) { logerror("paradr="); - logerror("%3x ",VCU_gfx_param_addr ); + logerror("%3x ", state->vcu_gfx_param_addr ); - logerror("%02x ", cfb_ram[VCU_gfx_param_addr + 0] ); - logerror("x=%04x ", xpos ); //1,2 - logerror("y=%04x ", ypos ); //3,4 - logerror("color=%02x ", color); //5 - logerror("color2=%02x ", color2); //6 - logerror("mode=%02x ", mode ); //7 - logerror("xpix=%02x ", pix_xsize ); //8 - logerror("ypix=%02x ", pix_ysize ); //9 + logerror("%02x ", state->cfb_ram[vcu_gfx_param_addr + 0] ); + logerror("x=%04x ", state->xpos ); //1,2 + logerror("y=%04x ", state->ypos ); //3,4 + logerror("color1=%02x ", state->color1); //5 + logerror("color2=%02x ", state->color2); //6 + logerror("mode=%02x ", state->mode ); //7 + logerror("xpix=%02x ", state->pix_xsize ); //8 + logerror("ypix=%02x ", state->pix_ysize ); //9 - logerror("addr=%4i bank=%1i\n", offset, gfx_rom_bank); + logerror("addr=%4i bank=%1i\n", offset, state->gfx_rom_bank); } */ - VCU_gfx_addr = offset; + state->vcu_gfx_addr = offset; /* draw */ - offs = VCU_gfx_addr; + offs = state->vcu_gfx_addr; - switch(mode) + switch(state->mode) { /* 2 bits per pixel */ case 0x0f: @@ -403,42 +413,36 @@ static READ8_HANDLER( VCU_set_gfx_addr_r ) case 0x0c: // if (dbg_gfx_e) // { -// if (vbank==dbg_vbank) +// if (state->vbank == dbg_vbank) { - if (game_id==MAZERBLA) - color_base = 0x80; /* 0x80 constant: matches Mazer Blazer movie */ - - if (game_id==GREATGUN) - color_base = 0x00; - - for (y = 0; y <= pix_ysize; y++) + for (y = 0; y <= state->pix_ysize; y++) { - for (x = 0; x <= pix_xsize; x++) + for (x = 0; x <= state->pix_xsize; x++) { - UINT8 pixeldata = rom[(offs + (bits>>3)) % 0x2000]; - UINT8 data = (pixeldata>>(6-(bits&7))) & 3; + UINT8 pixeldata = rom[(offs + (bits >> 3)) % 0x2000]; + UINT8 data = (pixeldata >> (6 - (bits & 7))) & 3; UINT8 col = 0; switch(data) { case 0: - col = color_base | ((color &0x0f)); //background PEN + col = color_base | ((state->color1 & 0x0f)); //background PEN break; case 1: - col = color_base | ((color &0xf0)>>4); //foreground PEN + col = color_base | ((state->color1 & 0xf0) >> 4); //foreground PEN break; case 2: - col = color_base | ((color2 &0x0f)); //background PEN2 + col = color_base | ((state->color2 & 0x0f)); //background PEN2 break; case 3: - col = color_base | ((color2 &0xf0)>>4); //foreground PEN2 + col = color_base | ((state->color2 & 0xf0) >> 4); //foreground PEN2 break; } - if ( ((xpos+x)<256) && ((ypos+y)<256) ) - *BITMAP_ADDR16(tmpbitmaps[plane], ypos+y, xpos+x) = col; + if (((state->xpos + x) < 256) && ((state->ypos + y) < 256) ) + *BITMAP_ADDR16(state->tmpbitmaps[state->plane], state->ypos + y, state->xpos + x) = col; - bits+=2; + bits += 2; } } } @@ -452,27 +456,22 @@ static READ8_HANDLER( VCU_set_gfx_addr_r ) case 0x08:/* */ // if (dbg_gfx_e) // { -// if (vbank==dbg_vbank) +// if (state->vbank == dbg_vbank) { - if (game_id==MAZERBLA) - color_base = 0x80; /* 0x80 - good for Mazer Blazer: (only in game, CRT test mode is bad) */ - if (game_id==GREATGUN) - color_base = 0x00; /* 0x00 - good for Great Guns: (both in game and CRT test mode) */ - - for (y = 0; y <= pix_ysize; y++) + for (y = 0; y <= state->pix_ysize; y++) { - for (x = 0; x <= pix_xsize; x++) + for (x = 0; x <= state->pix_xsize; x++) { - UINT8 pixeldata = rom[(offs + (bits>>3)) % 0x2000]; - UINT8 data = (pixeldata>>(7-(bits&7))) & 1; + UINT8 pixeldata = rom[(offs + (bits >> 3)) % 0x2000]; + UINT8 data = (pixeldata >> (7 - (bits & 7))) & 1; /* color = 4 MSB = front PEN, 4 LSB = background PEN */ - if ( ((xpos+x)<256) && ((ypos+y)<256) ) - *BITMAP_ADDR16(tmpbitmaps[plane], ypos+y, xpos+x) = data? color_base | ((color&0xf0)>>4): color_base | ((color&0x0f)); + if (((state->xpos + x) < 256) && ((state->ypos + y) < 256)) + *BITMAP_ADDR16(state->tmpbitmaps[state->plane], state->ypos + y, state->xpos + x) = data ? color_base | ((state->color1 & 0xf0) >> 4): color_base | ((state->color1 & 0x0f)); - bits+=1; + bits += 1; } } } @@ -485,74 +484,69 @@ static READ8_HANDLER( VCU_set_gfx_addr_r ) case 0x00: // if (dbg_gfx_e) // { -// if (vbank==dbg_vbank) +// if (state->vbank == dbg_vbank) { - if (game_id==MAZERBLA) - color_base = 0x80; /* 0x80 - good for Mazer Blazer: (only in game, CRT test mode is bad) */ - - if (game_id==GREATGUN) - color_base = 0x00; /* 0x00 - good for Great Guns: (both in game and CRT test mode) */ - - for (y = 0; y <= pix_ysize; y++) + for (y = 0; y <= state->pix_ysize; y++) { - for (x = 0; x <= pix_xsize; x++) + for (x = 0; x <= state->pix_xsize; x++) { - UINT8 pixeldata = rom[(offs + (bits>>3)) % 0x2000]; - UINT8 data = (pixeldata>>(4-(bits&7))) & 15; + UINT8 pixeldata = rom[(offs + (bits >> 3)) % 0x2000]; + UINT8 data = (pixeldata >> (4 - (bits & 7))) & 15; UINT8 col = 0; col = color_base | data; - if ( ((xpos+x)<256) && ((ypos+y)<256) ) - *BITMAP_ADDR16(tmpbitmaps[plane], ypos+y, xpos+x) = col; + if (((state->xpos + x) < 256) && ((state->ypos + y) < 256)) + *BITMAP_ADDR16(state->tmpbitmaps[state->plane], state->ypos + y, state->xpos + x) = col; - bits+=4; + bits += 4; } } } // } break; default: - popmessage("not supported VCU drawing mode=%2x", mode); + popmessage("not supported VCU drawing mode=%2x", state->mode); break; } return 0; } -static READ8_HANDLER( VCU_set_clr_addr_r ) +static READ8_HANDLER( vcu_set_clr_addr_r ) { + mazerbla_state *state = (mazerbla_state *)space->machine->driver_data; + UINT8 * rom = memory_region(space->machine, "sub2") + (state->gfx_rom_bank * 0x2000) + 0x10000; int offs; - int x,y; + int x, y; int bits = 0; - UINT8 color_base=0; + UINT8 color_base = 0; - UINT8 * rom = memory_region(space->machine, "sub2") + (gfx_rom_bank * 0x2000) + 0x10000; /* //if (0) //(mode != 0x07) { logerror("paladr="); - logerror("%3x ",VCU_gfx_param_addr ); + logerror("%3x ", state->vcu_gfx_param_addr ); - logerror("%02x ", cfb_ram[VCU_gfx_param_addr + 0] ); - logerror("x=%04x ", xpos ); //1,2 - logerror("y=%04x ", ypos ); //3,4 - logerror("color=%02x ", color); //5 - logerror("color2=%02x ", color2 ); //6 - logerror("mode=%02x ", mode ); //7 - logerror("xpix=%02x ", pix_xsize ); //8 - logerror("ypix=%02x ", pix_ysize ); //9 + logerror("%02x ", state->cfb_ram[state->vcu_gfx_param_addr + 0] ); + logerror("x=%04x ", state->xpos ); //1,2 + logerror("y=%04x ", state->ypos ); //3,4 + logerror("color1=%02x ", state->color1); //5 + logerror("color2=%02x ", state->color2 ); //6 + logerror("mode=%02x ", state->mode ); //7 + logerror("xpix=%02x ", state->pix_xsize ); //8 + logerror("ypix=%02x ", state->pix_ysize ); //9 - logerror("addr=%4i bank=%1i\n", offset, gfx_rom_bank); + logerror("addr=%4i bank=%1i\n", offset, state->gfx_rom_bank); - for (y=0; y<16; y++) + for (y = 0; y < 16; y++) { - logerror("%04x: ",offset+y*16); - for (x=0; x<16; x++) + logerror("%04x: ", offset + y * 16); + for (x = 0; x < 16; x++) { - logerror("%02x ",cfb_ram[offset+x+y*16]); + logerror("%02x ", state->cfb_ram[offset + x + y * 16]); } logerror("\n"); } @@ -563,7 +557,7 @@ static READ8_HANDLER( VCU_set_clr_addr_r ) /* copy palette / CLUT(???) */ - switch(mode) + switch (state->mode) { case 0x13: /* draws sprites?? in mazer blazer and ... wrong sprite in place of targeting-cross and UFO laser */ case 0x03: @@ -571,42 +565,42 @@ static READ8_HANDLER( VCU_set_clr_addr_r ) the draw command/palette selector is done via the 'mode' only ... */ //if (dbg_clr_e) { - offs = VCU_gfx_addr; + offs = state->vcu_gfx_addr; - if (game_id==MAZERBLA) + if (state->game_id == MAZERBLA) color_base = 0x80; /* 0x80 constant: matches Mazer Blazer movie */ - if (game_id==GREATGUN) + if (state->game_id == GREATGUN) color_base = 0x00; - for (y = 0; y <= pix_ysize; y++) + for (y = 0; y <= state->pix_ysize; y++) { - for (x = 0; x <= pix_xsize; x++) + for (x = 0; x <= state->pix_xsize; x++) { - UINT8 pixeldata = rom[(offs + (bits>>3)) % 0x2000]; - UINT8 data = (pixeldata>>(6-(bits&7))) & 3; + UINT8 pixeldata = rom[(offs + (bits >> 3)) % 0x2000]; + UINT8 data = (pixeldata >> (6 - (bits & 7))) & 3; UINT8 col = 0; switch(data) { case 0: - col = color_base | ((color &0x0f)); //background PEN + col = color_base | ((state->color1 & 0x0f)); //background PEN break; case 1: - col = color_base | ((color &0xf0)>>4); //foreground PEN + col = color_base | ((state->color1 & 0xf0) >> 4); //foreground PEN break; case 2: - col = color_base | ((color2 &0x0f)); //background PEN2 + col = color_base | ((state->color2 & 0x0f)); //background PEN2 break; case 3: - col = color_base | ((color2 &0xf0)>>4); //foreground PEN2 + col = color_base | ((state->color2 & 0xf0) >> 4); //foreground PEN2 break; } - if ( ((xpos+x)<256) && ((ypos+y)<256) ) - *BITMAP_ADDR16(tmpbitmaps[plane], ypos+y, xpos+x) = col; + if (((state->xpos + x) < 256) && ((state->ypos + y) < 256)) + *BITMAP_ADDR16(state->tmpbitmaps[state->plane], state->ypos + y, state->xpos + x) = col; - bits+=2; + bits += 2; } } } @@ -616,97 +610,97 @@ static READ8_HANDLER( VCU_set_clr_addr_r ) case 0x07: offs = offset; - switch(ypos) + switch(state->ypos) { case 6: //seems to encode palette write { - int r,g,b, bit0, bit1, bit2; + int r, g, b, bit0, bit1, bit2; //pix_xsize and pix_ysize seem to be related to palette length ? (divide by 2) - int lookup_offs = (ypos>>1)*256; //=3*256 + int lookup_offs = (state->ypos >> 1) * 256; //=3*256 - for (y=0; y<16; y++) + for (y = 0; y < 16; y++) { - for (x=0; x<16; x++) + for (x = 0; x < 16; x++) { - UINT8 colour = cfb_ram[ offs + x + y*16 ]; + UINT8 colour = state->cfb_ram[offs + x + y * 16]; /* red component */ bit1 = (colour >> 7) & 0x01; bit0 = (colour >> 6) & 0x01; - r = combine_2_weights(weights_r, bit0, bit1); + r = combine_2_weights(state->weights_r, bit0, bit1); /* green component */ bit2 = (colour >> 5) & 0x01; bit1 = (colour >> 4) & 0x01; bit0 = (colour >> 3) & 0x01; - g = combine_3_weights(weights_g, bit0, bit1, bit2); + g = combine_3_weights(state->weights_g, bit0, bit1, bit2); /* blue component */ bit2 = (colour >> 2) & 0x01; bit1 = (colour >> 1) & 0x01; bit0 = (colour >> 0) & 0x01; - b = combine_3_weights(weights_b, bit0, bit1, bit2); + b = combine_3_weights(state->weights_b, bit0, bit1, bit2); - if ((x+y*16)<255)//keep color 255 free for use as background color - palette_set_color(space->machine, x+y*16, MAKE_RGB(r, g, b)); + if ((x + y * 16) < 255)//keep color 255 free for use as background color + palette_set_color(space->machine, x + y * 16, MAKE_RGB(r, g, b)); - lookup_RAM[ lookup_offs + x + y*16 ] = colour; + state->lookup_ram[lookup_offs + x + y * 16] = colour; } } } break; case 4: //seems to encode lookup???? table write { - int lookup_offs = (ypos>>1)*256; //=2*256 + int lookup_offs = (state->ypos >> 1) * 256; //=2*256 - for (y=0; y<16; y++) + for (y = 0; y < 16; y++) { - for (x=0; x<16; x++) + for (x = 0; x < 16; x++) { - UINT8 dat = cfb_ram[ offs + x + y*16 ]; - lookup_RAM[ lookup_offs + x + y*16 ] = dat; + UINT8 dat = state->cfb_ram[offs + x + y * 16]; + state->lookup_ram[lookup_offs + x + y * 16] = dat; } } } break; case 2: //seems to encode lookup???? table write { - int lookup_offs = (ypos>>1)*256; //=1*256 + int lookup_offs = (state->ypos >> 1) * 256; //=1*256 - for (y=0; y<16; y++) + for (y = 0; y < 16; y++) { - for (x=0; x<16; x++) + for (x = 0; x < 16; x++) { - UINT8 dat = cfb_ram[ offs + x + y*16 ]; - lookup_RAM[ lookup_offs + x + y*16 ] = dat; + UINT8 dat = state->cfb_ram[offs + x + y * 16]; + state->lookup_ram[lookup_offs + x + y * 16] = dat; } } } break; case 0: //seems to encode lookup???? table write { - int lookup_offs = (ypos>>1)*256; //=0*256 + int lookup_offs = (state->ypos >> 1) * 256; //=0*256 - for (y=0; y<16; y++) + for (y = 0; y < 16; y++) { - for (x=0; x<16; x++) + for (x = 0; x < 16; x++) { - UINT8 dat = cfb_ram[ offs + x + y*16 ]; - lookup_RAM[ lookup_offs + x + y*16 ] = dat; + UINT8 dat = state->cfb_ram[offs + x + y * 16]; + state->lookup_ram[lookup_offs + x + y * 16] = dat; } } } break; default: - popmessage("not supported lookup/color write mode=%2x", ypos); + popmessage("not supported lookup/color write mode=%2x", state->ypos); break; } break; default: - popmessage("not supported VCU color mode=%2x", mode); + popmessage("not supported VCU color mode=%2x", state->mode); break; } @@ -721,64 +715,74 @@ static READ8_HANDLER( VCU_set_clr_addr_r ) static WRITE8_HANDLER( cfb_zpu_int_req_set_w ) { - zpu_int_vector &= ~2; /* clear D1 on INTA (interrupt acknowledge) */ + mazerbla_state *state = (mazerbla_state *)space->machine->driver_data; - cputag_set_input_line(space->machine, "maincpu", 0, ASSERT_LINE); /* main cpu interrupt (comes from CFB (generated at the start of INT routine on CFB) - vblank?) */ + state->zpu_int_vector &= ~2; /* clear D1 on INTA (interrupt acknowledge) */ + + cpu_set_input_line(state->maincpu, 0, ASSERT_LINE); /* main cpu interrupt (comes from CFB (generated at the start of INT routine on CFB) - vblank?) */ } static READ8_HANDLER( cfb_zpu_int_req_clr ) { - zpu_int_vector |= 2; + mazerbla_state *state = (mazerbla_state *)space->machine->driver_data; + + state->zpu_int_vector |= 2; /* clear the INT line when there are no more interrupt requests */ - if (zpu_int_vector == 0xff) - cputag_set_input_line(space->machine, "maincpu", 0, CLEAR_LINE); + if (state->zpu_int_vector == 0xff) + cpu_set_input_line(state->maincpu, 0, CLEAR_LINE); return 0; } static READ8_HANDLER( ls670_0_r ) { + mazerbla_state *state = (mazerbla_state *)space->machine->driver_data; + /* set a timer to force synchronization after the read */ timer_call_after_resynch(space->machine, NULL, 0, NULL); - return ls670_0[offset]; + return state->ls670_0[offset]; } static TIMER_CALLBACK( deferred_ls670_0_w ) { - int offset = (param>>8) & 255; + mazerbla_state *state = (mazerbla_state *)machine->driver_data; + int offset = (param >> 8) & 255; int data = param & 255; - ls670_0[offset] = data; + state->ls670_0[offset] = data; } static WRITE8_HANDLER( ls670_0_w ) { /* do this on a timer to let the CPUs synchronize */ - timer_call_after_resynch(space->machine, NULL, (offset<<8) | data, deferred_ls670_0_w); + timer_call_after_resynch(space->machine, NULL, (offset << 8) | data, deferred_ls670_0_w); } static READ8_HANDLER( ls670_1_r ) { + mazerbla_state *state = (mazerbla_state *)space->machine->driver_data; + /* set a timer to force synchronization after the read */ timer_call_after_resynch(space->machine, NULL, 0, NULL); - return ls670_1[offset]; + return state->ls670_1[offset]; } static TIMER_CALLBACK( deferred_ls670_1_w ) { - int offset = (param>>8) & 255; + mazerbla_state *state = (mazerbla_state *)machine->driver_data; + int offset = (param >> 8) & 255; int data = param & 255; - ls670_1[offset] = data; + state->ls670_1[offset] = data; } static WRITE8_HANDLER( ls670_1_w ) { /* do this on a timer to let the CPUs synchronize */ - timer_call_after_resynch(space->machine, NULL, (offset<<8) | data, deferred_ls670_1_w); + timer_call_after_resynch(space->machine, NULL, (offset << 8) | data, deferred_ls670_1_w); } @@ -836,18 +840,21 @@ Vertical movement of gun is Strobe 9, Bits 0-7. static WRITE8_HANDLER( zpu_bcd_decoder_w ) { + mazerbla_state *state = (mazerbla_state *)space->machine->driver_data; + /* bcd decoder used a input select (a mux) for reads from port 0x62 */ - bcd_7445 = data & 0xf; + state->bcd_7445 = data & 0xf; } static READ8_HANDLER( zpu_inputs_r ) { + mazerbla_state *state = (mazerbla_state *)space->machine->driver_data; static const char *const strobenames[] = { "ZPU", "DSW0", "DSW1", "DSW2", "DSW3", "BUTTONS", "STICK0_X", "STICK0_Y", "STICK1_X", "STICK1_Y", "UNUSED", "UNUSED", "UNUSED", "UNUSED", "UNUSED", "UNUSED" }; UINT8 ret = 0; - ret = input_port_read(space->machine, strobenames[bcd_7445]); + ret = input_port_read(space->machine, strobenames[state->bcd_7445]); return ret; } @@ -856,7 +863,7 @@ static WRITE8_HANDLER( zpu_led_w ) { /* 0x6e - reset (offset = 0)*/ /* 0x6f - set */ - set_led_status(space->machine, 0, offset&1 ); + set_led_status(space->machine, 0, offset & 1); } static WRITE8_HANDLER( zpu_lamps_w) @@ -864,26 +871,26 @@ static WRITE8_HANDLER( zpu_lamps_w) /* bit 4 = /LAMP0 */ /* bit 5 = /LAMP1 */ - /*set_led_status(space->machine, 0, (data&0x10)>>4 );*/ - /*set_led_status(space->machine, 1, (data&0x20)>>4 );*/ + /*set_led_status(space->machine, 0, (data & 0x10) >> 4);*/ + /*set_led_status(space->machine, 1, (data & 0x20) >> 4);*/ } static WRITE8_HANDLER( zpu_coin_counter_w ) { /* bit 6 = coin counter */ - coin_counter_w(space->machine, offset, (data&0x40)>>6 ); + coin_counter_w(space->machine, offset, BIT(data, 6)); } static WRITE8_HANDLER(cfb_led_w) { /* bit 7 - led on */ - set_led_status(space->machine, 2,(data&0x80)>>7); + set_led_status(space->machine, 2, BIT(data, 7)); } static WRITE8_DEVICE_HANDLER( gg_led_ctrl_w ) { /* bit 0, bit 1 - led on */ - set_led_status(device->machine,1,data&0x01); + set_led_status(device->machine, 1, BIT(data, 0)); } @@ -895,23 +902,26 @@ static WRITE8_DEVICE_HANDLER( gg_led_ctrl_w ) static WRITE8_HANDLER( vsb_ls273_audio_control_w ) { - vsb_ls273 = data; + mazerbla_state *state = (mazerbla_state *)space->machine->driver_data; + state->vsb_ls273 = data; /* bit 5 - led on */ - set_led_status(space->machine, 1,(data&0x20)>>5); + set_led_status(space->machine, 1, BIT(data, 5)); } static READ8_DEVICE_HANDLER( soundcommand_r ) { - return soundlatch; + mazerbla_state *state = (mazerbla_state *)device->machine->driver_data; + return state->soundlatch; } static TIMER_CALLBACK( delayed_sound_w ) { - soundlatch = param; + mazerbla_state *state = (mazerbla_state *)machine->driver_data; + state->soundlatch = param; /* cause NMI on sound CPU */ - cputag_set_input_line(machine, "sub", INPUT_LINE_NMI, ASSERT_LINE); + cpu_set_input_line(state->subcpu, INPUT_LINE_NMI, ASSERT_LINE); } static WRITE8_HANDLER( main_sound_w ) @@ -921,12 +931,14 @@ static WRITE8_HANDLER( main_sound_w ) static WRITE8_HANDLER( sound_int_clear_w ) { - cputag_set_input_line(space->machine, "sub", 0, CLEAR_LINE); + mazerbla_state *state = (mazerbla_state *)space->machine->driver_data; + cpu_set_input_line(state->subcpu, 0, CLEAR_LINE); } static WRITE8_HANDLER( sound_nmi_clear_w ) { - cputag_set_input_line(space->machine, "sub", INPUT_LINE_NMI, CLEAR_LINE); + mazerbla_state *state = (mazerbla_state *)space->machine->driver_data; + cpu_set_input_line(state->subcpu, INPUT_LINE_NMI, CLEAR_LINE); } @@ -940,7 +952,7 @@ static ADDRESS_MAP_START( mazerbla_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x0000, 0x7fff) AM_ROM AM_RANGE(0xc000, 0xc7ff) AM_RAM AM_SHARE("share1") AM_RANGE(0xd800, 0xd800) AM_READ(cfb_zpu_int_req_clr) - AM_RANGE(0xe000, 0xe7ff) AM_RAM AM_BASE_GENERIC(videoram) AM_SIZE_GENERIC(videoram) + AM_RANGE(0xe000, 0xe7ff) AM_RAM AM_BASE_SIZE_MEMBER(mazerbla_state, videoram, videoram_size) AM_RANGE(0xe800, 0xefff) AM_RAM ADDRESS_MAP_END @@ -970,11 +982,11 @@ static ADDRESS_MAP_START( mazerbla_cpu3_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x0000, 0x37ff) AM_ROM AM_RANGE(0x3800, 0x3fff) AM_RAM AM_SHARE("share1") AM_RANGE(0x4000, 0x5fff) AM_ROMBANK("bank1") /* GFX roms */ - AM_RANGE(0x4000, 0x4003) AM_WRITE(VCU_video_reg_w) - AM_RANGE(0x6000, 0x67ff) AM_RAM AM_BASE(&cfb_ram) /* Color Frame Buffer PCB, a.k.a. RAM for VCU commands and parameters */ - AM_RANGE(0xa000, 0xa7ff) AM_READ(VCU_set_cmd_param_r) /* VCU command and parameters LOAD */ - AM_RANGE(0xc000, 0xdfff) AM_READ(VCU_set_gfx_addr_r) /* gfx LOAD (blit) */ - AM_RANGE(0xe000, 0xffff) AM_READ(VCU_set_clr_addr_r) /* palette? LOAD */ + AM_RANGE(0x4000, 0x4003) AM_WRITE(vcu_video_reg_w) + AM_RANGE(0x6000, 0x67ff) AM_RAM AM_BASE_MEMBER(mazerbla_state, cfb_ram) /* Color Frame Buffer PCB, a.k.a. RAM for VCU commands and parameters */ + AM_RANGE(0xa000, 0xa7ff) AM_READ(vcu_set_cmd_param_r) /* VCU command and parameters LOAD */ + AM_RANGE(0xc000, 0xdfff) AM_READ(vcu_set_gfx_addr_r) /* gfx LOAD (blit) */ + AM_RANGE(0xe000, 0xffff) AM_READ(vcu_set_clr_addr_r) /* palette? LOAD */ ADDRESS_MAP_END static ADDRESS_MAP_START( mazerbla_cpu3_io_map, ADDRESS_SPACE_IO, 8 ) @@ -1367,7 +1379,8 @@ static IRQ_CALLBACK(irq_callback) note: 1111 11110 (0xfe) - cannot happen and is not handled by game */ - return (zpu_int_vector & ~1); /* D0->GND is performed on CFB board */ + mazerbla_state *state = (mazerbla_state *)device->machine->driver_data; + return (state->zpu_int_vector & ~1); /* D0->GND is performed on CFB board */ } /* frequency is 14.318 MHz/16/16/16/16 */ @@ -1383,32 +1396,86 @@ static INTERRUPT_GEN( sound_interrupt ) * *************************************/ +static MACHINE_START( mazerbla ) +{ + mazerbla_state *state = (mazerbla_state *)machine->driver_data; + + state->maincpu = devtag_get_device(machine, "maincpu"); + state->subcpu = devtag_get_device(machine, "sub"); + + state_save_register_global_array(machine, state->vcu_video_reg); + state_save_register_global(machine, state->vcu_gfx_addr); + state_save_register_global(machine, state->vcu_gfx_param_addr); + + state_save_register_global(machine, state->bknd_col); + state_save_register_global(machine, state->port02_status); + state_save_register_global(machine, state->vbank); + state_save_register_global(machine, state->xpos); + state_save_register_global(machine, state->ypos); + state_save_register_global(machine, state->pix_xsize); + state_save_register_global(machine, state->pix_ysize); + state_save_register_global(machine, state->color1); + state_save_register_global(machine, state->color2); + state_save_register_global(machine, state->mode); + state_save_register_global(machine, state->plane); + state_save_register_global_array(machine, state->lookup_ram); + state_save_register_global(machine, state->gfx_rom_bank); + + state_save_register_global_array(machine, state->ls670_0); + state_save_register_global_array(machine, state->ls670_1); + + state_save_register_global(machine, state->zpu_int_vector); + + state_save_register_global(machine, state->bcd_7445); + + state_save_register_global(machine, state->vsb_ls273); + state_save_register_global(machine, state->soundlatch); +} + static MACHINE_RESET( mazerbla ) { - game_id = MAZERBLA; - zpu_int_vector = 0xff; + mazerbla_state *state = (mazerbla_state *)machine->driver_data; + int i; + + state->zpu_int_vector = 0xff; + + state->bknd_col = 0xaa; + state->gfx_rom_bank = 0xff; + + state->vcu_gfx_addr = 0; + state->vcu_gfx_param_addr = 0; + state->port02_status = 0; + state->vbank = 0; + state->xpos = 0; + state->ypos = 0; + state->pix_xsize = 0; + state->pix_ysize = 0; + state->color1 = 0; + state->color2 = 0; + state->mode = 0; + state->plane = 0; + state->bcd_7445 = 0; + state->vsb_ls273 = 0; + state->soundlatch = 0; + + for (i = 0; i < 4; i++) + { + state->vcu_video_reg[i] = 0; + state->ls670_0[i] = 0; + state->ls670_1[i] = 0; + } + + memset(state->lookup_ram, 0, ARRAY_LENGTH(state->lookup_ram)); + cpu_set_irq_callback(devtag_get_device(machine, "maincpu"), irq_callback); } -static MACHINE_RESET( greatgun ) -{ - UINT8 *rom = memory_region(machine, "sub2"); - game_id = GREATGUN; - zpu_int_vector = 0xff; - cpu_set_irq_callback(devtag_get_device(machine, "maincpu"), irq_callback); - - -// patch VCU test -// VCU test starts at PC=0x56f - rom[0x05b6] = 0; - rom[0x05b7] = 0; -// so we also need to patch ROM checksum test - rom[0x037f] = 0; - rom[0x0380] = 0; -} - static MACHINE_DRIVER_START( mazerbla ) + + /* driver data */ + MDRV_DRIVER_DATA(mazerbla_state) + /* basic machine hardware */ MDRV_CPU_ADD("maincpu", Z80, MASTER_CLOCK) /* 4 MHz, no NMI, IM2 - vectors at 0xf8, 0xfa, 0xfc */ MDRV_CPU_PROGRAM_MAP(mazerbla_map) @@ -1429,6 +1496,7 @@ static MACHINE_DRIVER_START( mazerbla ) MDRV_CPU_VBLANK_INT("screen", irq0_line_hold) /* synchronization forced on the fly */ + MDRV_MACHINE_START(mazerbla) MDRV_MACHINE_RESET(mazerbla) /* video hardware */ @@ -1451,6 +1519,9 @@ MACHINE_DRIVER_END static MACHINE_DRIVER_START( greatgun ) + /* driver data */ + MDRV_DRIVER_DATA(mazerbla_state) + /* basic machine hardware */ MDRV_CPU_ADD("maincpu", Z80, MASTER_CLOCK) /* 4 MHz, no NMI, IM2 - vectors at 0xf8, 0xfa, 0xfc */ MDRV_CPU_PROGRAM_MAP(mazerbla_map) @@ -1469,7 +1540,8 @@ static MACHINE_DRIVER_START( greatgun ) */ MDRV_CPU_VBLANK_INT("screen", irq0_line_hold) - MDRV_MACHINE_RESET(greatgun) + MDRV_MACHINE_START(mazerbla) + MDRV_MACHINE_RESET(mazerbla) /* video hardware */ MDRV_SCREEN_ADD("screen", RASTER) @@ -1483,7 +1555,7 @@ static MACHINE_DRIVER_START( greatgun ) MDRV_PALETTE_INIT(mazerbla) MDRV_VIDEO_START(mazerbla) - MDRV_VIDEO_UPDATE(greatgun) + MDRV_VIDEO_UPDATE(mazerbla) /* sound hardware */ MDRV_SPEAKER_STANDARD_MONO("mono") @@ -1610,10 +1682,26 @@ ROM_END static DRIVER_INIT( mazerbla ) { - bknd_col = 0xaa; - gfx_rom_bank = 0xff; + mazerbla_state *state = (mazerbla_state *)machine->driver_data; + state->game_id = MAZERBLA; } -GAME( 1983, mazerbla, 0, mazerbla, mazerbla, mazerbla, ROT0, "Stern", "Mazer Blazer (set 1)", GAME_IMPERFECT_GRAPHICS | GAME_NO_SOUND | GAME_NOT_WORKING ) -GAME( 1983, mazerblaa,mazerbla, mazerbla, mazerbla, mazerbla, ROT0, "Stern", "Mazer Blazer (set 2)", GAME_IMPERFECT_GRAPHICS | GAME_NO_SOUND | GAME_NOT_WORKING ) -GAME( 1983, greatgun, 0, greatgun, greatgun, mazerbla, ROT0, "Stern", "Great Guns", GAME_IMPERFECT_GRAPHICS | GAME_NOT_WORKING ) +static DRIVER_INIT( greatgun ) +{ + mazerbla_state *state = (mazerbla_state *)machine->driver_data; + UINT8 *rom = memory_region(machine, "sub2"); + + state->game_id = GREATGUN; + + // patch VCU test + // VCU test starts at PC=0x56f + rom[0x05b6] = 0; + rom[0x05b7] = 0; + // so we also need to patch ROM checksum test + rom[0x037f] = 0; + rom[0x0380] = 0; +} + +GAME( 1983, mazerbla, 0, mazerbla, mazerbla, mazerbla, ROT0, "Stern", "Mazer Blazer (set 1)", GAME_IMPERFECT_GRAPHICS | GAME_NO_SOUND | GAME_NOT_WORKING | GAME_SUPPORTS_SAVE ) +GAME( 1983, mazerblaa, mazerbla, mazerbla, mazerbla, mazerbla, ROT0, "Stern", "Mazer Blazer (set 2)", GAME_IMPERFECT_GRAPHICS | GAME_NO_SOUND | GAME_NOT_WORKING | GAME_SUPPORTS_SAVE ) +GAME( 1983, greatgun, 0, greatgun, greatgun, greatgun, ROT0, "Stern", "Great Guns", GAME_IMPERFECT_GRAPHICS | GAME_NOT_WORKING | GAME_SUPPORTS_SAVE ) diff --git a/src/mame/drivers/mikie.c b/src/mame/drivers/mikie.c index 196c8d2117a..c70463f4b11 100644 --- a/src/mame/drivers/mikie.c +++ b/src/mame/drivers/mikie.c @@ -1,17 +1,17 @@ /*************************************************************************** -Mikie memory map (preliminary) + Mikie memory map (preliminary) -driver by Allard Van Der Bas + driver by Allard Van Der Bas -MAIN BOARD: -2800-288f Sprite RAM (288f, not 287f - quite unusual) -3800-3bff Color RAM -3c00-3fff Video RAM -4000-5fff ROM (?) -5ff0 Watchdog (?) -6000-ffff ROM + MAIN BOARD: + 2800-288f Sprite RAM (288f, not 287f - quite unusual) + 3800-3bff Color RAM + 3c00-3fff Video RAM + 4000-5fff ROM (?) + 5ff0 Watchdog (?) + 6000-ffff ROM ***************************************************************************/ @@ -21,43 +21,40 @@ MAIN BOARD: #include "cpu/m6809/m6809.h" #include "sound/sn76496.h" #include "includes/konamipt.h" +#include "includes/mikie.h" -extern UINT8 *mikie_videoram; -extern UINT8 *mikie_colorram; -extern WRITE8_HANDLER( mikie_videoram_w ); -extern WRITE8_HANDLER( mikie_colorram_w ); -extern WRITE8_HANDLER( mikie_palettebank_w ); -extern WRITE8_HANDLER( mikie_flipscreen_w ); +#define MIKIE_TIMER_RATE 512 -extern PALETTE_INIT( mikie ); -extern VIDEO_START( mikie ); -extern VIDEO_UPDATE( mikie ); +#define XTAL 14318180 +#define OSC 18432000 +#define CLK XTAL/4 -/* Read/Write Handlers */ + +/************************************* + * + * Memory handlers + * + *************************************/ static READ8_HANDLER( mikie_sh_timer_r ) { - int clock; - - #define TIMER_RATE 512 - - clock = cpu_get_total_cycles(space->cpu) / TIMER_RATE; + int clock = cpu_get_total_cycles(space->cpu) / MIKIE_TIMER_RATE; return clock; } static WRITE8_HANDLER( mikie_sh_irqtrigger_w ) { - static int last; + mikie_state *state = (mikie_state *)space->machine->driver_data; - if (last == 0 && data == 1) + if (state->last_irq == 0 && data == 1) { // setting bit 0 low then high triggers IRQ on the sound CPU - cputag_set_input_line_and_vector(space->machine, "audiocpu", 0, HOLD_LINE, 0xff); + cpu_set_input_line_and_vector(state->audiocpu, 0, HOLD_LINE, 0xff); } - last = data; + state->last_irq = data; } static WRITE8_HANDLER( mikie_coin_counter_w ) @@ -65,7 +62,11 @@ static WRITE8_HANDLER( mikie_coin_counter_w ) coin_counter_w(space->machine, offset, data); } -/* Memory Maps */ +/************************************* + * + * Address maps + * + *************************************/ static ADDRESS_MAP_START( mikie_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x0000, 0x00ff) AM_RAM @@ -82,10 +83,10 @@ static ADDRESS_MAP_START( mikie_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x2403, 0x2403) AM_READ_PORT("DSW2") AM_RANGE(0x2500, 0x2500) AM_READ_PORT("DSW0") AM_RANGE(0x2501, 0x2501) AM_READ_PORT("DSW1") - AM_RANGE(0x2800, 0x288f) AM_RAM AM_BASE_SIZE_GENERIC(spriteram) + AM_RANGE(0x2800, 0x288f) AM_RAM AM_BASE_SIZE_MEMBER(mikie_state, spriteram, spriteram_size) AM_RANGE(0x2890, 0x37ff) AM_RAM - AM_RANGE(0x3800, 0x3bff) AM_RAM_WRITE(mikie_colorram_w) AM_BASE(&mikie_colorram) - AM_RANGE(0x3c00, 0x3fff) AM_RAM_WRITE(mikie_videoram_w) AM_BASE(&mikie_videoram) + AM_RANGE(0x3800, 0x3bff) AM_RAM_WRITE(mikie_colorram_w) AM_BASE_MEMBER(mikie_state, colorram) + AM_RANGE(0x3c00, 0x3fff) AM_RAM_WRITE(mikie_videoram_w) AM_BASE_MEMBER(mikie_state, videoram) AM_RANGE(0x4000, 0x5fff) AM_ROM // Machine checks for extra rom AM_RANGE(0x6000, 0xffff) AM_ROM ADDRESS_MAP_END @@ -103,7 +104,11 @@ static ADDRESS_MAP_START( sound_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0xa003, 0xa003) AM_WRITENOP // ??? ADDRESS_MAP_END -/* Input Ports */ +/************************************* + * + * Input ports + * + *************************************/ static INPUT_PORTS_START( mikie ) PORT_START("SYSTEM") @@ -152,7 +157,12 @@ static INPUT_PORTS_START( mikie ) PORT_DIPSETTING( 0x00, DEF_STR( On ) ) INPUT_PORTS_END -/* Graphics Layouts */ + +/************************************* + * + * Graphics definitions + * + *************************************/ static const gfx_layout charlayout = { @@ -178,24 +188,44 @@ static const gfx_layout spritelayout = 128*8 /* every sprite takes 64 bytes */ }; -/* Graphics Decode Information */ - static GFXDECODE_START( mikie ) GFXDECODE_ENTRY( "gfx1", 0x0000, charlayout, 0, 16*8 ) GFXDECODE_ENTRY( "gfx2", 0x0000, spritelayout, 16*8*16, 16*8 ) GFXDECODE_ENTRY( "gfx2", 0x0001, spritelayout, 16*8*16, 16*8 ) GFXDECODE_END -/* Sound Interface */ -#define XTAL 14318180 -#define OSC 18432000 -#define CLK XTAL/4 +/************************************* + * + * Machine driver + * + *************************************/ -/* Machine Driver */ +static MACHINE_START( mikie ) +{ + mikie_state *state = (mikie_state *)machine->driver_data; + + state->maincpu = devtag_get_device(machine, "maincpu"); + state->audiocpu = devtag_get_device(machine, "audiocpu"); + + state_save_register_global(machine, state->palettebank); + state_save_register_global(machine, state->last_irq); +} + +static MACHINE_RESET( mikie ) +{ + mikie_state *state = (mikie_state *)machine->driver_data; + + state->palettebank = 0; + state->last_irq = 0; +} static MACHINE_DRIVER_START( mikie ) - // basic machine hardware + + /* driver data */ + MDRV_DRIVER_DATA(mikie_state) + + /* basic machine hardware */ MDRV_CPU_ADD("maincpu", M6809, OSC/12) MDRV_CPU_PROGRAM_MAP(mikie_map) MDRV_CPU_VBLANK_INT("screen", irq0_line_hold) @@ -203,8 +233,10 @@ static MACHINE_DRIVER_START( mikie ) MDRV_CPU_ADD("audiocpu", Z80, CLK) MDRV_CPU_PROGRAM_MAP(sound_map) - // video hardware + MDRV_MACHINE_START(mikie) + MDRV_MACHINE_RESET(mikie) + /* video hardware */ MDRV_SCREEN_ADD("screen", RASTER) MDRV_SCREEN_REFRESH_RATE(60.59) MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0)) @@ -219,7 +251,7 @@ static MACHINE_DRIVER_START( mikie ) MDRV_VIDEO_START(mikie) MDRV_VIDEO_UPDATE(mikie) - // sound hardware + /* sound hardware */ // on the pcb there are 2x76489AN but SN76489 sounds correct in the locker room level (sound test 24) MDRV_SPEAKER_STANDARD_MONO("mono") @@ -230,7 +262,11 @@ static MACHINE_DRIVER_START( mikie ) MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.60) MACHINE_DRIVER_END -/* ROMs */ +/************************************* + * + * ROM definition(s) + * + *************************************/ ROM_START( mikie ) ROM_REGION( 0x10000, "maincpu", 0 ) @@ -310,8 +346,12 @@ ROM_START( mikiehs ) ROM_LOAD( "d18.f9", 0x0400, 0x0100, CRC(7396b374) SHA1(fedcc421a61d6623dc9c41b0a3e164efeb50ec7c) ) // sprite lookup table ROM_END -/* Game Drivers */ +/************************************* + * + * Game driver(s) + * + *************************************/ -GAME( 1984, mikie, 0, mikie, mikie, 0, ROT270, "Konami", "Mikie", 0 ) -GAME( 1984, mikiej, mikie, mikie, mikie, 0, ROT270, "Konami", "Shinnyuushain Tooru-kun", 0 ) -GAME( 1984, mikiehs, mikie, mikie, mikie, 0, ROT270, "Konami", "Mikie (High School Graffiti)", 0 ) +GAME( 1984, mikie, 0, mikie, mikie, 0, ROT270, "Konami", "Mikie", GAME_SUPPORTS_SAVE ) +GAME( 1984, mikiej, mikie, mikie, mikie, 0, ROT270, "Konami", "Shinnyuushain Tooru-kun", GAME_SUPPORTS_SAVE ) +GAME( 1984, mikiehs, mikie, mikie, mikie, 0, ROT270, "Konami", "Mikie (High School Graffiti)", GAME_SUPPORTS_SAVE ) diff --git a/src/mame/drivers/mjsister.c b/src/mame/drivers/mjsister.c index 5b9c812556b..6d8796f5b5a 100644 --- a/src/mame/drivers/mjsister.c +++ b/src/mame/drivers/mjsister.c @@ -1,6 +1,6 @@ /***************************************************************************** -Mahjong Sisters (c) 1986 Toa Plan + Mahjong Sisters (c) 1986 Toa Plan Driver by Uki @@ -14,142 +14,262 @@ Mahjong Sisters (c) 1986 Toa Plan #define MCLK 12000000 -extern int mjsister_flip_screen; -extern int mjsister_video_enable; -extern int mjsister_screen_redraw; -extern int mjsister_vrambank; -extern int mjsister_colorbank; +typedef struct _mjsister_state mjsister_state; +struct _mjsister_state +{ + /* memory pointers */ + UINT8 * videoram0, *videoram1; -VIDEO_START( mjsister ); -VIDEO_UPDATE( mjsister ); -WRITE8_HANDLER( mjsister_videoram_w ); + /* video-related */ + bitmap_t *tmpbitmap0, *tmpbitmap1; + int flip_screen; + int video_enable; + int screen_redraw; + int vrambank; + int colorbank; -static int mjsister_input_sel1; -static int mjsister_input_sel2; + /* misc */ + int input_sel1; + int input_sel2; -static int rombank0,rombank1; + int rombank0,rombank1; -static UINT32 dac_adr,dac_bank,dac_adr_s,dac_adr_e,dac_busy; + UINT32 dac_adr, dac_bank, dac_adr_s, dac_adr_e, dac_busy; -/****************************************************************************/ + /* devices */ + running_device *maincpu; + running_device *dac; +}; + + +/************************************* + * + * Video emulation + * + *************************************/ + +static VIDEO_START( mjsister ) +{ + mjsister_state *state = (mjsister_state *)machine->driver_data; + state->tmpbitmap0 = auto_bitmap_alloc(machine, 256, 256, video_screen_get_format(machine->primary_screen)); + state->tmpbitmap1 = auto_bitmap_alloc(machine, 256, 256, video_screen_get_format(machine->primary_screen)); + state->videoram0 = auto_alloc_array(machine, UINT8, 0x8000); + state->videoram1 = auto_alloc_array(machine, UINT8, 0x8000); + + state_save_register_global_pointer(machine, state->videoram0, 0x8000); + state_save_register_global_pointer(machine, state->videoram1, 0x8000); +} + +static void mjsister_plot0( running_machine *machine, int offset, UINT8 data ) +{ + mjsister_state *state = (mjsister_state *)machine->driver_data; + int x, y, c1, c2; + + x = offset & 0x7f; + y = offset / 0x80; + + c1 = (data & 0x0f) + state->colorbank * 0x20; + c2 = ((data & 0xf0) >> 4) + state->colorbank * 0x20; + + *BITMAP_ADDR16(state->tmpbitmap0, y, x * 2 + 0) = c1; + *BITMAP_ADDR16(state->tmpbitmap0, y, x * 2 + 1) = c2; +} + +static void mjsister_plot1( running_machine *machine, int offset, UINT8 data ) +{ + mjsister_state *state = (mjsister_state *)machine->driver_data; + int x, y, c1, c2; + + x = offset & 0x7f; + y = offset / 0x80; + + c1 = data & 0x0f; + c2 = (data & 0xf0) >> 4; + + if (c1) + c1 += state->colorbank * 0x20 + 0x10; + if (c2) + c2 += state->colorbank * 0x20 + 0x10; + + *BITMAP_ADDR16(state->tmpbitmap1, y, x * 2 + 0) = c1; + *BITMAP_ADDR16(state->tmpbitmap1, y, x * 2 + 1) = c2; +} + +static WRITE8_HANDLER( mjsister_videoram_w ) +{ + mjsister_state *state = (mjsister_state *)space->machine->driver_data; + if (state->vrambank) + { + state->videoram1[offset] = data; + mjsister_plot1(space->machine, offset, data); + } + else + { + state->videoram0[offset] = data; + mjsister_plot0(space->machine, offset, data); + } +} + +static VIDEO_UPDATE( mjsister ) +{ + mjsister_state *state = (mjsister_state *)screen->machine->driver_data; + int flip = state->flip_screen; + int i, j; + + if (state->screen_redraw) + { + int offs; + + for (offs = 0; offs < 0x8000; offs++) + { + mjsister_plot0(screen->machine, offs, state->videoram0[offs]); + mjsister_plot1(screen->machine, offs, state->videoram1[offs]); + } + state->screen_redraw = 0; + } + + if (state->video_enable) + { + for (i = 0; i < 256; i++) + for (j = 0; j < 4; j++) + *BITMAP_ADDR16(bitmap, i, 256 + j) = state->colorbank * 0x20; + + copybitmap(bitmap, state->tmpbitmap0, flip, flip, 0, 0, cliprect); + copybitmap_trans(bitmap, state->tmpbitmap1, flip, flip, 2, 0, cliprect, 0); + } + else + bitmap_fill(bitmap, cliprect, get_black_pen(screen->machine)); + return 0; +} + +/************************************* + * + * Memory handlers + * + *************************************/ static TIMER_CALLBACK( dac_callback ) { + mjsister_state *state = (mjsister_state *)machine->driver_data; UINT8 *DACROM = memory_region(machine, "samples"); - dac_data_w(devtag_get_device(machine, "dac"),DACROM[(dac_bank * 0x10000 + dac_adr++) & 0x1ffff]); + dac_data_w(state->dac, DACROM[(state->dac_bank * 0x10000 + state->dac_adr++) & 0x1ffff]); - if (((dac_adr & 0xff00 ) >> 8) != dac_adr_e ) + if (((state->dac_adr & 0xff00 ) >> 8) != state->dac_adr_e) timer_set(machine, attotime_mul(ATTOTIME_IN_HZ(MCLK), 1024), NULL, 0, dac_callback); else - dac_busy = 0; + state->dac_busy = 0; } static WRITE8_HANDLER( mjsister_dac_adr_s_w ) { - dac_adr_s = data; + mjsister_state *state = (mjsister_state *)space->machine->driver_data; + state->dac_adr_s = data; } static WRITE8_HANDLER( mjsister_dac_adr_e_w ) { - dac_adr_e = data; - dac_adr = dac_adr_s << 8; + mjsister_state *state = (mjsister_state *)space->machine->driver_data; + state->dac_adr_e = data; + state->dac_adr = state->dac_adr_s << 8; - if (dac_busy == 0) - timer_call_after_resynch(space->machine, NULL, 0,dac_callback); + if (state->dac_busy == 0) + timer_call_after_resynch(space->machine, NULL, 0, dac_callback); - dac_busy = 1; -} - -static MACHINE_RESET( mjsister ) -{ - dac_busy = 0; + state->dac_busy = 1; } static WRITE8_HANDLER( mjsister_banksel1_w ) { - UINT8 *BANKROM = memory_region(space->machine, "maincpu"); - int tmp = mjsister_colorbank; + mjsister_state *state = (mjsister_state *)space->machine->driver_data; + int tmp = state->colorbank; switch (data) { - case 0x0: rombank0 = 0 ; break; - case 0x1: rombank0 = 1 ; break; + case 0x0: state->rombank0 = 0 ; break; + case 0x1: state->rombank0 = 1 ; break; - case 0x2: mjsister_flip_screen = 0 ; break; - case 0x3: mjsister_flip_screen = 1 ; break; + case 0x2: state->flip_screen = 0 ; break; + case 0x3: state->flip_screen = 1 ; break; - case 0x4: mjsister_colorbank &=0xfe; break; - case 0x5: mjsister_colorbank |=0x01; break; - case 0x6: mjsister_colorbank &=0xfd; break; - case 0x7: mjsister_colorbank |=0x02; break; - case 0x8: mjsister_colorbank &=0xfb; break; - case 0x9: mjsister_colorbank |=0x04; break; + case 0x4: state->colorbank &= 0xfe; break; + case 0x5: state->colorbank |= 0x01; break; + case 0x6: state->colorbank &= 0xfd; break; + case 0x7: state->colorbank |= 0x02; break; + case 0x8: state->colorbank &= 0xfb; break; + case 0x9: state->colorbank |= 0x04; break; - case 0xa: mjsister_video_enable = 0 ; break; - case 0xb: mjsister_video_enable = 1 ; break; + case 0xa: state->video_enable = 0 ; break; + case 0xb: state->video_enable = 1 ; break; - case 0xe: mjsister_vrambank = 0 ; break; - case 0xf: mjsister_vrambank = 1 ; break; + case 0xe: state->vrambank = 0 ; break; + case 0xf: state->vrambank = 1 ; break; default: - logerror("%04x p30_w:%02x\n",cpu_get_pc(space->cpu),data); + logerror("%04x p30_w:%02x\n", cpu_get_pc(space->cpu), data); } - if (tmp != mjsister_colorbank) - mjsister_screen_redraw = 1; + if (tmp != state->colorbank) + state->screen_redraw = 1; - memory_set_bankptr(space->machine, "bank1",&BANKROM[rombank0*0x10000+rombank1*0x8000]+0x10000); + memory_set_bank(space->machine, "bank1", state->rombank0 * 2 + state->rombank1); } static WRITE8_HANDLER( mjsister_banksel2_w ) { - UINT8 *BANKROM = memory_region(space->machine, "maincpu"); + mjsister_state *state = (mjsister_state *)space->machine->driver_data; switch (data) { - case 0xa: dac_bank = 0; break; - case 0xb: dac_bank = 1; break; + case 0xa: state->dac_bank = 0; break; + case 0xb: state->dac_bank = 1; break; - case 0xc: rombank1 = 0; break; - case 0xd: rombank1 = 1; break; + case 0xc: state->rombank1 = 0; break; + case 0xd: state->rombank1 = 1; break; default: - logerror("%04x p31_w:%02x\n",cpu_get_pc(space->cpu),data); + logerror("%04x p31_w:%02x\n", cpu_get_pc(space->cpu), data); } - memory_set_bankptr(space->machine, "bank1",&BANKROM[rombank0*0x10000+rombank1*0x8000]+0x10000); + memory_set_bank(space->machine, "bank1", state->rombank0 * 2 + state->rombank1); } static WRITE8_HANDLER( mjsister_input_sel1_w ) { - mjsister_input_sel1 = data; + mjsister_state *state = (mjsister_state *)space->machine->driver_data; + state->input_sel1 = data; } static WRITE8_HANDLER( mjsister_input_sel2_w ) { - mjsister_input_sel2 = data; + mjsister_state *state = (mjsister_state *)space->machine->driver_data; + state->input_sel2 = data; } static READ8_HANDLER( mjsister_keys_r ) { - int p,i,ret = 0; + mjsister_state *state = (mjsister_state *)space->machine->driver_data; + int p, i, ret = 0; static const char *const keynames[] = { "KEY0", "KEY1", "KEY2", "KEY3", "KEY4", "KEY5" }; - p = mjsister_input_sel1 & 0x3f; -// p |= ((mjsister_input_sel2 & 8) << 4) | ((mjsister_input_sel2 & 0x20) << 1); + p = state->input_sel1 & 0x3f; + // p |= ((state->input_sel2 & 8) << 4) | ((state->input_sel2 & 0x20) << 1); - for (i=0; i<6; i++) + for (i = 0; i < 6; i++) { - if (p & (1 << i)) + if (BIT(p, i)) ret |= input_port_read(space->machine, keynames[i]); } return ret; } -/****************************************************************************/ +/************************************* + * + * Address maps + * + *************************************/ static ADDRESS_MAP_START( mjsister_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x0000, 0x77ff) AM_ROM @@ -174,11 +294,14 @@ static ADDRESS_MAP_START( mjsister_io_map, ADDRESS_SPACE_IO, 8 ) ADDRESS_MAP_END -/****************************************************************************/ +/************************************* + * + * Input ports + * + *************************************/ static INPUT_PORTS_START( mjsister ) - - PORT_START("DSW1") /* DSW1 (0) */ + PORT_START("DSW1") PORT_DIPNAME( 0x07, 0x07, DEF_STR( Coinage ) ) PORT_DIPSETTING( 0x03, DEF_STR( 5C_1C ) ) PORT_DIPSETTING( 0x00, DEF_STR( 4C_1C ) ) @@ -202,7 +325,7 @@ static INPUT_PORTS_START( mjsister ) PORT_DIPSETTING( 0x80, DEF_STR( Off ) ) PORT_DIPSETTING( 0x00, DEF_STR( On ) ) - PORT_START("DSW2") /* DSW2 (1) */ + PORT_START("DSW2") PORT_DIPNAME( 0x01, 0x01, "Unknown 2-1" ) PORT_DIPSETTING( 0x01, DEF_STR( Off ) ) PORT_DIPSETTING( 0x00, DEF_STR( On ) ) @@ -228,7 +351,7 @@ static INPUT_PORTS_START( mjsister ) PORT_DIPSETTING( 0x80, DEF_STR( Off ) ) PORT_DIPSETTING( 0x00, DEF_STR( On ) ) - PORT_START("IN0") /* (2) */ + PORT_START("IN0") PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN2 ) PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_UNKNOWN ) /* memory reset 1 */ PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNKNOWN ) /* analyzer */ @@ -238,57 +361,61 @@ static INPUT_PORTS_START( mjsister ) PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_COIN1 ) PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_UNKNOWN ) /* hopper */ - PORT_START("KEY0") /* (3) PORT 1-0 */ - PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_MAHJONG_A ) - PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_MAHJONG_B ) - PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_MAHJONG_C ) - PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_MAHJONG_D ) - PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_MAHJONG_LAST_CHANCE ) + PORT_START("KEY0") + PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_MAHJONG_A ) + PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_MAHJONG_B ) + PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_MAHJONG_C ) + PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_MAHJONG_D ) + PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_MAHJONG_LAST_CHANCE ) PORT_BIT( 0xe0, IP_ACTIVE_HIGH, IPT_UNUSED ) - PORT_START("KEY1") /* (4) PORT 1-1 */ - PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_MAHJONG_E ) - PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_MAHJONG_F ) - PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_MAHJONG_G ) - PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_MAHJONG_H ) - PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_MAHJONG_SCORE ) + PORT_START("KEY1") + PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_MAHJONG_E ) + PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_MAHJONG_F ) + PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_MAHJONG_G ) + PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_MAHJONG_H ) + PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_MAHJONG_SCORE ) PORT_BIT( 0xe0, IP_ACTIVE_HIGH, IPT_UNUSED ) - PORT_START("KEY2") /* (5) PORT 1-2 */ - PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_MAHJONG_I ) - PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_MAHJONG_J ) - PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_MAHJONG_K ) - PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_MAHJONG_L ) - PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_MAHJONG_DOUBLE_UP ) + PORT_START("KEY2") + PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_MAHJONG_I ) + PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_MAHJONG_J ) + PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_MAHJONG_K ) + PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_MAHJONG_L ) + PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_MAHJONG_DOUBLE_UP ) PORT_BIT( 0xe0, IP_ACTIVE_HIGH, IPT_UNUSED ) - PORT_START("KEY3") /* (6) PORT 1-3 */ - PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_MAHJONG_M ) - PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_MAHJONG_N ) - PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_MAHJONG_CHI ) - PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_MAHJONG_PON ) - PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_MAHJONG_FLIP_FLOP ) + PORT_START("KEY3") + PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_MAHJONG_M ) + PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_MAHJONG_N ) + PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_MAHJONG_CHI ) + PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_MAHJONG_PON ) + PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_MAHJONG_FLIP_FLOP ) PORT_BIT( 0xe0, IP_ACTIVE_HIGH, IPT_UNUSED ) - PORT_START("KEY4") /* (7) PORT 1-4 */ - PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_MAHJONG_KAN ) - PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_MAHJONG_REACH ) - PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_MAHJONG_RON ) + PORT_START("KEY4") + PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_MAHJONG_KAN ) + PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_MAHJONG_REACH ) + PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_MAHJONG_RON ) PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNKNOWN ) - PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_MAHJONG_BIG ) + PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_MAHJONG_BIG ) PORT_BIT( 0xe0, IP_ACTIVE_HIGH, IPT_UNUSED ) - PORT_START("KEY5") /* (8) PORT 1-5 */ + PORT_START("KEY5") PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_START1 ) - PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_MAHJONG_BET ) + PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_MAHJONG_BET ) PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNKNOWN ) PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNKNOWN ) - PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_MAHJONG_SMALL ) + PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_MAHJONG_SMALL ) PORT_BIT( 0xe0, IP_ACTIVE_HIGH, IPT_UNUSED ) INPUT_PORTS_END -/****************************************************************************/ +/************************************* + * + * Sound interface + * + *************************************/ static const ay8910_interface ay8910_config = { @@ -300,14 +427,79 @@ static const ay8910_interface ay8910_config = DEVCB_NULL }; +/************************************* + * + * Machine driver + * + *************************************/ + +static STATE_POSTLOAD( mjsister_redraw ) +{ + mjsister_state *state = (mjsister_state *)machine->driver_data; + + /* we can skip saving tmpbitmaps because we can redraw them from vram */ + state->screen_redraw = 1; +} + +static MACHINE_START( mjsister ) +{ + mjsister_state *state = (mjsister_state *)machine->driver_data; + UINT8 *ROM = memory_region(machine, "maincpu"); + + memory_configure_bank(machine, "bank1", 0, 4, &ROM[0x10000], 0x8000); + + state->maincpu = devtag_get_device(machine, "maincpu"); + state->dac = devtag_get_device(machine, "dac"); + + state_save_register_global(machine, state->dac_busy); + state_save_register_global(machine, state->flip_screen); + state_save_register_global(machine, state->video_enable); + state_save_register_global(machine, state->vrambank); + state_save_register_global(machine, state->colorbank); + state_save_register_global(machine, state->input_sel1); + state_save_register_global(machine, state->input_sel2); + state_save_register_global(machine, state->rombank0); + state_save_register_global(machine, state->rombank1); + state_save_register_global(machine, state->dac_adr); + state_save_register_global(machine, state->dac_bank); + state_save_register_global(machine, state->dac_adr_s); + state_save_register_global(machine, state->dac_adr_e); + state_save_register_postload(machine, mjsister_redraw, 0); +} + +static MACHINE_RESET( mjsister ) +{ + mjsister_state *state = (mjsister_state *)machine->driver_data; + + state->dac_busy = 0; + state->flip_screen = 0; + state->video_enable = 0; + state->screen_redraw = 0; + state->vrambank = 0; + state->colorbank = 0; + state->input_sel1 = 0; + state->input_sel2 = 0; + state->rombank0 = 0; + state->rombank1 = 0; + state->dac_adr = 0; + state->dac_bank = 0; + state->dac_adr_s = 0; + state->dac_adr_e = 0; +} + + static MACHINE_DRIVER_START( mjsister ) + /* driver data */ + MDRV_DRIVER_DATA(mjsister_state) + /* basic machine hardware */ MDRV_CPU_ADD("maincpu", Z80, MCLK/2) /* 6.000 MHz */ MDRV_CPU_PROGRAM_MAP(mjsister_map) MDRV_CPU_IO_MAP(mjsister_io_map) MDRV_CPU_VBLANK_INT_HACK(irq0_line_hold,2) + MDRV_MACHINE_START(mjsister) MDRV_MACHINE_RESET(mjsister) /* video hardware */ @@ -335,11 +527,11 @@ static MACHINE_DRIVER_START( mjsister ) MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0) MACHINE_DRIVER_END -/*************************************************************************** - - Game driver(s) - -***************************************************************************/ +/************************************* + * + * ROM definition(s) + * + *************************************/ ROM_START( mjsister ) ROM_REGION( 0x30000, "maincpu", 0 ) /* CPU */ @@ -358,5 +550,11 @@ ROM_START( mjsister ) ROM_LOAD( "ms08.bpr", 0x0300, 0x0100, CRC(da2b3b38) SHA1(4de99c17b227653bc1b904f1309f447f5a0ab516) ) // ? ROM_END -GAME( 1986, mjsister, 0, mjsister, mjsister, 0, ROT0, "Toaplan", "Mahjong Sisters (Japan)", 0 ) +/************************************* + * + * Game driver(s) + * + *************************************/ + +GAME( 1986, mjsister, 0, mjsister, mjsister, 0, ROT0, "Toaplan", "Mahjong Sisters (Japan)", GAME_SUPPORTS_SAVE ) diff --git a/src/mame/drivers/mogura.c b/src/mame/drivers/mogura.c index 6b8b45cd055..d303759213a 100644 --- a/src/mame/drivers/mogura.c +++ b/src/mame/drivers/mogura.c @@ -5,112 +5,129 @@ #include "sound/dac.h" #include "includes/konamipt.h" -static UINT8 *mogura_tileram; -static UINT8* mogura_gfxram; -static tilemap_t *mogura_tilemap; +typedef struct _mogura_state mogura_state; +struct _mogura_state +{ + /* memory pointers */ + UINT8 * tileram; + UINT8 * gfxram; + + /* video-related */ + tilemap_t *tilemap; + + /* devices */ + running_device *maincpu; + running_device *dac1; + running_device *dac2; +}; + static PALETTE_INIT( mogura ) { - int i,j; + int i, j; j = 0; - for (i = 0;i < 0x20;i++) + for (i = 0; i < 0x20; i++) { - int bit0,bit1,bit2,r,g,b; + int bit0, bit1, bit2, r, g, b; /* red component */ - bit0 = (color_prom[i] >> 0) & 0x01; - bit1 = (color_prom[i] >> 1) & 0x01; - bit2 = (color_prom[i] >> 2) & 0x01; + bit0 = BIT(color_prom[i], 0); + bit1 = BIT(color_prom[i], 1); + bit2 = BIT(color_prom[i], 2); r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; /* green component */ - bit0 = (color_prom[i] >> 3) & 0x01; - bit1 = (color_prom[i] >> 4) & 0x01; - bit2 = (color_prom[i] >> 5) & 0x01; + bit0 = BIT(color_prom[i], 3); + bit1 = BIT(color_prom[i], 4); + bit2 = BIT(color_prom[i], 5); g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; /* blue component */ bit0 = 0; - bit1 = (color_prom[i] >> 6) & 0x01; - bit2 = (color_prom[i] >> 7) & 0x01; + bit1 = BIT(color_prom[i], 6); + bit2 = BIT(color_prom[i], 7); b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; - palette_set_color(machine,j,MAKE_RGB(r,g,b)); - j+=4; - if (j>31) j-=31; + palette_set_color(machine, j, MAKE_RGB(r, g, b)); + j += 4; + if (j > 31) j -= 31; } } static TILE_GET_INFO( get_mogura_tile_info ) { - int code = mogura_tileram[tile_index]; - int attr = mogura_tileram[tile_index+0x800]; + mogura_state *state = (mogura_state *)machine->driver_data; + int code = state->tileram[tile_index]; + int attr = state->tileram[tile_index + 0x800]; SET_TILE_INFO( 0, code, - (attr>>1)&7, + (attr >> 1) & 7, 0); } static VIDEO_START( mogura ) { - gfx_element_set_source(machine->gfx[0], mogura_gfxram); - mogura_tilemap = tilemap_create(machine, get_mogura_tile_info,tilemap_scan_rows,8,8,64, 32); + mogura_state *state = (mogura_state *)machine->driver_data; + gfx_element_set_source(machine->gfx[0], state->gfxram); + state->tilemap = tilemap_create(machine, get_mogura_tile_info, tilemap_scan_rows, 8, 8, 64, 32); } static VIDEO_UPDATE( mogura ) { + mogura_state *state = (mogura_state *)screen->machine->driver_data; const rectangle *visarea = video_screen_get_visible_area(screen); /* tilemap layout is a bit strange ... */ rectangle clip; clip.min_x = visarea->min_x; - clip.max_x = 256-1; + clip.max_x = 256 - 1; clip.min_y = visarea->min_y; clip.max_y = visarea->max_y; - tilemap_set_scrollx(mogura_tilemap,0, 256); - tilemap_draw(bitmap,&clip,mogura_tilemap,0,0); + tilemap_set_scrollx(state->tilemap, 0, 256); + tilemap_draw(bitmap, &clip, state->tilemap, 0, 0); clip.min_x = 256; - clip.max_x = 512-1; + clip.max_x = 512 - 1; clip.min_y = visarea->min_y; clip.max_y = visarea->max_y; - tilemap_set_scrollx(mogura_tilemap,0, -128); - tilemap_draw(bitmap,&clip,mogura_tilemap,0,0); + tilemap_set_scrollx(state->tilemap, 0, -128); + tilemap_draw(bitmap, &clip, state->tilemap, 0, 0); return 0; } static WRITE8_HANDLER( mogura_tileram_w ) { - mogura_tileram[offset] = data; - tilemap_mark_tile_dirty(mogura_tilemap,offset&0x7ff); + mogura_state *state = (mogura_state *)space->machine->driver_data; + state->tileram[offset] = data; + tilemap_mark_tile_dirty(state->tilemap, offset & 0x7ff); } static WRITE8_HANDLER(mogura_dac_w) { - dac_data_w(devtag_get_device(space->machine, "dac1"), data & 0xf0 ); /* left */ - dac_data_w(devtag_get_device(space->machine, "dac2"), (data & 0x0f)<<4 ); /* right */ + mogura_state *state = (mogura_state *)space->machine->driver_data; + dac_data_w(state->dac1, data & 0xf0); /* left */ + dac_data_w(state->dac2, (data & 0x0f) << 4); /* right */ } - - static WRITE8_HANDLER ( mogura_gfxram_w ) { - mogura_gfxram[offset] = data ; + mogura_state *state = (mogura_state *)space->machine->driver_data; + state->gfxram[offset] = data ; - gfx_element_mark_dirty(space->machine->gfx[0], offset/16); + gfx_element_mark_dirty(space->machine->gfx[0], offset / 16); } static ADDRESS_MAP_START( mogura_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x0000, 0x7fff) AM_ROM AM_RANGE(0xc000, 0xdfff) AM_RAM // main ram - AM_RANGE(0xe000, 0xefff) AM_RAM_WRITE(mogura_gfxram_w) AM_BASE(&mogura_gfxram) // ram based characters - AM_RANGE(0xf000, 0xffff) AM_RAM_WRITE(mogura_tileram_w) AM_BASE(&mogura_tileram) // tilemap + AM_RANGE(0xe000, 0xefff) AM_RAM_WRITE(mogura_gfxram_w) AM_BASE_MEMBER(mogura_state, gfxram) // ram based characters + AM_RANGE(0xf000, 0xffff) AM_RAM_WRITE(mogura_tileram_w) AM_BASE_MEMBER(mogura_state, tileram) // tilemap ADDRESS_MAP_END static ADDRESS_MAP_START( mogura_io_map, ADDRESS_SPACE_IO, 8 ) @@ -170,13 +187,28 @@ static GFXDECODE_START( mogura ) GFXDECODE_ENTRY( NULL, 0, tiles8x8_layout, 0, 8 ) GFXDECODE_END +static MACHINE_START( mogura ) +{ + mogura_state *state = (mogura_state *)machine->driver_data; + + state->maincpu = devtag_get_device(machine, "maincpu"); + state->dac1 = devtag_get_device(machine, "dac1"); + state->dac2 = devtag_get_device(machine, "dac2"); +} + static MACHINE_DRIVER_START( mogura ) + + /* driver data */ + MDRV_DRIVER_DATA(mogura_state) + /* basic machine hardware */ MDRV_CPU_ADD("maincpu", Z80,3000000) /* 3 MHz */ MDRV_CPU_PROGRAM_MAP(mogura_map) MDRV_CPU_IO_MAP(mogura_io_map) MDRV_CPU_VBLANK_INT("screen", irq0_line_hold) + MDRV_MACHINE_START(mogura) + MDRV_GFXDECODE(mogura) /* video hardware */ @@ -211,4 +243,4 @@ ROM_START( mogura ) ROM_LOAD( "gx141.7j", 0x00, 0x20, CRC(b21c5d5f) SHA1(6913c840dd69a7d4687f4c4cbe3ff12300f62bc2) ) ROM_END -GAME( 1991, mogura, 0, mogura, mogura, 0, ROT0, "Konami", "Mogura Desse (Japan)", 0 ) +GAME( 1991, mogura, 0, mogura, mogura, 0, ROT0, "Konami", "Mogura Desse (Japan)", GAME_SUPPORTS_SAVE ) diff --git a/src/mame/drivers/mole.c b/src/mame/drivers/mole.c index ec9002d24a6..08b784a568b 100644 --- a/src/mame/drivers/mole.c +++ b/src/mame/drivers/mole.c @@ -1,4 +1,6 @@ -/* MOLE ATTACK by Yachiyo Electronics Co.,LTD. 1982 +/***************************************************************************** + + MOLE ATTACK by Yachiyo Electronics Co.,LTD. 1982 Known Clones: "Holey Moley", from tai (Thomas Automatics, Inc.) @@ -43,21 +45,93 @@ 0x3DC affects mole popmessage 0x3E5 round point/passing point control? 0x3E7 round point/passing point control? -*/ +******************************************************************************/ #include "emu.h" #include "cpu/m6502/m6502.h" #include "sound/ay8910.h" -WRITE8_HANDLER(mole_videoram_w); -WRITE8_HANDLER(mole_tilebank_w); -WRITE8_HANDLER(mole_flipscreen_w); -PALETTE_INIT(mole); -VIDEO_START(mole); -VIDEO_UPDATE(mole); +typedef struct _mole_state mole_state; +struct _mole_state +{ + /* memory pointers */ + UINT16 * tileram; + /* video-related */ + tilemap_t *bg_tilemap; + int tile_bank; +}; + + +/************************************* + * + * Video emulation + * + *************************************/ + +static PALETTE_INIT( mole ) +{ + int i; + + for (i = 0; i < 8; i++) + palette_set_color_rgb(machine, i, pal1bit(i >> 0), pal1bit(i >> 2), pal1bit(i >> 1)); +} + +static TILE_GET_INFO( get_bg_tile_info ) +{ + mole_state *state = (mole_state *)machine->driver_data; + UINT16 code = state->tileram[tile_index]; + + SET_TILE_INFO((code & 0x200) ? 1 : 0, code & 0x1ff, 0, 0); +} + +static VIDEO_START( mole ) +{ + mole_state *state = (mole_state *)machine->driver_data; + state->tileram = auto_alloc_array_clear(machine, UINT16, 0x400); + state->bg_tilemap = tilemap_create(machine, get_bg_tile_info, tilemap_scan_rows, 8, 8, 40, 25); + + state_save_register_global_pointer(machine, state->tileram, 0x400); +} + +static WRITE8_HANDLER( mole_videoram_w ) +{ + mole_state *state = (mole_state *)space->machine->driver_data; + + state->tileram[offset] = data | (state->tile_bank << 8); + tilemap_mark_tile_dirty(state->bg_tilemap, offset); +} + +static WRITE8_HANDLER( mole_tilebank_w ) +{ + mole_state *state = (mole_state *)space->machine->driver_data; + + state->tile_bank = data; + tilemap_mark_all_tiles_dirty(state->bg_tilemap); +} + +static WRITE8_HANDLER( mole_flipscreen_w ) +{ + flip_screen_set(space->machine, data & 0x01); +} + +static VIDEO_UPDATE( mole ) +{ + mole_state *state = (mole_state *)screen->machine->driver_data; + + tilemap_draw(bitmap, cliprect, state->bg_tilemap, 0, 0); + return 0; +} + + + +/************************************* + * + * Memory handlers + * + *************************************/ static READ8_HANDLER( mole_protection_r ) { @@ -109,6 +183,12 @@ static READ8_HANDLER( mole_protection_r ) } +/************************************* + * + * Address maps + * + *************************************/ + static ADDRESS_MAP_START( mole_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x0000, 0x03ff) AM_RAM AM_RANGE(0x0800, 0x08ff) AM_READ(mole_protection_r) @@ -128,6 +208,12 @@ static ADDRESS_MAP_START( mole_map, ADDRESS_SPACE_PROGRAM, 8 ) ADDRESS_MAP_END +/************************************* + * + * Input ports + * + *************************************/ + static INPUT_PORTS_START( mole ) PORT_START("DSW") /* 0x8d00 */ PORT_DIPNAME( 0x01, 0x00, "Round Points" ) @@ -181,6 +267,12 @@ static INPUT_PORTS_START( mole ) INPUT_PORTS_END +/************************************* + * + * Graphics definitions + * + *************************************/ + static const gfx_layout tile_layout = { 8,8, /* character size */ @@ -199,14 +291,40 @@ static GFXDECODE_START( mole ) GFXDECODE_END +/************************************* + * + * Machine driver + * + *************************************/ + +static MACHINE_START( mole ) +{ + mole_state *state = (mole_state *)machine->driver_data; + + state_save_register_global(machine, state->tile_bank); +} + +static MACHINE_RESET( mole ) +{ + mole_state *state = (mole_state *)machine->driver_data; + + state->tile_bank = 0; +} + static MACHINE_DRIVER_START( mole ) - // basic machine hardware + + /* driver data */ + MDRV_DRIVER_DATA(mole_state) + + /* basic machine hardware */ MDRV_CPU_ADD("maincpu", M6502, 4000000) // ??? MDRV_CPU_PROGRAM_MAP(mole_map) MDRV_CPU_VBLANK_INT("screen", irq0_line_hold) - // video hardware + MDRV_MACHINE_START(mole) + MDRV_MACHINE_RESET(mole) + /* video hardware */ MDRV_SCREEN_ADD("screen", RASTER) MDRV_SCREEN_REFRESH_RATE(60) MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0)) @@ -221,7 +339,7 @@ static MACHINE_DRIVER_START( mole ) MDRV_VIDEO_START(mole) MDRV_VIDEO_UPDATE(mole) - // sound hardware + /* sound hardware */ MDRV_SPEAKER_STANDARD_MONO("mono") MDRV_SOUND_ADD("aysnd", AY8910, 2000000) @@ -229,6 +347,12 @@ static MACHINE_DRIVER_START( mole ) MACHINE_DRIVER_END +/************************************* + * + * ROM definition(s) + * + *************************************/ + ROM_START( mole ) // ALL ROMS ARE 2732 ROM_REGION( 0x10000, "maincpu", 0 ) // 64k for 6502 code ROM_LOAD( "m3a.5h", 0x5000, 0x1000, CRC(5fbbdfef) SHA1(8129e90a05b3ca50f47f7610eec51c16c8609590) ) @@ -245,4 +369,10 @@ ROM_START( mole ) // ALL ROMS ARE 2732 ROM_END -GAME( 1982, mole, 0, mole, mole, 0, ROT0, "Yachiyo Electronics, Ltd.", "Mole Attack", 0 ) +/************************************* + * + * Game driver(s) + * + *************************************/ + +GAME( 1982, mole, 0, mole, mole, 0, ROT0, "Yachiyo Electronics, Ltd.", "Mole Attack", GAME_SUPPORTS_SAVE ) diff --git a/src/mame/drivers/momoko.c b/src/mame/drivers/momoko.c index b0492507b0f..bc8e7e14ae0 100644 --- a/src/mame/drivers/momoko.c +++ b/src/mame/drivers/momoko.c @@ -1,6 +1,6 @@ /***************************************************************************** -Momoko 120% (c) 1986 Jaleco + Momoko 120% (c) 1986 Jaleco Driver by Uki @@ -44,28 +44,12 @@ Stephh's notes (based on the game Z80 code and some tests) : #include "emu.h" #include "cpu/z80/z80.h" #include "sound/2203intf.h" +#include "includes/momoko.h" -extern UINT8 *momoko_bg_scrollx; -extern UINT8 *momoko_bg_scrolly; - -VIDEO_UPDATE( momoko ); - -WRITE8_HANDLER( momoko_fg_scrollx_w ); -WRITE8_HANDLER( momoko_fg_scrolly_w ); -WRITE8_HANDLER( momoko_text_scrolly_w ); -WRITE8_HANDLER( momoko_text_mode_w ); -WRITE8_HANDLER( momoko_bg_scrollx_w ); -WRITE8_HANDLER( momoko_bg_scrolly_w ); -WRITE8_HANDLER( momoko_flipscreen_w ); -WRITE8_HANDLER( momoko_fg_select_w); -WRITE8_HANDLER( momoko_bg_select_w); -WRITE8_HANDLER( momoko_bg_priority_w); static WRITE8_HANDLER( momoko_bg_read_bank_w ) { - UINT8 *BG_MAP = memory_region(space->machine, "user1"); - int bank_address = (data & 0x1f) * 0x1000; - memory_set_bankptr(space->machine, "bank1", &BG_MAP[bank_address]); + memory_set_bank(space->machine, "bank1", data & 0x1f); } /****************************************************************************/ @@ -73,7 +57,7 @@ static WRITE8_HANDLER( momoko_bg_read_bank_w ) static ADDRESS_MAP_START( momoko_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x0000, 0xbfff) AM_ROM AM_RANGE(0xc000, 0xcfff) AM_RAM - AM_RANGE(0xd064, 0xd0ff) AM_RAM AM_BASE_SIZE_GENERIC(spriteram) + AM_RANGE(0xd064, 0xd0ff) AM_RAM AM_BASE_SIZE_MEMBER(momoko_state, spriteram, spriteram_size) AM_RANGE(0xd400, 0xd400) AM_READ_PORT("IN0") AM_WRITENOP /* interrupt ack? */ AM_RANGE(0xd402, 0xd402) AM_READ_PORT("IN1") AM_WRITE(momoko_flipscreen_w) AM_RANGE(0xd404, 0xd404) AM_WRITE(watchdog_reset_w) @@ -83,12 +67,12 @@ static ADDRESS_MAP_START( momoko_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0xdc00, 0xdc00) AM_WRITE(momoko_fg_scrolly_w) AM_RANGE(0xdc01, 0xdc01) AM_WRITE(momoko_fg_scrollx_w) AM_RANGE(0xdc02, 0xdc02) AM_WRITE(momoko_fg_select_w) - AM_RANGE(0xe000, 0xe3ff) AM_RAM AM_BASE_GENERIC(videoram) AM_SIZE_GENERIC(videoram) + AM_RANGE(0xe000, 0xe3ff) AM_RAM AM_BASE_SIZE_MEMBER(momoko_state, videoram, videoram_size) AM_RANGE(0xe800, 0xe800) AM_WRITE(momoko_text_scrolly_w) AM_RANGE(0xe801, 0xe801) AM_WRITE(momoko_text_mode_w) AM_RANGE(0xf000, 0xffff) AM_ROMBANK("bank1") - AM_RANGE(0xf000, 0xf001) AM_WRITE(momoko_bg_scrolly_w) AM_BASE(&momoko_bg_scrolly) - AM_RANGE(0xf002, 0xf003) AM_WRITE(momoko_bg_scrollx_w) AM_BASE(&momoko_bg_scrollx) + AM_RANGE(0xf000, 0xf001) AM_WRITE(momoko_bg_scrolly_w) AM_BASE_MEMBER(momoko_state, bg_scrolly) + AM_RANGE(0xf002, 0xf003) AM_WRITE(momoko_bg_scrollx_w) AM_BASE_MEMBER(momoko_state, bg_scrollx) AM_RANGE(0xf004, 0xf004) AM_WRITE(momoko_bg_read_bank_w) AM_RANGE(0xf006, 0xf006) AM_WRITE(momoko_bg_select_w) AM_RANGE(0xf007, 0xf007) AM_WRITE(momoko_bg_priority_w) @@ -241,8 +225,46 @@ static const ym2203_interface ym2203_config = NULL }; +static MACHINE_START( momoko ) +{ + momoko_state *state = (momoko_state *)machine->driver_data; + UINT8 *BG_MAP = memory_region(machine, "user1"); + + memory_configure_bank(machine, "bank1", 0, 32, &BG_MAP[0x0000], 0x1000); + + state_save_register_global(machine, state->fg_scrollx); + state_save_register_global(machine, state->fg_scrolly); + state_save_register_global(machine, state->fg_select); + state_save_register_global(machine, state->text_scrolly); + state_save_register_global(machine, state->text_mode); + state_save_register_global(machine, state->bg_select); + state_save_register_global(machine, state->bg_priority); + state_save_register_global(machine, state->bg_mask); + state_save_register_global(machine, state->fg_mask); + state_save_register_global(machine, state->flipscreen); +} + +static MACHINE_RESET( momoko ) +{ + momoko_state *state = (momoko_state *)machine->driver_data; + + state->fg_scrollx = 0; + state->fg_scrolly = 0; + state->fg_select = 0; + state->text_scrolly = 0; + state->text_mode = 0; + state->bg_select = 0; + state->bg_priority = 0; + state->bg_mask = 0; + state->fg_mask = 0; + state->flipscreen = 0; +} + static MACHINE_DRIVER_START( momoko ) + /* driver data */ + MDRV_DRIVER_DATA(momoko_state) + /* basic machine hardware */ MDRV_CPU_ADD("maincpu", Z80, 5000000) /* 5.0MHz */ MDRV_CPU_PROGRAM_MAP(momoko_map) @@ -251,6 +273,9 @@ static MACHINE_DRIVER_START( momoko ) MDRV_CPU_ADD("audiocpu", Z80, 2500000) /* 2.5MHz */ MDRV_CPU_PROGRAM_MAP(momoko_sound_map) + MDRV_MACHINE_START(momoko) + MDRV_MACHINE_RESET(momoko) + /* video hardware */ MDRV_SCREEN_ADD("screen", RASTER) MDRV_SCREEN_REFRESH_RATE(60) @@ -324,4 +349,4 @@ ROM_START( momoko ) ROM_LOAD( "momoko-b.bin", 0x0100, 0x0020, CRC(427b0e5c) SHA1(aa2797b899571527cc96013fd3420b841954ee67) ) ROM_END -GAME( 1986, momoko, 0, momoko, momoko, 0, ROT0, "Jaleco", "Momoko 120%", 0 ) +GAME( 1986, momoko, 0, momoko, momoko, 0, ROT0, "Jaleco", "Momoko 120%", GAME_SUPPORTS_SAVE ) diff --git a/src/mame/includes/madmotor.h b/src/mame/includes/madmotor.h new file mode 100644 index 00000000000..2f873e7d972 --- /dev/null +++ b/src/mame/includes/madmotor.h @@ -0,0 +1,39 @@ +/************************************************************************* + + Mad Motor + +*************************************************************************/ + +typedef struct _madmotor_state madmotor_state; +struct _madmotor_state +{ + /* memory pointers */ + UINT16 * pf1_rowscroll; + UINT16 * pf1_data; + UINT16 * pf2_data; + UINT16 * pf3_data; + UINT16 * pf1_control; + UINT16 * pf2_control; + UINT16 * pf3_control; + UINT16 * spriteram; +// UINT16 * paletteram; // this currently uses generic palette handlers + size_t spriteram_size; + + /* video-related */ + tilemap_t *pf1_tilemap, *pf2_tilemap, *pf3_tilemap, *pf3a_tilemap; + int flipscreen; + + /* devices */ + running_device *maincpu; + running_device *audiocpu; +}; + + +/*----------- defined in video/madmotor.c -----------*/ + +WRITE16_HANDLER( madmotor_pf1_data_w ); +WRITE16_HANDLER( madmotor_pf2_data_w ); +WRITE16_HANDLER( madmotor_pf3_data_w ); + +VIDEO_START( madmotor ); +VIDEO_UPDATE( madmotor ); diff --git a/src/mame/includes/mikie.h b/src/mame/includes/mikie.h new file mode 100644 index 00000000000..31a44aaedbb --- /dev/null +++ b/src/mame/includes/mikie.h @@ -0,0 +1,38 @@ +/************************************************************************* + + Mikie + +*************************************************************************/ + +typedef struct _mikie_state mikie_state; +struct _mikie_state +{ + /* memory pointers */ + UINT8 * videoram; + UINT8 * colorram; + UINT8 * spriteram; + size_t spriteram_size; + + /* video-related */ + tilemap_t *bg_tilemap; + int palettebank; + + /* misc */ + int last_irq; + + /* devices */ + running_device *maincpu; + running_device *audiocpu; +}; + + +/*----------- defined in video/mikie.c -----------*/ + +WRITE8_HANDLER( mikie_videoram_w ); +WRITE8_HANDLER( mikie_colorram_w ); +WRITE8_HANDLER( mikie_palettebank_w ); +WRITE8_HANDLER( mikie_flipscreen_w ); + +PALETTE_INIT( mikie ); +VIDEO_START( mikie ); +VIDEO_UPDATE( mikie ); diff --git a/src/mame/includes/momoko.h b/src/mame/includes/momoko.h new file mode 100644 index 00000000000..be11a82b645 --- /dev/null +++ b/src/mame/includes/momoko.h @@ -0,0 +1,46 @@ +/************************************************************************* + + Momoko 120% + +*************************************************************************/ + +typedef struct _momoko_state momoko_state; +struct _momoko_state +{ + /* memory pointers */ + UINT8 * bg_scrollx; + UINT8 * bg_scrolly; + UINT8 * videoram; + UINT8 * spriteram; +// UINT8 * paletteram; // currently this uses generic palette handling + size_t spriteram_size; + size_t videoram_size; + + /* video-related */ + UINT8 fg_scrollx; + UINT8 fg_scrolly; + UINT8 fg_select; + UINT8 text_scrolly; + UINT8 text_mode; + UINT8 bg_select; + UINT8 bg_priority; + UINT8 bg_mask; + UINT8 fg_mask; + UINT8 flipscreen; +}; + + +/*----------- defined in video/momoko.c -----------*/ + +WRITE8_HANDLER( momoko_fg_scrollx_w ); +WRITE8_HANDLER( momoko_fg_scrolly_w ); +WRITE8_HANDLER( momoko_text_scrolly_w ); +WRITE8_HANDLER( momoko_text_mode_w ); +WRITE8_HANDLER( momoko_bg_scrollx_w ); +WRITE8_HANDLER( momoko_bg_scrolly_w ); +WRITE8_HANDLER( momoko_flipscreen_w ); +WRITE8_HANDLER( momoko_fg_select_w); +WRITE8_HANDLER( momoko_bg_select_w); +WRITE8_HANDLER( momoko_bg_priority_w); + +VIDEO_UPDATE( momoko ); diff --git a/src/mame/mame.mak b/src/mame/mame.mak index 4b5b094cddd..a692a2fa32f 100644 --- a/src/mame/mame.mak +++ b/src/mame/mame.mak @@ -1394,7 +1394,7 @@ $(MAMEOBJ)/thepit.a: \ $(DRIVERS)/timelimt.o $(VIDEO)/timelimt.o \ $(MAMEOBJ)/toaplan.a: \ - $(DRIVERS)/mjsister.o $(VIDEO)/mjsister.o \ + $(DRIVERS)/mjsister.o \ $(DRIVERS)/slapfght.o $(MACHINE)/slapfght.o $(VIDEO)/slapfght.o \ $(DRIVERS)/snowbros.o $(VIDEO)/kan_pand.o $(VIDEO)/kan_panb.o \ $(DRIVERS)/toaplan1.o $(MACHINE)/toaplan1.o $(VIDEO)/toaplan1.o \ @@ -1576,7 +1576,7 @@ $(MAMEOBJ)/misc.a: \ $(DRIVERS)/mirage.o \ $(DRIVERS)/mirax.o \ $(DRIVERS)/mirderby.o \ - $(DRIVERS)/mole.o $(VIDEO)/mole.o \ + $(DRIVERS)/mole.o \ $(DRIVERS)/mosaic.o $(VIDEO)/mosaic.o \ $(DRIVERS)/mrjong.o $(VIDEO)/mrjong.o \ $(DRIVERS)/multfish.o \ diff --git a/src/mame/video/madmotor.c b/src/mame/video/madmotor.c index 44a49fb9568..0860f65354a 100644 --- a/src/mame/video/madmotor.c +++ b/src/mame/video/madmotor.c @@ -7,18 +7,7 @@ ***************************************************************************/ #include "emu.h" - -UINT16 *madmotor_pf1_rowscroll; -UINT16 *madmotor_pf1_data,*madmotor_pf2_data,*madmotor_pf3_data; - -UINT16 *madmotor_pf1_control; -UINT16 *madmotor_pf2_control; -UINT16 *madmotor_pf3_control; - -static int flipscreen; -static tilemap_t *madmotor_pf1_tilemap,*madmotor_pf2_tilemap,*madmotor_pf3_tilemap,*madmotor_pf3a_tilemap; - - +#include "includes/madmotor.h" /* 512 by 512 playfield, 8 by 8 tiles */ @@ -30,11 +19,11 @@ static TILEMAP_MAPPER( pf1_scan ) static TILE_GET_INFO( get_pf1_tile_info ) { - int tile,color; + madmotor_state *state = (madmotor_state *)machine->driver_data; + int tile = state->pf1_data[tile_index]; + int color = tile >> 12; - tile=madmotor_pf1_data[tile_index]; - color=tile >> 12; - tile=tile&0xfff; + tile = tile & 0xfff; SET_TILE_INFO( 0, @@ -52,11 +41,11 @@ static TILEMAP_MAPPER( pf2_scan ) static TILE_GET_INFO( get_pf2_tile_info ) { - int tile,color; + madmotor_state *state = (madmotor_state *)machine->driver_data; + int tile = state->pf2_data[tile_index]; + int color = tile >> 12; - tile=madmotor_pf2_data[tile_index]; - color=tile >> 12; - tile=tile&0xfff; + tile = tile & 0xfff; SET_TILE_INFO( 1, @@ -74,11 +63,11 @@ static TILEMAP_MAPPER( pf3_scan ) static TILE_GET_INFO( get_pf3_tile_info ) { - int tile,color; + madmotor_state *state = (madmotor_state *)machine->driver_data; + int tile = state->pf3_data[tile_index]; + int color = tile >> 12; - tile=madmotor_pf3_data[tile_index]; - color=tile >> 12; - tile=tile&0xfff; + tile = tile & 0xfff; SET_TILE_INFO( 2, @@ -96,11 +85,11 @@ static TILEMAP_MAPPER( pf3a_scan ) static TILE_GET_INFO( get_pf3a_tile_info ) { - int tile,color; + madmotor_state *state = (madmotor_state *)machine->driver_data; + int tile = state->pf3_data[tile_index]; + int color = tile >> 12; - tile=madmotor_pf3_data[tile_index]; - color=tile >> 12; - tile=tile&0xfff; + tile = tile & 0xfff; SET_TILE_INFO( 2, @@ -113,58 +102,67 @@ static TILE_GET_INFO( get_pf3a_tile_info ) VIDEO_START( madmotor ) { - madmotor_pf1_tilemap = tilemap_create(machine, get_pf1_tile_info, pf1_scan, 8, 8, 64,64); - madmotor_pf2_tilemap = tilemap_create(machine, get_pf2_tile_info, pf2_scan, 16,16, 32,32); - madmotor_pf3_tilemap = tilemap_create(machine, get_pf3_tile_info, pf3_scan, 16,16, 32,64); - madmotor_pf3a_tilemap= tilemap_create(machine, get_pf3a_tile_info,pf3a_scan, 16,16,128,16); + madmotor_state *state = (madmotor_state *)machine->driver_data; - tilemap_set_transparent_pen(madmotor_pf1_tilemap,0); - tilemap_set_transparent_pen(madmotor_pf2_tilemap,0); - tilemap_set_scroll_rows(madmotor_pf1_tilemap,512); + state->pf1_tilemap = tilemap_create(machine, get_pf1_tile_info, pf1_scan, 8, 8, 64, 64); + state->pf2_tilemap = tilemap_create(machine, get_pf2_tile_info, pf2_scan, 16, 16, 32, 32); + state->pf3_tilemap = tilemap_create(machine, get_pf3_tile_info, pf3_scan, 16, 16, 32, 64); + state->pf3a_tilemap= tilemap_create(machine, get_pf3a_tile_info, pf3a_scan, 16, 16, 128, 16); + + tilemap_set_transparent_pen(state->pf1_tilemap, 0); + tilemap_set_transparent_pen(state->pf2_tilemap, 0); + tilemap_set_scroll_rows(state->pf1_tilemap, 512); } /******************************************************************************/ WRITE16_HANDLER( madmotor_pf1_data_w ) { - COMBINE_DATA(&madmotor_pf1_data[offset]); - tilemap_mark_tile_dirty(madmotor_pf1_tilemap,offset); + madmotor_state *state = (madmotor_state *)space->machine->driver_data; + + COMBINE_DATA(&state->pf1_data[offset]); + tilemap_mark_tile_dirty(state->pf1_tilemap, offset); } WRITE16_HANDLER( madmotor_pf2_data_w ) { - COMBINE_DATA(&madmotor_pf2_data[offset]); - tilemap_mark_tile_dirty(madmotor_pf2_tilemap,offset); + madmotor_state *state = (madmotor_state *)space->machine->driver_data; + + COMBINE_DATA(&state->pf2_data[offset]); + tilemap_mark_tile_dirty(state->pf2_tilemap, offset); } WRITE16_HANDLER( madmotor_pf3_data_w ) { - COMBINE_DATA(&madmotor_pf3_data[offset]); + madmotor_state *state = (madmotor_state *)space->machine->driver_data; + + COMBINE_DATA(&state->pf3_data[offset]); /* Mark the dirty position on the 512 x 1024 version */ - tilemap_mark_tile_dirty(madmotor_pf3_tilemap,offset); + tilemap_mark_tile_dirty(state->pf3_tilemap, offset); /* Mark the dirty position on the 2048 x 256 version */ - tilemap_mark_tile_dirty(madmotor_pf3a_tilemap,offset); + tilemap_mark_tile_dirty(state->pf3a_tilemap, offset); } /******************************************************************************/ -static void draw_sprites(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int pri_mask,int pri_val) +static void draw_sprites( running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int pri_mask, int pri_val ) { - UINT16 *spriteram16 = machine->generic.spriteram.u16; + madmotor_state *state = (madmotor_state *)machine->driver_data; + UINT16 *spriteram = state->spriteram; int offs; offs = 0; - while (offs < machine->generic.spriteram_size/2) + while (offs < state->spriteram_size / 2) { - int sx,sy,code,color,w,h,flipx,flipy,incy,flash,mult,x,y; + int sx, sy, code, color, w, h, flipx, flipy, incy, flash, mult, x, y; - sy = spriteram16[offs]; - sx = spriteram16[offs+2]; + sy = spriteram[offs]; + sx = spriteram[offs + 2]; color = sx >> 12; - flash=sx&0x800; + flash = sx & 0x800; flipx = sy & 0x2000; flipy = sy & 0x4000; @@ -172,7 +170,7 @@ static void draw_sprites(running_machine *machine, bitmap_t *bitmap,const rectan w = (1 << ((sy & 0x0600) >> 9)); /* 1x, 2x, 4x, 8x width */ /* multi width used only on the title screen? */ - code = spriteram16[offs+1] & 0x1fff; + code = spriteram[offs + 1] & 0x1fff; sx = sx & 0x01ff; sy = sy & 0x01ff; @@ -190,18 +188,20 @@ static void draw_sprites(running_machine *machine, bitmap_t *bitmap,const rectan incy = 1; } - if (flipscreen) { - sy=240-sy; - sx=240-sx; - if (flipx) flipx=0; else flipx=1; - if (flipy) flipy=0; else flipy=1; - mult=16; - } - else mult=-16; - - for (x = 0;x < w;x++) + if (state->flipscreen) { - for (y = 0;y < h;y++) + sy = 240 - sy; + sx = 240 - sx; + if (flipx) flipx = 0; else flipx = 1; + if (flipy) flipy = 0; else flipy = 1; + mult = 16; + } + else + mult = -16; + + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) { if ((color & pri_mask) == pri_val && (!flash || (video_screen_get_frame_number(machine->primary_screen) & 1))) @@ -213,8 +213,7 @@ static void draw_sprites(running_machine *machine, bitmap_t *bitmap,const rectan } offs += 4; - if (offs >= machine->generic.spriteram_size/2 || - spriteram16[offs] & 0x8000) // seems the expected behaviour on the title screen + if (offs >= state->spriteram_size / 2 || spriteram[offs] & 0x8000) // seems the expected behaviour on the title screen break; } } @@ -225,33 +224,37 @@ static void draw_sprites(running_machine *machine, bitmap_t *bitmap,const rectan VIDEO_UPDATE( madmotor ) { + madmotor_state *state = (madmotor_state *)screen->machine->driver_data; int offs; /* Update flipscreen */ - if (madmotor_pf1_control[0]&0x80) - flipscreen=1; + if (state->pf1_control[0] & 0x80) + state->flipscreen = 1; else - flipscreen=0; - tilemap_set_flip_all(screen->machine,flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0); + state->flipscreen = 0; + + tilemap_set_flip_all(screen->machine, state->flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0); /* Setup scroll registers */ - for (offs = 0;offs < 512;offs++) - tilemap_set_scrollx( madmotor_pf1_tilemap,offs, madmotor_pf1_control[0x08] + madmotor_pf1_rowscroll[0x200+offs] ); - tilemap_set_scrolly( madmotor_pf1_tilemap,0, madmotor_pf1_control[0x09] ); - tilemap_set_scrollx( madmotor_pf2_tilemap,0, madmotor_pf2_control[0x08] ); - tilemap_set_scrolly( madmotor_pf2_tilemap,0, madmotor_pf2_control[0x09] ); - tilemap_set_scrollx( madmotor_pf3_tilemap,0, madmotor_pf3_control[0x08] ); - tilemap_set_scrolly( madmotor_pf3_tilemap,0, madmotor_pf3_control[0x09] ); - tilemap_set_scrollx( madmotor_pf3a_tilemap,0, madmotor_pf3_control[0x08] ); - tilemap_set_scrolly( madmotor_pf3a_tilemap,0, madmotor_pf3_control[0x09] ); + for (offs = 0; offs < 512; offs++) + tilemap_set_scrollx(state->pf1_tilemap, offs, state->pf1_control[0x08] + state->pf1_rowscroll[0x200 + offs]); + + tilemap_set_scrolly(state->pf1_tilemap, 0, state->pf1_control[0x09]); + tilemap_set_scrollx(state->pf2_tilemap, 0, state->pf2_control[0x08]); + tilemap_set_scrolly(state->pf2_tilemap, 0, state->pf2_control[0x09]); + tilemap_set_scrollx(state->pf3_tilemap, 0, state->pf3_control[0x08]); + tilemap_set_scrolly(state->pf3_tilemap, 0, state->pf3_control[0x09]); + tilemap_set_scrollx(state->pf3a_tilemap, 0, state->pf3_control[0x08]); + tilemap_set_scrolly(state->pf3a_tilemap, 0, state->pf3_control[0x09]); /* Draw playfields & sprites */ - if (madmotor_pf3_control[0x03]==2) - tilemap_draw(bitmap,cliprect,madmotor_pf3_tilemap,0,0); + if (state->pf3_control[0x03] == 2) + tilemap_draw(bitmap, cliprect, state->pf3_tilemap, 0, 0); else - tilemap_draw(bitmap,cliprect,madmotor_pf3a_tilemap,0,0); - tilemap_draw(bitmap,cliprect,madmotor_pf2_tilemap,0,0); - draw_sprites(screen->machine,bitmap,cliprect,0x00,0x00); - tilemap_draw(bitmap,cliprect,madmotor_pf1_tilemap,0,0); + tilemap_draw(bitmap, cliprect, state->pf3a_tilemap, 0, 0); + + tilemap_draw(bitmap, cliprect, state->pf2_tilemap, 0, 0); + draw_sprites(screen->machine, bitmap, cliprect, 0x00, 0x00); + tilemap_draw(bitmap, cliprect, state->pf1_tilemap, 0, 0); return 0; } diff --git a/src/mame/video/mikie.c b/src/mame/video/mikie.c index 492bcf30778..9fc71a1b585 100644 --- a/src/mame/video/mikie.c +++ b/src/mame/video/mikie.c @@ -8,12 +8,7 @@ #include "emu.h" #include "video/resnet.h" - -static int palettebank; - -UINT8 *mikie_videoram; -UINT8 *mikie_colorram; -static tilemap_t *bg_tilemap; +#include "includes/mikie.h" /*************************************************************************** @@ -30,6 +25,7 @@ static tilemap_t *bg_tilemap; bit 0 -- 2.2kohm resistor -- RED/GREEN/BLUE ***************************************************************************/ + PALETTE_INIT( mikie ) { static const int resistances[4] = { 2200, 1000, 470, 220 }; @@ -78,8 +74,7 @@ PALETTE_INIT( mikie ) /* color_prom now points to the beginning of the lookup table,*/ color_prom += 0x300; - /* characters use colors 0x10-0x1f of each 0x20 color bank, - while sprites use colors 0-0x0f */ + /* characters use colors 0x10-0x1f of each 0x20 color bank, while sprites use colors 0-0x0f */ for (i = 0; i < 0x200; i++) { int j; @@ -94,21 +89,27 @@ PALETTE_INIT( mikie ) WRITE8_HANDLER( mikie_videoram_w ) { - mikie_videoram[offset] = data; - tilemap_mark_tile_dirty(bg_tilemap, offset); + mikie_state *state = (mikie_state *)space->machine->driver_data; + + state->videoram[offset] = data; + tilemap_mark_tile_dirty(state->bg_tilemap, offset); } WRITE8_HANDLER( mikie_colorram_w ) { - mikie_colorram[offset] = data; - tilemap_mark_tile_dirty(bg_tilemap, offset); + mikie_state *state = (mikie_state *)space->machine->driver_data; + + state->colorram[offset] = data; + tilemap_mark_tile_dirty(state->bg_tilemap, offset); } WRITE8_HANDLER( mikie_palettebank_w ) { - if (palettebank != (data & 0x07)) + mikie_state *state = (mikie_state *)space->machine->driver_data; + + if (state->palettebank != (data & 0x07)) { - palettebank = data & 0x07; + state->palettebank = data & 0x07; tilemap_mark_all_tiles_dirty_all(space->machine); } } @@ -124,13 +125,15 @@ WRITE8_HANDLER( mikie_flipscreen_w ) static TILE_GET_INFO( get_bg_tile_info ) { - int code = mikie_videoram[tile_index] + ((mikie_colorram[tile_index] & 0x20) << 3); - int color = (mikie_colorram[tile_index] & 0x0f) + 16 * palettebank; - int flags = ((mikie_colorram[tile_index] & 0x40) ? TILE_FLIPX : 0) | ((mikie_colorram[tile_index] & 0x80) ? TILE_FLIPY : 0); - if (mikie_colorram[tile_index] & 0x10) + mikie_state *state = (mikie_state *)machine->driver_data; + int code = state->videoram[tile_index] + ((state->colorram[tile_index] & 0x20) << 3); + int color = (state->colorram[tile_index] & 0x0f) + 16 * state->palettebank; + int flags = ((state->colorram[tile_index] & 0x40) ? TILE_FLIPX : 0) | ((state->colorram[tile_index] & 0x80) ? TILE_FLIPY : 0); + if (state->colorram[tile_index] & 0x10) tileinfo->category = 1; else tileinfo->category = 0; + SET_TILE_INFO(0, code, color, flags); @@ -138,20 +141,21 @@ static TILE_GET_INFO( get_bg_tile_info ) VIDEO_START( mikie ) { - bg_tilemap = tilemap_create(machine, get_bg_tile_info, tilemap_scan_rows, - 8, 8, 32, 32); + mikie_state *state = (mikie_state *)machine->driver_data; + state->bg_tilemap = tilemap_create(machine, get_bg_tile_info, tilemap_scan_rows, 8, 8, 32, 32); } static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect) { - UINT8 *spriteram = machine->generic.spriteram.u8; + mikie_state *state = (mikie_state *)machine->driver_data; + UINT8 *spriteram = state->spriteram; int offs; - for (offs = 0;offs < machine->generic.spriteram_size;offs += 4) + for (offs = 0; offs < state->spriteram_size; offs += 4) { - int gfxbank = (spriteram[offs+2] & 0x40) ? 2 : 1; + int gfxbank = (spriteram[offs + 2] & 0x40) ? 2 : 1; int code = (spriteram[offs + 2] & 0x3f) + ((spriteram[offs + 2] & 0x80) >> 1) + ((spriteram[offs] & 0x40) << 1); - int color = (spriteram[offs] & 0x0f) + 16 * palettebank; + int color = (spriteram[offs] & 0x0f) + 16 * state->palettebank; int sx = spriteram[offs + 3]; int sy = 244 - spriteram[offs + 1]; int flipx = ~spriteram[offs] & 0x10; @@ -173,8 +177,9 @@ static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const recta VIDEO_UPDATE( mikie ) { - tilemap_draw(bitmap, cliprect, bg_tilemap, TILEMAP_DRAW_CATEGORY(0), 0); + mikie_state *state = (mikie_state *)screen->machine->driver_data; + tilemap_draw(bitmap, cliprect, state->bg_tilemap, TILEMAP_DRAW_CATEGORY(0), 0); draw_sprites(screen->machine, bitmap, cliprect); - tilemap_draw(bitmap, cliprect, bg_tilemap, TILEMAP_DRAW_CATEGORY(1), 0); + tilemap_draw(bitmap, cliprect, state->bg_tilemap, TILEMAP_DRAW_CATEGORY(1), 0); return 0; } diff --git a/src/mame/video/mjsister.c b/src/mame/video/mjsister.c deleted file mode 100644 index 9af9206c2c0..00000000000 --- a/src/mame/video/mjsister.c +++ /dev/null @@ -1,109 +0,0 @@ -/***************************************************************************** - -Mahjong Sisters (c) 1986 Toa Plan - -Video hardware - driver by Uki - -*****************************************************************************/ - -#include "emu.h" - -int mjsister_screen_redraw; -int mjsister_flip_screen; -int mjsister_video_enable; - -int mjsister_vrambank; -int mjsister_colorbank; - -static bitmap_t *mjsister_tmpbitmap0, *mjsister_tmpbitmap1; -static UINT8 *mjsister_videoram0, *mjsister_videoram1; - -/****************************************************************************/ - -VIDEO_START( mjsister ) -{ - mjsister_tmpbitmap0 = auto_bitmap_alloc(machine,256,256,video_screen_get_format(machine->primary_screen)); - mjsister_tmpbitmap1 = auto_bitmap_alloc(machine,256,256,video_screen_get_format(machine->primary_screen)); - mjsister_videoram0 = auto_alloc_array(machine, UINT8, 0x8000); - mjsister_videoram1 = auto_alloc_array(machine, UINT8, 0x8000); -} - -static void mjsister_plot0(int offset,UINT8 data) -{ - int x,y,c1,c2; - - x = offset & 0x7f; - y = offset / 0x80; - - c1 = (data & 0x0f) + mjsister_colorbank * 0x20; - c2 = ((data & 0xf0) >> 4) + mjsister_colorbank * 0x20; - - *BITMAP_ADDR16(mjsister_tmpbitmap0, y, x*2+0) = c1; - *BITMAP_ADDR16(mjsister_tmpbitmap0, y, x*2+1) = c2; -} - -static void mjsister_plot1(int offset,UINT8 data) -{ - int x,y,c1,c2; - - x = offset & 0x7f; - y = offset / 0x80; - - c1 = data & 0x0f; - c2 = (data & 0xf0) >> 4; - - if (c1) - c1 += mjsister_colorbank * 0x20 + 0x10; - if (c2) - c2 += mjsister_colorbank * 0x20 + 0x10; - - *BITMAP_ADDR16(mjsister_tmpbitmap1, y, x*2+0) = c1; - *BITMAP_ADDR16(mjsister_tmpbitmap1, y, x*2+1) = c2; -} - -WRITE8_HANDLER( mjsister_videoram_w ) -{ - if (mjsister_vrambank) - { - mjsister_videoram1[offset] = data; - mjsister_plot1(offset,data); - } - else - { - mjsister_videoram0[offset] = data; - mjsister_plot0(offset,data); - } -} - -VIDEO_UPDATE( mjsister ) -{ - int f = mjsister_flip_screen; - int i,j; - - if (mjsister_screen_redraw) - { - int offs; - - for (offs=0; offs<0x8000; offs++) - { - mjsister_plot0(offs,mjsister_videoram0[offs]); - mjsister_plot1(offs,mjsister_videoram1[offs]); - } - - mjsister_screen_redraw = 0; - } - - if (mjsister_video_enable) - { - for (i=0; i<256; i++) - for (j=0; j<4; j++) - *BITMAP_ADDR16(bitmap, i, 256+j) = mjsister_colorbank * 0x20; - - copybitmap (bitmap,mjsister_tmpbitmap0,f,f,0,0,cliprect); - copybitmap_trans(bitmap,mjsister_tmpbitmap1,f,f,2,0,cliprect,0); - } - else - bitmap_fill(bitmap, cliprect, get_black_pen(screen->machine)); - return 0; -} diff --git a/src/mame/video/mole.c b/src/mame/video/mole.c deleted file mode 100644 index 5da7d7e497e..00000000000 --- a/src/mame/video/mole.c +++ /dev/null @@ -1,58 +0,0 @@ -/*************************************************************************** - video/mole.c - Functions to emulate the video hardware of Mole Attack!. - Mole Attack's Video hardware is essentially two banks of 512 characters. - The program uses a single byte to indicate which character goes in each location, - and uses a control location (0x8400) to select the character sets -***************************************************************************/ - -#include "emu.h" - -static int tile_bank; -static UINT16 *tileram; -static tilemap_t *bg_tilemap; - -PALETTE_INIT( mole ) -{ - int i; - - for (i = 0; i < 8; i++) { - palette_set_color_rgb(machine, i, pal1bit(i >> 0), pal1bit(i >> 2), pal1bit(i >> 1)); - } -} - -static TILE_GET_INFO( get_bg_tile_info ) -{ - UINT16 code = tileram[tile_index]; - SET_TILE_INFO((code & 0x200) ? 1 : 0, code & 0x1ff, 0, 0); -} - -VIDEO_START( mole ) -{ - tileram = auto_alloc_array(machine, UINT16, 0x400); - - bg_tilemap = tilemap_create(machine, get_bg_tile_info, tilemap_scan_rows, 8, 8, 40, 25); -} - -WRITE8_HANDLER( mole_videoram_w ) -{ - tileram[offset] = data | (tile_bank << 8); - tilemap_mark_tile_dirty(bg_tilemap, offset); -} - -WRITE8_HANDLER( mole_tilebank_w ) -{ - tile_bank = data; - tilemap_mark_all_tiles_dirty(bg_tilemap); -} - -WRITE8_HANDLER( mole_flipscreen_w ) -{ - flip_screen_set(space->machine, data & 0x01); -} - -VIDEO_UPDATE( mole ) -{ - tilemap_draw(bitmap, cliprect, bg_tilemap, 0, 0); - return 0; -} diff --git a/src/mame/video/momoko.c b/src/mame/video/momoko.c index 04dbd0be4fc..3bf76651c7b 100644 --- a/src/mame/video/momoko.c +++ b/src/mame/video/momoko.c @@ -1,97 +1,107 @@ /******************************************************************************* -Momoko 120% (c) 1986 Jaleco + Momoko 120% (c) 1986 Jaleco -Video hardware driver by Uki + Video hardware driver by Uki 02/Mar/2001 - *******************************************************************************/ #include "emu.h" +#include "includes/momoko.h" -UINT8 *momoko_bg_scrollx; -UINT8 *momoko_bg_scrolly; -static UINT8 momoko_fg_scrollx; -static UINT8 momoko_fg_scrolly; -static UINT8 momoko_fg_select; -static UINT8 momoko_text_scrolly; -static UINT8 momoko_text_mode; -static UINT8 momoko_bg_select; -static UINT8 momoko_bg_priority; -static UINT8 momoko_bg_mask; -static UINT8 momoko_fg_mask; -static UINT8 momoko_flipscreen; - -/****************************************************************************/ WRITE8_HANDLER ( momoko_fg_scrollx_w ) { - momoko_fg_scrollx = data; + momoko_state *state = (momoko_state *)space->machine->driver_data; + state->fg_scrollx = data; } + WRITE8_HANDLER ( momoko_fg_scrolly_w ) { - momoko_fg_scrolly = data; + momoko_state *state = (momoko_state *)space->machine->driver_data; + state->fg_scrolly = data; } + WRITE8_HANDLER ( momoko_fg_select_w ) { - momoko_fg_select = data & 0x0f; - momoko_fg_mask = data & 0x10; + momoko_state *state = (momoko_state *)space->machine->driver_data; + state->fg_select = data & 0x0f; + state->fg_mask = data & 0x10; } + WRITE8_HANDLER ( momoko_text_scrolly_w ) { - momoko_text_scrolly = data; + momoko_state *state = (momoko_state *)space->machine->driver_data; + state->text_scrolly = data; } + WRITE8_HANDLER ( momoko_text_mode_w ) { - momoko_text_mode = data; + momoko_state *state = (momoko_state *)space->machine->driver_data; + state->text_mode = data; } + WRITE8_HANDLER ( momoko_bg_scrollx_w ) { - momoko_bg_scrollx[ offset ] = data; + momoko_state *state = (momoko_state *)space->machine->driver_data; + state->bg_scrollx[offset] = data; } + WRITE8_HANDLER ( momoko_bg_scrolly_w ) { - momoko_bg_scrolly[ offset ] = data; + momoko_state *state = (momoko_state *)space->machine->driver_data; + state->bg_scrolly[offset] = data; } + WRITE8_HANDLER( momoko_bg_select_w ) { - momoko_bg_select = data & 0x0f; - momoko_bg_mask = data & 0x10; + momoko_state *state = (momoko_state *)space->machine->driver_data; + state->bg_select = data & 0x0f; + state->bg_mask = data & 0x10; } + WRITE8_HANDLER( momoko_bg_priority_w ) { - momoko_bg_priority = data & 0x01; + momoko_state *state = (momoko_state *)space->machine->driver_data; + state->bg_priority = data & 0x01; } + WRITE8_HANDLER( momoko_flipscreen_w ) { - momoko_flipscreen = data & 0x01; + momoko_state *state = (momoko_state *)space->machine->driver_data; + state->flipscreen = data & 0x01; } + /****************************************************************************/ -static void momoko_draw_bg_pri(running_machine *machine, bitmap_t *bitmap, int chr, int col, int flipx, int flipy, int x,int y, int pri) +static void momoko_draw_bg_pri( running_machine *machine, bitmap_t *bitmap, int chr, int col, int flipx, int flipy, int x, int y, int pri ) { - int xx,sx,sy,px,py,dot; + int xx, sx, sy, px, py, dot; UINT32 gfxadr; UINT8 d0, d1; - UINT8 *BG_GFX = memory_region( machine, "gfx2" ); - for (sy=0; sy<8; sy++) + UINT8 *BG_GFX = memory_region(machine, "gfx2"); + + for (sy = 0; sy < 8; sy++) { - gfxadr = chr*16 + sy*2; - for (xx=0; xx<2; xx++) + gfxadr = chr * 16 + sy * 2; + for (xx = 0; xx < 2; xx++) { - d0 = BG_GFX[gfxadr + xx*4096]; - d1 = BG_GFX[gfxadr + xx*4096+1]; - for (sx=0; sx<4; sx++) + d0 = BG_GFX[gfxadr + xx * 4096]; + d1 = BG_GFX[gfxadr + xx * 4096 + 1]; + + for (sx = 0; sx < 4; sx++) { dot = (d0 & 0x08) | ((d0 & 0x80) >>5) | ((d1 & 0x08) >>2) | ((d1 & 0x80) >>7); - if (flipx==0) px=sx+xx*4 + x; - else px=7-sx-xx*4 + x; - if (flipy==0) py=sy + y; - else py=7-sy + y; + if (flipx == 0) px = sx + xx * 4 + x; + else px = 7 - sx - xx * 4 + x; + if (flipy == 0) py = sy + y; + else py = 7 - sy + y; + + if (dot >= pri) + *BITMAP_ADDR16(bitmap, py, px) = col * 16 + dot + 256; - if (dot>=pri) - *BITMAP_ADDR16(bitmap, py, px) = col*16+dot+256; d0 = d0 << 1; d1 = d1 << 1; } @@ -103,44 +113,44 @@ static void momoko_draw_bg_pri(running_machine *machine, bitmap_t *bitmap, int c VIDEO_UPDATE( momoko ) { + momoko_state *state = (momoko_state *)screen->machine->driver_data; int x, y, dx, dy, rx, ry, radr, chr, sy, fx, fy, px, py, offs, col, pri, flip ; - UINT8 *spriteram = screen->machine->generic.spriteram.u8; + UINT8 *spriteram = state->spriteram; - UINT8 *BG_MAP = memory_region( screen->machine, "user1" ); - UINT8 *BG_COL_MAP = memory_region( screen->machine, "user2" ); - UINT8 *FG_MAP = memory_region( screen->machine, "user3" ); - UINT8 *TEXT_COLOR = memory_region( screen->machine, "proms" ); + UINT8 *BG_MAP = memory_region(screen->machine, "user1"); + UINT8 *BG_COL_MAP = memory_region(screen->machine, "user2"); + UINT8 *FG_MAP = memory_region(screen->machine, "user3"); + UINT8 *TEXT_COLOR = memory_region(screen->machine, "proms"); - flip = momoko_flipscreen ^ (input_port_read(screen->machine, "FAKE") & 0x01); + flip = state->flipscreen ^ (input_port_read(screen->machine, "FAKE") & 0x01); -/* draw BG layer */ + /* draw BG layer */ + dx = (7 - state->bg_scrollx[0]) & 7; + dy = (7 - state->bg_scrolly[0]) & 7; + rx = (state->bg_scrollx[0] + state->bg_scrollx[1] * 256) >> 3; + ry = (state->bg_scrolly[0] + state->bg_scrolly[1] * 256) >> 3; - dx = ( 7 - momoko_bg_scrollx[0] ) & 7 ; - dy = ( 7 - momoko_bg_scrolly[0] ) & 7 ; - rx = (momoko_bg_scrollx[0] + momoko_bg_scrollx[1]*256) >> 3 ; - ry = (momoko_bg_scrolly[0] + momoko_bg_scrolly[1]*256) >> 3 ; - - if (momoko_bg_mask == 0) + if (state->bg_mask == 0) { - for (y=0; y<29; y++) + for (y = 0; y < 29; y++) { - for (x=0; x<32; x++) + for (x = 0; x < 32; x++) { - radr = ( (ry + y +2 ) & 0x3ff ) * 128 + ( (rx + x) & 0x7f ) ; - chr = BG_MAP[ radr ] ; - col = BG_COL_MAP[ chr+momoko_bg_select*512+momoko_bg_priority*256] & 0x0f; - chr = chr + momoko_bg_select * 512; + radr = ((ry + y + 2) & 0x3ff) * 128 + ((rx + x) & 0x7f); + chr = BG_MAP[radr]; + col = BG_COL_MAP[chr + state->bg_select * 512 + state->bg_priority * 256] & 0x0f; + chr = chr + state->bg_select * 512; - if (flip==0) + if (flip == 0) { - px = 8*x+dx-6; - py = 8*y+dy+9; + px = 8 * x + dx - 6; + py = 8 * y + dy + 9; } else { - px = 248-(8*x+dx-8); - py = 248-(8*y+dy+9); + px = 248 - (8 * x + dx - 8); + py = 248 - (8 * y + dy + 9); } drawgfx_opaque(bitmap,cliprect,screen->machine->gfx[1], @@ -155,26 +165,26 @@ VIDEO_UPDATE( momoko ) bitmap_fill(bitmap, cliprect, 256); -/* draw sprites (momoko) */ - - for (offs=0; offs<9*4; offs +=4) + /* draw sprites (momoko) */ + for (offs = 0; offs < 9 * 4; offs +=4) { - chr = spriteram[offs+1] | ((spriteram[offs+2]&0x60)<<3); + chr = spriteram[offs + 1] | ((spriteram[offs + 2] & 0x60) << 3); chr = ((chr & 0x380) << 1) | (chr & 0x7f); - col = spriteram[offs+2] & 0x07; - fx = ((spriteram[offs+2] & 0x10) >> 4) ^ flip; - fy = ((spriteram[offs+2] & 0x08) >> 3) ^ flip; /* ??? */ - x = spriteram[offs+3]; - y = spriteram[offs+0]; - if (flip==0) + col = spriteram[offs + 2] & 0x07; + fx = ((spriteram[offs + 2] & 0x10) >> 4) ^ flip; + fy = ((spriteram[offs + 2] & 0x08) >> 3) ^ flip; /* ??? */ + x = spriteram[offs + 3]; + y = spriteram[offs + 0]; + + if (flip == 0) { px = x; - py = 239-y; + py = 239 - y; } else { - px = 248-x; - py = y+1; + px = 248 - x; + py = y + 1; } drawgfx_transpen(bitmap,cliprect,screen->machine->gfx[3], @@ -185,60 +195,59 @@ VIDEO_UPDATE( momoko ) } -/* draw BG layer */ - - if (momoko_bg_mask ==0) + /* draw BG layer */ + if (state->bg_mask ==0) { - for (y=0; y<29; y++) + for (y = 0; y < 29; y++) { - for (x=0; x<32; x++) + for (x = 0; x < 32; x++) { - radr = ( (ry + y +2 ) & 0x3ff ) * 128 + ( (rx + x) & 0x7f ) ; - chr = BG_MAP[ radr ] ; - col = BG_COL_MAP[ chr+momoko_bg_select*512+momoko_bg_priority*256 ]; + radr = ((ry + y + 2) & 0x3ff) * 128 + ((rx + x) & 0x7f) ; + chr = BG_MAP[radr] ; + col = BG_COL_MAP[chr + state->bg_select * 512 + state->bg_priority * 256]; pri = (col & 0x10) >> 1; - if (flip==0) + if (flip == 0) { - px = 8*x+dx-6; - py = 8*y+dy+9; - } + px = 8 * x + dx - 6; + py = 8 * y + dy + 9; + } else { - px = 248-(8*x+dx-8); - py = 248-(8*y+dy+9); + px = 248 - (8 * x + dx - 8); + py = 248 - (8 * y + dy + 9); } if (pri != 0) { col = col & 0x0f; - chr = chr + momoko_bg_select * 512; - momoko_draw_bg_pri(screen->machine,bitmap,chr,col,flip,flip,px,py,pri); + chr = chr + state->bg_select * 512; + momoko_draw_bg_pri(screen->machine, bitmap, chr, col, flip, flip, px, py, pri); } } } } -/* draw sprites (others) */ - - for (offs=9*4; offsmachine->generic.spriteram_size; offs +=4) + /* draw sprites (others) */ + for (offs = 9 * 4; offs < state->spriteram_size; offs += 4) { - chr = spriteram[offs+1] | ((spriteram[offs+2]&0x60)<<3); + chr = spriteram[offs + 1] | ((spriteram[offs + 2] & 0x60) << 3); chr = ((chr & 0x380) << 1) | (chr & 0x7f); - col = spriteram[offs+2] & 0x07; - fx = ((spriteram[offs+2] & 0x10) >> 4) ^ flip; - fy = ((spriteram[offs+2] & 0x08) >> 3) ^ flip; /* ??? */ - x = spriteram[offs+3]; - y = spriteram[offs+0]; - if (flip==0) + col = spriteram[offs + 2] & 0x07; + fx = ((spriteram[offs + 2] & 0x10) >> 4) ^ flip; + fy = ((spriteram[offs + 2] & 0x08) >> 3) ^ flip; /* ??? */ + x = spriteram[offs + 3]; + y = spriteram[offs + 0]; + + if (flip == 0) { px = x; - py = 239-y; + py = 239 - y; } else { - px = 248-x; - py = y+1; + px = 248 - x; + py = y + 1; } drawgfx_transpen(bitmap,cliprect,screen->machine->gfx[3], chr, @@ -248,34 +257,33 @@ VIDEO_UPDATE( momoko ) } -/* draw text layer */ - - for (y=16; y<240; y++) + /* draw text layer */ + for (y = 16; y < 240; y++) { - for (x=0; x<32; x++) + for (x = 0; x < 32; x++) { sy = y; - if (momoko_text_mode == 0) - col = TEXT_COLOR[ (sy >> 3) + 0x100 ] & 0x0f; + if (state->text_mode == 0) + col = TEXT_COLOR[(sy >> 3) + 0x100] & 0x0f; else { - if (TEXT_COLOR[ y ] < 0x08) - sy += momoko_text_scrolly; - col = (TEXT_COLOR[ y ] & 0x07) + 0x10; + if (TEXT_COLOR[y] < 0x08) + sy += state->text_scrolly; + col = (TEXT_COLOR[y] & 0x07) + 0x10; } - dy=sy & 7; - if (flip==0) + dy = sy & 7; + if (flip == 0) { - px = x*8; + px = x * 8; py = y; } else { - px = 248-x*8; - py = 255-y; + px = 248 - x * 8; + py = 255 - y; } drawgfx_transpen(bitmap,cliprect,screen->machine->gfx[0], - screen->machine->generic.videoram.u8[(sy>>3)*32+x]*8+dy, + state->videoram[(sy >> 3) * 32 + x] * 8 + dy, col, flip,0, px,py,0); @@ -283,30 +291,29 @@ VIDEO_UPDATE( momoko ) } -/* draw FG layer */ - - if (momoko_fg_mask==0) + /* draw FG layer */ + if (state->fg_mask == 0) { - dx = ( 7 - momoko_fg_scrollx ) & 7 ; - dy = ( 7 - momoko_fg_scrolly ) & 7 ; - rx = momoko_fg_scrollx >> 3 ; - ry = momoko_fg_scrolly >> 3 ; + dx = (7 - state->fg_scrollx) & 7; + dy = (7 - state->fg_scrolly) & 7; + rx = state->fg_scrollx >> 3; + ry = state->fg_scrolly >> 3; - for (y=0; y<29; y++) + for (y = 0; y < 29; y++) { - for (x=0; x<32; x++) + for (x = 0; x < 32; x++) { - radr = ((ry + y +34) & 0x3f) *0x20 + ((rx + x) & 0x1f) + (momoko_fg_select & 3) *0x800; - chr = FG_MAP[ radr ] ; - if (flip==0) + radr = ((ry + y + 34) & 0x3f) * 0x20 + ((rx + x) & 0x1f) + (state->fg_select & 3) * 0x800; + chr = FG_MAP[radr] ; + if (flip == 0) { - px = 8*x+dx-6; - py = 8*y+dy+9; + px = 8 * x + dx - 6; + py = 8 * y + dy + 9; } else { - px = 248-(8*x+dx-8); - py = 248-(8*y+dy+9); + px = 248 - (8 * x + dx - 8); + py = 248 - (8 * y + dy + 9); } drawgfx_transpen(bitmap,cliprect,screen->machine->gfx[2], chr,