diff --git a/src/mame/drivers/88games.c b/src/mame/drivers/88games.c index ff679158b66..4919bbb4da9 100644 --- a/src/mame/drivers/88games.c +++ b/src/mame/drivers/88games.c @@ -14,7 +14,6 @@ #include "includes/88games.h" -static UINT8 *paletteram_1000; /************************************* @@ -137,7 +136,7 @@ static WRITE8_HANDLER( k052109_051960_w ) static ADDRESS_MAP_START( main_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x0000, 0x0fff) AM_RAM AM_BASE_MEMBER(_88games_state, banked_rom) /* banked ROM + palette RAM */ - AM_RANGE(0x1000, 0x1fff) AM_RAM_WRITE(paletteram_xBBBBBGGGGGRRRRR_be_w) AM_BASE(&paletteram_1000) /* banked ROM + palette RAM */ + AM_RANGE(0x1000, 0x1fff) AM_RAM_WRITE(paletteram_xBBBBBGGGGGRRRRR_be_w) AM_BASE_MEMBER(_88games_state, paletteram_1000) /* banked ROM + palette RAM */ AM_RANGE(0x2000, 0x2fff) AM_RAM AM_RANGE(0x3000, 0x37ff) AM_RAM AM_SHARE("nvram") AM_RANGE(0x3800, 0x3fff) AM_READWRITE(bankedram_r, bankedram_w) AM_BASE_MEMBER(_88games_state, ram) @@ -287,10 +286,10 @@ static KONAMI_SETLINES_CALLBACK( k88games_banking ) memcpy(state->banked_rom, &RAM[offs], 0x1000); if (lines & 0x08) { - if (device->machine->generic.paletteram.u8 != paletteram_1000) + if (device->machine->generic.paletteram.u8 != state->paletteram_1000) { - memcpy(paletteram_1000, device->machine->generic.paletteram.u8, 0x1000); - device->machine->generic.paletteram.u8 = paletteram_1000; + memcpy(state->paletteram_1000, device->machine->generic.paletteram.u8, 0x1000); + device->machine->generic.paletteram.u8 = state->paletteram_1000; } } else @@ -300,7 +299,7 @@ static KONAMI_SETLINES_CALLBACK( k88games_banking ) memcpy(&RAM[0x20000], device->machine->generic.paletteram.u8, 0x1000); device->machine->generic.paletteram.u8 = &RAM[0x20000]; } - memcpy(paletteram_1000, &RAM[offs+0x1000], 0x1000); + memcpy(state->paletteram_1000, &RAM[offs+0x1000], 0x1000); } state->videobank = lines & 0x10; diff --git a/src/mame/drivers/asterix.c b/src/mame/drivers/asterix.c index 4a0347939d0..504b54265cb 100644 --- a/src/mame/drivers/asterix.c +++ b/src/mame/drivers/asterix.c @@ -134,15 +134,14 @@ static WRITE16_HANDLER( protection_w ) } #endif -static UINT16 prot[2]; - static WRITE16_HANDLER( protection_w ) { - COMBINE_DATA(prot + offset); + asterix_state *state = space->machine->driver_data(); + COMBINE_DATA(state->prot + offset); if (offset == 1) { - UINT32 cmd = (prot[0] << 16) | prot[1]; + UINT32 cmd = (state->prot[0] << 16) | state->prot[1]; switch (cmd >> 24) { case 0x64: diff --git a/src/mame/drivers/beezer.c b/src/mame/drivers/beezer.c index d18592ee813..d345b29787c 100644 --- a/src/mame/drivers/beezer.c +++ b/src/mame/drivers/beezer.c @@ -13,9 +13,6 @@ #include "sound/dac.h" #include "includes/beezer.h" -extern const via6522_interface b_via_0_interface; -extern const via6522_interface b_via_1_interface; - static ADDRESS_MAP_START( main_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x0000, 0xbfff) AM_RAM AM_BASE_MEMBER(beezer_state, videoram) AM_RANGE(0xc000, 0xcfff) AM_ROMBANK("bank1") diff --git a/src/mame/drivers/bingoc.c b/src/mame/drivers/bingoc.c index 26c34f68ef4..14e86e75a87 100644 --- a/src/mame/drivers/bingoc.c +++ b/src/mame/drivers/bingoc.c @@ -33,6 +33,17 @@ SOUND : YM2151 uPD7759C #include "sound/2151intf.h" #include "sound/upd7759.h" + +class bingoc_state : public driver_device +{ +public: + bingoc_state(running_machine &machine, const driver_device_config_base &config) + : driver_device(machine, config) { } + + UINT8 x; +}; + + #define SOUND_TEST 0 static VIDEO_START(bingoc) @@ -59,19 +70,19 @@ static READ16_HANDLER( bingoc_rand_r ) */ static READ8_HANDLER( sound_test_r ) { - static UINT8 x; + bingoc_state *state = space->machine->driver_data(); if(input_code_pressed_once(space->machine, KEYCODE_Z)) - x++; + state->x++; if(input_code_pressed_once(space->machine, KEYCODE_X)) - x--; + state->x--; if(input_code_pressed_once(space->machine, KEYCODE_A)) return 0xff; - popmessage("%02x",x); - return x; + popmessage("%02x",state->x); + return state->x; } #else static WRITE16_HANDLER( main_sound_latch_w ) @@ -125,7 +136,7 @@ static INPUT_PORTS_START( bingoc ) INPUT_PORTS_END -static MACHINE_CONFIG_START( bingoc, driver_device ) +static MACHINE_CONFIG_START( bingoc, bingoc_state ) MCFG_CPU_ADD("maincpu", M68000,8000000) /* ? MHz */ MCFG_CPU_PROGRAM_MAP(main_map) diff --git a/src/mame/drivers/coolridr.c b/src/mame/drivers/coolridr.c index d643498c23a..865482acd44 100644 --- a/src/mame/drivers/coolridr.c +++ b/src/mame/drivers/coolridr.c @@ -251,61 +251,86 @@ Note: This hardware appears to have been designed as a test-bed for a new RLE ba #include "deprecat.h" #include "sound/scsp.h" -static UINT32* sysh1_workram_h,*framebuffer_vram, *h1_unk, *h1_charram, *h1_vram; -static UINT32* sysh1_txt_blit; -static UINT32* txt_vram; -static bitmap_t* temp_bitmap_sprites; + +class coolridr_state : public driver_device +{ +public: + coolridr_state(running_machine &machine, const driver_device_config_base &config) + : driver_device(machine, config) { } + + UINT32* sysh1_workram_h; + UINT32* framebuffer_vram; + UINT32* h1_unk; + UINT32* h1_charram; + UINT32* h1_vram; + UINT32* sysh1_txt_blit; + UINT32* txt_vram; + bitmap_t* temp_bitmap_sprites; + UINT32 test_offs; + int color; + UINT8 vblank; + UINT16 cmd; + UINT16 param; + UINT32 dst_addr; + UINT32 txt_buff[0x10]; + UINT32 attr_buff[0x10]; + UINT8 txt_index; + UINT8 attr_index; +}; + + /* video */ static VIDEO_START(coolridr) { + coolridr_state *state = machine->driver_data(); int width = machine->primary_screen->width(); int height = machine->primary_screen->height(); - temp_bitmap_sprites = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_RGB32); + state->temp_bitmap_sprites = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_RGB32); + state->test_offs = 0x2000; } static VIDEO_UPDATE(coolridr) { + coolridr_state *state = screen->machine->driver_data(); /* planes seems to basically be at 0x8000 and 0x28000... */ const gfx_element *gfx = screen->machine->gfx[2]; UINT32 count; int y,x; - static int color; - static UINT32 test_offs = 0x2000; if(input_code_pressed(screen->machine,KEYCODE_Z)) - test_offs+=4; + state->test_offs+=4; if(input_code_pressed(screen->machine,KEYCODE_X)) - test_offs-=4; + state->test_offs-=4; if(input_code_pressed(screen->machine,KEYCODE_C)) - test_offs+=0x40; + state->test_offs+=0x40; if(input_code_pressed(screen->machine,KEYCODE_V)) - test_offs-=0x40; + state->test_offs-=0x40; if(input_code_pressed(screen->machine,KEYCODE_B)) - test_offs+=0x400; + state->test_offs+=0x400; if(input_code_pressed(screen->machine,KEYCODE_N)) - test_offs-=0x400; + state->test_offs-=0x400; if(input_code_pressed_once(screen->machine,KEYCODE_A)) - color++; + state->color++; if(input_code_pressed_once(screen->machine,KEYCODE_S)) - color--; + state->color--; - if(test_offs > 0x100000*4) - test_offs = 0; + if(state->test_offs > 0x100000*4) + state->test_offs = 0; - count = test_offs/4; + count = state->test_offs/4; - popmessage("%08x %04x",test_offs,color); + popmessage("%08x %04x",state->test_offs,state->color); for (y=0;y<64;y++) { @@ -313,18 +338,18 @@ static VIDEO_UPDATE(coolridr) { int tile; - tile = (h1_vram[count] & 0x0fff0000) >> 16; - drawgfx_opaque(bitmap,cliprect,gfx,tile,color,0,0,(x+0)*16,y*16); + tile = (state->h1_vram[count] & 0x0fff0000) >> 16; + drawgfx_opaque(bitmap,cliprect,gfx,tile,state->color,0,0,(x+0)*16,y*16); - tile = (h1_vram[count] & 0x00000fff) >> 0; - drawgfx_opaque(bitmap,cliprect,gfx,tile,color,0,0,(x+1)*16,y*16); + tile = (state->h1_vram[count] & 0x00000fff) >> 0; + drawgfx_opaque(bitmap,cliprect,gfx,tile,state->color,0,0,(x+1)*16,y*16); count++; } } - copybitmap_trans(bitmap, temp_bitmap_sprites, 0, 0, 0, 0, cliprect, 0); - bitmap_fill(temp_bitmap_sprites, cliprect, 0); + copybitmap_trans(bitmap, state->temp_bitmap_sprites, 0, 0, 0, 0, cliprect, 0); + bitmap_fill(state->temp_bitmap_sprites, cliprect, 0); return 0; @@ -335,27 +360,28 @@ static VIDEO_UPDATE(coolridr) /* unknown purpose */ static READ32_HANDLER(sysh1_unk_r) { + coolridr_state *state = space->machine->driver_data(); switch(offset) { case 0x08/4: { - static UINT8 vblank = 0; - vblank^=1; + state->vblank^=1; - return (h1_unk[offset] & 0xfdffffff) | (vblank<<25); + return (state->h1_unk[offset] & 0xfdffffff) | (state->vblank<<25); } case 0x14/4: - return h1_unk[offset]; + return state->h1_unk[offset]; //case 0x20/4: } - return 0xffffffff;//h1_unk[offset]; + return 0xffffffff;//state->h1_unk[offset]; } static WRITE32_HANDLER(sysh1_unk_w) { - COMBINE_DATA(&h1_unk[offset]); + coolridr_state *state = space->machine->driver_data(); + COMBINE_DATA(&state->h1_unk[offset]); } /* According to Guru, this is actually the same I/O chip of Sega Model 2 HW */ @@ -403,77 +429,74 @@ CMD = ac90 PARAM = 0001 DATA = 03f40170 /* this looks like an exotic I/O-based tilemap / sprite blitter, very unusual from Sega... */ static WRITE32_HANDLER( sysh1_txt_blit_w ) { - static UINT16 cmd,param; - static UINT32 dst_addr; - static UINT32 txt_buff[0x10],attr_buff[0x10]; - static UINT8 txt_index,attr_index; + coolridr_state *state = space->machine->driver_data(); - COMBINE_DATA(&sysh1_txt_blit[offset]); + COMBINE_DATA(&state->sysh1_txt_blit[offset]); switch(offset) { - case 0x10/4: //cmd + param? - cmd = (sysh1_txt_blit[offset] & 0xffff0000) >> 16; - param = (sysh1_txt_blit[offset] & 0x0000ffff) >> 0; - dst_addr = 0x3f40000; - txt_index = 0; - attr_index = 0; + case 0x10/4: //state->cmd + state->param? + state->cmd = (state->sysh1_txt_blit[offset] & 0xffff0000) >> 16; + state->param = (state->sysh1_txt_blit[offset] & 0x0000ffff) >> 0; + state->dst_addr = 0x3f40000; + state->txt_index = 0; + state->attr_index = 0; break; case 0x14/4: //data /* "THIS MACHINE IS STAND-ALONE." / disclaimer written with this CMD */ - if((cmd & 0xff) == 0xf4) + if((state->cmd & 0xff) == 0xf4) { - txt_buff[txt_index++] = data; + state->txt_buff[state->txt_index++] = data; - //printf("CMD = %04x PARAM = %04x | %c%c%c%c\n",cmd,param,(data >> 24) & 0xff,(data >> 16) & 0xff,(data >> 8) & 0xff,(data >> 0) & 0xff); + //printf("CMD = %04x PARAM = %04x | %c%c%c%c\n",state->cmd,state->param,(data >> 24) & 0xff,(data >> 16) & 0xff,(data >> 8) & 0xff,(data >> 0) & 0xff); } - else if((cmd & 0xff) == 0x90 || (cmd & 0xff) == 0x30) + else if((state->cmd & 0xff) == 0x90 || (state->cmd & 0xff) == 0x30) { - attr_buff[attr_index++] = data; + state->attr_buff[state->attr_index++] = data; - if(attr_index == 0xa) + if(state->attr_index == 0xa) { - static UINT16 x,y; + UINT16 x,y; - y = (attr_buff[9] & 0x01f00000) >> 20; - x = (attr_buff[9] & 0x1f0) >> 4; - dst_addr = 0x3f40000 | y*0x40 | x; + y = (state->attr_buff[9] & 0x01f00000) >> 20; + x = (state->attr_buff[9] & 0x1f0) >> 4; + state->dst_addr = 0x3f40000 | y*0x40 | x; { int x2,y2; const gfx_element *gfx = space->machine->gfx[1]; rectangle clip; - y2 = (attr_buff[9] & 0x01ff0000) >> 16; - x2 = (attr_buff[9] & 0x000001ff); + y2 = (state->attr_buff[9] & 0x01ff0000) >> 16; + x2 = (state->attr_buff[9] & 0x000001ff); clip.min_x = 0; - clip.max_x = temp_bitmap_sprites->width; + clip.max_x = state->temp_bitmap_sprites->width; clip.min_y = 0; - clip.max_y = temp_bitmap_sprites->height; + clip.max_y = state->temp_bitmap_sprites->height; - drawgfx_opaque(temp_bitmap_sprites,&clip,gfx,1,1,0,0,x2,y2); + drawgfx_opaque(state->temp_bitmap_sprites,&clip,gfx,1,1,0,0,x2,y2); } } - if(attr_index == 0xc) + if(state->attr_index == 0xc) { - static UINT8 size; + UINT8 size; - size = (attr_buff[6] / 4)+1; - for(txt_index = 0;txt_index < size; txt_index++) + size = (state->attr_buff[6] / 4)+1; + for(state->txt_index = 0;state->txt_index < size; state->txt_index++) { - space->write_dword((dst_addr),txt_buff[txt_index]); - dst_addr+=4; + space->write_dword((state->dst_addr),state->txt_buff[state->txt_index]); + state->dst_addr+=4; } } } - else if((cmd & 0xff) == 0x10) + else if((state->cmd & 0xff) == 0x10) { - static UINT32 clear_vram; + UINT32 clear_vram; for(clear_vram=0x3f40000;clear_vram < 0x3f4ffff;clear_vram+=4) space->write_dword((clear_vram),0x00000000); } //else - // printf("CMD = %04x PARAM = %04x DATA = %08x\n",cmd,param,data); + // printf("CMD = %04x PARAM = %04x DATA = %08x\n",state->cmd,state->param,data); break; } } @@ -498,16 +521,17 @@ static WRITE32_HANDLER( sysh1_pal_w ) /* FIXME: this seems to do a hell lot of stuff, it's not ST-V SCU but still somewhat complex :/ */ static void sysh1_dma_transfer( address_space *space, UINT16 dma_index ) { - static UINT32 src,dst,size,type,s_i; - static UINT8 end_dma_mark; + coolridr_state *state = space->machine->driver_data(); + UINT32 src,dst,size,type,s_i; + UINT8 end_dma_mark; end_dma_mark = 0; do{ - src = (framebuffer_vram[(0+dma_index)/4] & 0x0fffffff); - dst = (framebuffer_vram[(4+dma_index)/4]); - size = framebuffer_vram[(8+dma_index)/4]; - type = (framebuffer_vram[(0+dma_index)/4] & 0xf0000000) >> 28; + src = (state->framebuffer_vram[(0+dma_index)/4] & 0x0fffffff); + dst = (state->framebuffer_vram[(4+dma_index)/4]); + size = state->framebuffer_vram[(8+dma_index)/4]; + type = (state->framebuffer_vram[(0+dma_index)/4] & 0xf0000000) >> 28; #if 0 if(type == 0xc || type == 0xd || type == 0xe) @@ -518,7 +542,7 @@ static void sysh1_dma_transfer( address_space *space, UINT16 dma_index ) if(type == 0x3 || type == 0x4) { - //type 3 sets a DMA param, type 4 sets some kind of table? Skip it for now + //type 3 sets a DMA state->param, type 4 sets some kind of table? Skip it for now dma_index+=4; continue; } @@ -573,26 +597,28 @@ static void sysh1_dma_transfer( address_space *space, UINT16 dma_index ) static WRITE32_HANDLER( sysh1_dma_w ) { - COMBINE_DATA(&framebuffer_vram[offset]); + coolridr_state *state = space->machine->driver_data(); + COMBINE_DATA(&state->framebuffer_vram[offset]); if(offset*4 == 0x000) { - if((framebuffer_vram[offset] & 0xff00000) == 0xfe00000) - sysh1_dma_transfer(space, framebuffer_vram[offset] & 0xffff); + if((state->framebuffer_vram[offset] & 0xff00000) == 0xfe00000) + sysh1_dma_transfer(space, state->framebuffer_vram[offset] & 0xffff); } } static WRITE32_HANDLER( sysh1_char_w ) { - COMBINE_DATA(&h1_charram[offset]); + coolridr_state *state = space->machine->driver_data(); + COMBINE_DATA(&state->h1_charram[offset]); { UINT8 *gfx = space->machine->region("ram_gfx")->base(); - gfx[offset*4+0] = (h1_charram[offset] & 0xff000000) >> 24; - gfx[offset*4+1] = (h1_charram[offset] & 0x00ff0000) >> 16; - gfx[offset*4+2] = (h1_charram[offset] & 0x0000ff00) >> 8; - gfx[offset*4+3] = (h1_charram[offset] & 0x000000ff) >> 0; + gfx[offset*4+0] = (state->h1_charram[offset] & 0xff000000) >> 24; + gfx[offset*4+1] = (state->h1_charram[offset] & 0x00ff0000) >> 16; + gfx[offset*4+2] = (state->h1_charram[offset] & 0x0000ff00) >> 8; + gfx[offset*4+3] = (state->h1_charram[offset] & 0x000000ff) >> 0; gfx_element_mark_dirty(space->machine->gfx[2], offset/64); //*4/256 } @@ -602,15 +628,15 @@ static ADDRESS_MAP_START( system_h1_map, ADDRESS_SPACE_PROGRAM, 32 ) AM_RANGE(0x00000000, 0x001fffff) AM_ROM AM_SHARE("share1") AM_WRITENOP AM_RANGE(0x01000000, 0x01ffffff) AM_ROM AM_REGION("gfx_data",0x0000000) - AM_RANGE(0x03000000, 0x030fffff) AM_RAM AM_BASE(&h1_vram)//bg vram + AM_RANGE(0x03000000, 0x030fffff) AM_RAM AM_BASE_MEMBER(coolridr_state, h1_vram)//bg vram AM_RANGE(0x03c00000, 0x03c0ffff) AM_RAM_WRITE(sysh1_pal_w) AM_BASE_GENERIC(paletteram) - AM_RANGE(0x03d00000, 0x03dfffff) AM_RAM_WRITE(sysh1_char_w) AM_BASE(&h1_charram) //FIXME: half size - AM_RANGE(0x03e00000, 0x03efffff) AM_RAM_WRITE(sysh1_dma_w) AM_BASE(&framebuffer_vram) //FIXME: not all of it + AM_RANGE(0x03d00000, 0x03dfffff) AM_RAM_WRITE(sysh1_char_w) AM_BASE_MEMBER(coolridr_state, h1_charram) //FIXME: half size + AM_RANGE(0x03e00000, 0x03efffff) AM_RAM_WRITE(sysh1_dma_w) AM_BASE_MEMBER(coolridr_state, framebuffer_vram) //FIXME: not all of it AM_RANGE(0x03f00000, 0x03f0ffff) AM_RAM AM_SHARE("share3") /*Communication area RAM*/ - AM_RANGE(0x03f40000, 0x03f4ffff) AM_RAM AM_BASE(&txt_vram)//text tilemap + "lineram" - AM_RANGE(0x04000000, 0x0400003f) AM_RAM_WRITE(sysh1_txt_blit_w) AM_BASE(&sysh1_txt_blit) - AM_RANGE(0x06000000, 0x060fffff) AM_RAM AM_BASE(&sysh1_workram_h) + AM_RANGE(0x03f40000, 0x03f4ffff) AM_RAM AM_BASE_MEMBER(coolridr_state, txt_vram)//text tilemap + "lineram" + AM_RANGE(0x04000000, 0x0400003f) AM_RAM_WRITE(sysh1_txt_blit_w) AM_BASE_MEMBER(coolridr_state, sysh1_txt_blit) + AM_RANGE(0x06000000, 0x060fffff) AM_RAM AM_BASE_MEMBER(coolridr_state, sysh1_workram_h) AM_RANGE(0x20000000, 0x201fffff) AM_ROM AM_SHARE("share1") AM_RANGE(0x60000000, 0x600003ff) AM_WRITENOP @@ -628,7 +654,7 @@ static ADDRESS_MAP_START( coolridr_submap, ADDRESS_SPACE_PROGRAM, 32 ) AM_RANGE(0x03208900, 0x03208903) AM_RAM /*???*/ AM_RANGE(0x03300400, 0x03300403) AM_RAM /*irq enable?*/ - AM_RANGE(0x04000000, 0x0400003f) AM_READWRITE(sysh1_unk_r,sysh1_unk_w) AM_BASE(&h1_unk) + AM_RANGE(0x04000000, 0x0400003f) AM_READWRITE(sysh1_unk_r,sysh1_unk_w) AM_BASE_MEMBER(coolridr_state, h1_unk) AM_RANGE(0x04200000, 0x0420003f) AM_RAM /*???*/ AM_RANGE(0x05000000, 0x05000fff) AM_RAM @@ -1067,7 +1093,7 @@ static MACHINE_RESET ( coolridr ) cputag_set_input_line(machine, "soundcpu", INPUT_LINE_HALT, ASSERT_LINE); } -static MACHINE_CONFIG_START( coolridr, driver_device ) +static MACHINE_CONFIG_START( coolridr, coolridr_state ) MCFG_CPU_ADD("maincpu", SH2, 28000000) // 28 mhz MCFG_CPU_PROGRAM_MAP(system_h1_map) MCFG_CPU_VBLANK_INT("screen",system_h1) @@ -1140,21 +1166,23 @@ ROM_END #if 0 static READ32_HANDLER( coolridr_hack1_r ) { + coolridr_state *state = space->machine->driver_data(); offs_t pc = downcast(space->cpu)->pc(); if(pc == 0x6012374 || pc == 0x6012392) return 0; - return sysh1_workram_h[0xd88a4/4]; + return state->sysh1_workram_h[0xd88a4/4]; } #endif static READ32_HANDLER( coolridr_hack2_r ) { + coolridr_state *state = space->machine->driver_data(); offs_t pc = downcast(space->cpu)->pc(); if(pc == 0x6002cba || pc == 0x6002d42) return 0; - return sysh1_workram_h[0xd8894/4]; + return state->sysh1_workram_h[0xd8894/4]; } static DRIVER_INIT( coolridr ) diff --git a/src/mame/drivers/djmain.c b/src/mame/drivers/djmain.c index 81beacad493..fa09190029e 100644 --- a/src/mame/drivers/djmain.c +++ b/src/mame/drivers/djmain.c @@ -71,21 +71,11 @@ hard drive 3.5 adapter long 3.5 IDE cable 3.5 adapter PCB #include "video/konicdev.h" #include "includes/djmain.h" -static int sndram_bank; -static UINT8 *sndram; -static int turntable_select; -static UINT8 turntable_last_pos[2]; -static UINT16 turntable_pos[2]; -static UINT8 pending_vb_int; -static UINT16 v_ctrl; -static UINT32 obj_regs[0xa0/4]; -static const UINT8 *ide_user_password; -static const UINT8 *ide_master_password; -#define DISABLE_VB_INT (!(v_ctrl & 0x8000)) +#define DISABLE_VB_INT (!(state->v_ctrl & 0x8000)) @@ -114,50 +104,54 @@ static WRITE32_HANDLER( paletteram32_w ) static void sndram_set_bank(running_machine *machine) { - sndram = machine->region("shared")->base() + 0x80000 * sndram_bank; + djmain_state *state = machine->driver_data(); + state->sndram = machine->region("shared")->base() + 0x80000 * state->sndram_bank; } static WRITE32_HANDLER( sndram_bank_w ) { + djmain_state *state = space->machine->driver_data(); if (ACCESSING_BITS_16_31) { - sndram_bank = (data >> 16) & 0x1f; + state->sndram_bank = (data >> 16) & 0x1f; sndram_set_bank(space->machine); } } static READ32_HANDLER( sndram_r ) { + djmain_state *state = space->machine->driver_data(); UINT32 data = 0; if (ACCESSING_BITS_24_31) - data |= sndram[offset * 4] << 24; + data |= state->sndram[offset * 4] << 24; if (ACCESSING_BITS_16_23) - data |= sndram[offset * 4 + 1] << 16; + data |= state->sndram[offset * 4 + 1] << 16; if (ACCESSING_BITS_8_15) - data |= sndram[offset * 4 + 2] << 8; + data |= state->sndram[offset * 4 + 2] << 8; if (ACCESSING_BITS_0_7) - data |= sndram[offset * 4 + 3]; + data |= state->sndram[offset * 4 + 3]; return data; } static WRITE32_HANDLER( sndram_w ) { + djmain_state *state = space->machine->driver_data(); if (ACCESSING_BITS_24_31) - sndram[offset * 4] = data >> 24; + state->sndram[offset * 4] = data >> 24; if (ACCESSING_BITS_16_23) - sndram[offset * 4 + 1] = data >> 16; + state->sndram[offset * 4 + 1] = data >> 16; if (ACCESSING_BITS_8_15) - sndram[offset * 4 + 2] = data >> 8; + state->sndram[offset * 4 + 2] = data >> 8; if (ACCESSING_BITS_0_7) - sndram[offset * 4 + 3] = data; + state->sndram[offset * 4 + 3] = data; } @@ -188,23 +182,26 @@ static WRITE16_HANDLER( dual539_w ) static READ32_HANDLER( obj_ctrl_r ) { - // read obj_regs[0x0c/4]: unknown - // read obj_regs[0x24/4]: unknown + djmain_state *state = space->machine->driver_data(); + // read state->obj_regs[0x0c/4]: unknown + // read state->obj_regs[0x24/4]: unknown - return obj_regs[offset]; + return state->obj_regs[offset]; } static WRITE32_HANDLER( obj_ctrl_w ) { - // write obj_regs[0x28/4]: bank for rom readthrough + djmain_state *state = space->machine->driver_data(); + // write state->obj_regs[0x28/4]: bank for rom readthrough - COMBINE_DATA(&obj_regs[offset]); + COMBINE_DATA(&state->obj_regs[offset]); } static READ32_HANDLER( obj_rom_r ) { + djmain_state *state = space->machine->driver_data(); UINT8 *mem8 = space->machine->region("gfx1")->base(); - int bank = obj_regs[0x28/4] >> 16; + int bank = state->obj_regs[0x28/4] >> 16; offset += bank * 0x200; offset *= 4; @@ -223,15 +220,16 @@ static READ32_HANDLER( obj_rom_r ) static WRITE32_HANDLER( v_ctrl_w ) { + djmain_state *state = space->machine->driver_data(); if (ACCESSING_BITS_16_31) { data >>= 16; mem_mask >>= 16; - COMBINE_DATA(&v_ctrl); + COMBINE_DATA(&state->v_ctrl); - if (pending_vb_int && !DISABLE_VB_INT) + if (state->pending_vb_int && !DISABLE_VB_INT) { - pending_vb_int = 0; + state->pending_vb_int = 0; cputag_set_input_line(space->machine, "maincpu", M68K_IRQ_4, HOLD_LINE); } } @@ -239,6 +237,7 @@ static WRITE32_HANDLER( v_ctrl_w ) static READ32_HANDLER( v_rom_r ) { + djmain_state *state = space->machine->driver_data(); device_t *k056832 = space->machine->device("k056832"); UINT8 *mem8 = space->machine->region("gfx2")->base(); int bank = k056832_word_r(k056832, 0x34/2, 0xffff); @@ -250,7 +249,7 @@ static READ32_HANDLER( v_rom_r ) offset += bank * 0x800 * 4; - if (v_ctrl & 0x020) + if (state->v_ctrl & 0x020) offset += 0x800 * 2; return mem8[offset] * 0x01010000; @@ -273,6 +272,7 @@ static READ8_HANDLER( inp2_r ) static READ32_HANDLER( turntable_r ) { + djmain_state *state = space->machine->driver_data(); UINT32 result = 0; static const char *const ttnames[] = { "TT1", "TT2" }; @@ -281,17 +281,17 @@ static READ32_HANDLER( turntable_r ) UINT8 pos; int delta; - pos = input_port_read_safe(space->machine, ttnames[turntable_select], 0); - delta = pos - turntable_last_pos[turntable_select]; + pos = input_port_read_safe(space->machine, ttnames[state->turntable_select], 0); + delta = pos - state->turntable_last_pos[state->turntable_select]; if (delta < -128) delta += 256; if (delta > 128) delta -= 256; - turntable_pos[turntable_select] += delta * 70; - turntable_last_pos[turntable_select] = pos; + state->turntable_pos[state->turntable_select] += delta * 70; + state->turntable_last_pos[state->turntable_select] = pos; - result |= turntable_pos[turntable_select] & 0xff00; + result |= state->turntable_pos[state->turntable_select] & 0xff00; } return result; @@ -299,8 +299,9 @@ static READ32_HANDLER( turntable_r ) static WRITE32_HANDLER( turntable_select_w ) { + djmain_state *state = space->machine->driver_data(); if (ACCESSING_BITS_16_23) - turntable_select = (data >> 19) & 1; + state->turntable_select = (data >> 19) & 1; } @@ -427,11 +428,12 @@ static WRITE32_HANDLER( unknownc02000_w ) static INTERRUPT_GEN( vb_interrupt ) { - pending_vb_int = 0; + djmain_state *state = device->machine->driver_data(); + state->pending_vb_int = 0; if (DISABLE_VB_INT) { - pending_vb_int = 1; + state->pending_vb_int = 1; return; } @@ -481,7 +483,7 @@ static ADDRESS_MAP_START( memory_map, ADDRESS_SPACE_PROGRAM, 32 ) AM_RANGE(0x5d6000, 0x5d6003) AM_WRITE(sndram_bank_w) // SOUND RAM bank AM_RANGE(0x5e0000, 0x5e0003) AM_READWRITE(turntable_r, turntable_select_w) // input port control (turn tables) AM_RANGE(0x600000, 0x601fff) AM_READ(v_rom_r) // VIDEO ROM readthrough (for POST) - AM_RANGE(0x801000, 0x8017ff) AM_RAM AM_BASE(&djmain_obj_ram) // OBJECT RAM + AM_RANGE(0x801000, 0x8017ff) AM_RAM AM_BASE_MEMBER(djmain_state, obj_ram) // OBJECT RAM AM_RANGE(0x802000, 0x802fff) AM_WRITE(unknown802000_w) // ?? AM_RANGE(0x803000, 0x80309f) AM_READWRITE(obj_ctrl_r, obj_ctrl_w) // OBJECT REGS AM_RANGE(0x803800, 0x803fff) AM_READ(obj_rom_r) // OBJECT ROM readthrough (for POST) @@ -1430,17 +1432,18 @@ static STATE_POSTLOAD( djmain_postload ) static MACHINE_START( djmain ) { + djmain_state *state = machine->driver_data(); device_t *ide = machine->device("ide"); - if (ide != NULL && ide_master_password != NULL) - ide_set_master_password(ide, ide_master_password); - if (ide != NULL && ide_user_password != NULL) - ide_set_user_password(ide, ide_user_password); + if (ide != NULL && state->ide_master_password != NULL) + ide_set_master_password(ide, state->ide_master_password); + if (ide != NULL && state->ide_user_password != NULL) + ide_set_user_password(ide, state->ide_user_password); - state_save_register_global(machine, sndram_bank); - state_save_register_global(machine, pending_vb_int); - state_save_register_global(machine, v_ctrl); - state_save_register_global_array(machine, obj_regs); + state_save_register_global(machine, state->sndram_bank); + state_save_register_global(machine, state->pending_vb_int); + state_save_register_global(machine, state->v_ctrl); + state_save_register_global_array(machine, state->obj_regs); machine->state().register_postload(djmain_postload, NULL); } @@ -1448,8 +1451,9 @@ static MACHINE_START( djmain ) static MACHINE_RESET( djmain ) { + djmain_state *state = machine->driver_data(); /* reset sound ram bank */ - sndram_bank = 0; + state->sndram_bank = 0; sndram_set_bank(machine); /* reset the IDE controller */ @@ -1478,7 +1482,7 @@ static const k056832_interface djmain_k056832_intf = djmain_tile_callback, "none" }; -static MACHINE_CONFIG_START( djmain, driver_device ) +static MACHINE_CONFIG_START( djmain, djmain_state ) /* basic machine hardware */ // popn3 works 9.6 MHz or slower in some songs */ @@ -2032,8 +2036,9 @@ ROM_END static DRIVER_INIT( beatmania ) { - ide_master_password = NULL; - ide_user_password = NULL; + djmain_state *state = machine->driver_data(); + state->ide_master_password = NULL; + state->ide_user_password = NULL; } static const UINT8 beatmania_master_password[2 + 32] = @@ -2047,6 +2052,7 @@ static const UINT8 beatmania_master_password[2 + 32] = static DRIVER_INIT( hmcompmx ) { + djmain_state *state = machine->driver_data(); static const UINT8 hmcompmx_user_password[2 + 32] = { 0x00, 0x00, @@ -2058,12 +2064,13 @@ static DRIVER_INIT( hmcompmx ) DRIVER_INIT_CALL(beatmania); - ide_master_password = beatmania_master_password; - ide_user_password = hmcompmx_user_password; + state->ide_master_password = beatmania_master_password; + state->ide_user_password = hmcompmx_user_password; } static DRIVER_INIT( bm4thmix ) { + djmain_state *state = machine->driver_data(); static const UINT8 bm4thmix_user_password[2 + 32] = { 0x00, 0x00, @@ -2075,11 +2082,12 @@ static DRIVER_INIT( bm4thmix ) DRIVER_INIT_CALL(beatmania); - ide_user_password = bm4thmix_user_password; + state->ide_user_password = bm4thmix_user_password; } static DRIVER_INIT( bm5thmix ) { + djmain_state *state = machine->driver_data(); static const UINT8 bm5thmix_user_password[2 + 32] = { 0x00, 0x00, @@ -2091,12 +2099,13 @@ static DRIVER_INIT( bm5thmix ) DRIVER_INIT_CALL(beatmania); - ide_master_password = beatmania_master_password; - ide_user_password = bm5thmix_user_password; + state->ide_master_password = beatmania_master_password; + state->ide_user_password = bm5thmix_user_password; } static DRIVER_INIT( bmclubmx ) { + djmain_state *state = machine->driver_data(); static const UINT8 bmclubmx_user_password[2 + 32] = { 0x00, 0x00, @@ -2108,13 +2117,14 @@ static DRIVER_INIT( bmclubmx ) DRIVER_INIT_CALL(beatmania); - ide_master_password = beatmania_master_password; - ide_user_password = bmclubmx_user_password; + state->ide_master_password = beatmania_master_password; + state->ide_user_password = bmclubmx_user_password; } static DRIVER_INIT( bmcompm2 ) { + djmain_state *state = machine->driver_data(); static const UINT8 bmcompm2_user_password[2 + 32] = { 0x00, 0x00, @@ -2126,12 +2136,13 @@ static DRIVER_INIT( bmcompm2 ) DRIVER_INIT_CALL(beatmania); - ide_master_password = beatmania_master_password; - ide_user_password = bmcompm2_user_password; + state->ide_master_password = beatmania_master_password; + state->ide_user_password = bmcompm2_user_password; } static DRIVER_INIT( hmcompm2 ) { + djmain_state *state = machine->driver_data(); static const UINT8 hmcompm2_user_password[2 + 32] = { 0x00, 0x00, @@ -2143,12 +2154,13 @@ static DRIVER_INIT( hmcompm2 ) DRIVER_INIT_CALL(beatmania); - ide_master_password = beatmania_master_password; - ide_user_password = hmcompm2_user_password; + state->ide_master_password = beatmania_master_password; + state->ide_user_password = hmcompm2_user_password; } static DRIVER_INIT( bmdct ) { + djmain_state *state = machine->driver_data(); static const UINT8 bmdct_user_password[2 + 32] = { 0x00, 0x00, @@ -2160,12 +2172,13 @@ static DRIVER_INIT( bmdct ) DRIVER_INIT_CALL(beatmania); - ide_master_password = beatmania_master_password; - ide_user_password = bmdct_user_password; + state->ide_master_password = beatmania_master_password; + state->ide_user_password = bmdct_user_password; } static DRIVER_INIT( bmcorerm ) { + djmain_state *state = machine->driver_data(); static const UINT8 bmcorerm_user_password[2 + 32] = { 0x00, 0x00, @@ -2177,12 +2190,13 @@ static DRIVER_INIT( bmcorerm ) DRIVER_INIT_CALL(beatmania); - ide_master_password = beatmania_master_password; - ide_user_password = bmcorerm_user_password; + state->ide_master_password = beatmania_master_password; + state->ide_user_password = bmcorerm_user_password; } static DRIVER_INIT( bm6thmix ) { + djmain_state *state = machine->driver_data(); static const UINT8 bm6thmix_user_password[2 + 32] = { 0x00, 0x00, @@ -2194,12 +2208,13 @@ static DRIVER_INIT( bm6thmix ) DRIVER_INIT_CALL(beatmania); - ide_master_password = beatmania_master_password; - ide_user_password = bm6thmix_user_password; + state->ide_master_password = beatmania_master_password; + state->ide_user_password = bm6thmix_user_password; } static DRIVER_INIT( bm7thmix ) { + djmain_state *state = machine->driver_data(); static const UINT8 bm7thmix_user_password[2 + 32] = { 0x00, 0x00, @@ -2211,12 +2226,13 @@ static DRIVER_INIT( bm7thmix ) DRIVER_INIT_CALL(beatmania); - ide_master_password = beatmania_master_password; - ide_user_password = bm7thmix_user_password; + state->ide_master_password = beatmania_master_password; + state->ide_user_password = bm7thmix_user_password; } static DRIVER_INIT( bmfinal ) { + djmain_state *state = machine->driver_data(); static const UINT8 bmfinal_user_password[2 + 32] = { 0x00, 0x00, @@ -2228,8 +2244,8 @@ static DRIVER_INIT( bmfinal ) DRIVER_INIT_CALL(beatmania); - ide_master_password = beatmania_master_password; - ide_user_password = bmfinal_user_password; + state->ide_master_password = beatmania_master_password; + state->ide_user_password = bmfinal_user_password; } diff --git a/src/mame/drivers/fastfred.c b/src/mame/drivers/fastfred.c index 636dba13637..44a5401529a 100644 --- a/src/mame/drivers/fastfred.c +++ b/src/mame/drivers/fastfred.c @@ -121,13 +121,11 @@ static READ8_HANDLER( boggy84_custom_io_r ) Imago sprites DMA */ -static UINT8 imago_sprites[0x800*3]; -static UINT16 imago_sprites_address; -static UINT8 imago_sprites_bank = 0; static MACHINE_START( imago ) { - gfx_element_set_source(machine->gfx[1], imago_sprites); + fastfred_state *state = machine->driver_data(); + gfx_element_set_source(machine->gfx[1], state->imago_sprites); } static WRITE8_HANDLER( imago_dma_irq_w ) @@ -137,40 +135,43 @@ static WRITE8_HANDLER( imago_dma_irq_w ) static WRITE8_HANDLER( imago_sprites_bank_w ) { - imago_sprites_bank = (data & 2) >> 1; + fastfred_state *state = space->machine->driver_data(); + state->imago_sprites_bank = (data & 2) >> 1; } static WRITE8_HANDLER( imago_sprites_dma_w ) { + fastfred_state *state = space->machine->driver_data(); UINT8 *rom = (UINT8 *)space->machine->region("gfx2")->base(); UINT8 sprites_data; - sprites_data = rom[imago_sprites_address + 0x2000*0 + imago_sprites_bank * 0x1000]; - imago_sprites[offset + 0x800*0] = sprites_data; + sprites_data = rom[state->imago_sprites_address + 0x2000*0 + state->imago_sprites_bank * 0x1000]; + state->imago_sprites[offset + 0x800*0] = sprites_data; - sprites_data = rom[imago_sprites_address + 0x2000*1 + imago_sprites_bank * 0x1000]; - imago_sprites[offset + 0x800*1] = sprites_data; + sprites_data = rom[state->imago_sprites_address + 0x2000*1 + state->imago_sprites_bank * 0x1000]; + state->imago_sprites[offset + 0x800*1] = sprites_data; - sprites_data = rom[imago_sprites_address + 0x2000*2 + imago_sprites_bank * 0x1000]; - imago_sprites[offset + 0x800*2] = sprites_data; + sprites_data = rom[state->imago_sprites_address + 0x2000*2 + state->imago_sprites_bank * 0x1000]; + state->imago_sprites[offset + 0x800*2] = sprites_data; gfx_element_mark_dirty(space->machine->gfx[1], offset/32); } static READ8_HANDLER( imago_sprites_offset_r ) { - imago_sprites_address = offset; + fastfred_state *state = space->machine->driver_data(); + state->imago_sprites_address = offset; return 0xff; //not really used } static ADDRESS_MAP_START( fastfred_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x0000, 0xbfff) AM_ROM AM_RANGE(0xc000, 0xc7ff) AM_RAM - AM_RANGE(0xd000, 0xd3ff) AM_MIRROR(0x400) AM_RAM_WRITE(fastfred_videoram_w) AM_BASE(&fastfred_videoram) - AM_RANGE(0xd800, 0xd83f) AM_RAM_WRITE(fastfred_attributes_w) AM_BASE(&fastfred_attributesram) - AM_RANGE(0xd840, 0xd85f) AM_RAM AM_BASE(&fastfred_spriteram) AM_SIZE(&fastfred_spriteram_size) + AM_RANGE(0xd000, 0xd3ff) AM_MIRROR(0x400) AM_RAM_WRITE(fastfred_videoram_w) AM_BASE_MEMBER(fastfred_state, videoram) + AM_RANGE(0xd800, 0xd83f) AM_RAM_WRITE(fastfred_attributes_w) AM_BASE_MEMBER(fastfred_state, attributesram) + AM_RANGE(0xd840, 0xd85f) AM_RAM AM_BASE_MEMBER(fastfred_state, spriteram) AM_SIZE_MEMBER(fastfred_state, spriteram_size) AM_RANGE(0xd860, 0xdbff) AM_RAM // Unused, but initialized - AM_RANGE(0xe000, 0xe000) AM_READ_PORT("BUTTONS") AM_WRITEONLY AM_BASE(&fastfred_background_color) + AM_RANGE(0xe000, 0xe000) AM_READ_PORT("BUTTONS") AM_WRITEONLY AM_BASE_MEMBER(fastfred_state, background_color) AM_RANGE(0xe800, 0xe800) AM_READ_PORT("JOYS") AM_RANGE(0xf000, 0xf000) AM_READ_PORT("DSW") AM_WRITENOP AM_RANGE(0xf001, 0xf001) AM_WRITE(interrupt_enable_w) @@ -189,11 +190,11 @@ ADDRESS_MAP_END static ADDRESS_MAP_START( jumpcoas_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x0000, 0x7fff) AM_ROM AM_RANGE(0xc000, 0xc7ff) AM_RAM - AM_RANGE(0xd000, 0xd03f) AM_RAM_WRITE(fastfred_attributes_w) AM_BASE(&fastfred_attributesram) - AM_RANGE(0xd040, 0xd05f) AM_RAM AM_BASE(&fastfred_spriteram) AM_SIZE(&fastfred_spriteram_size) + AM_RANGE(0xd000, 0xd03f) AM_RAM_WRITE(fastfred_attributes_w) AM_BASE_MEMBER(fastfred_state, attributesram) + AM_RANGE(0xd040, 0xd05f) AM_RAM AM_BASE_MEMBER(fastfred_state, spriteram) AM_SIZE_MEMBER(fastfred_state, spriteram_size) AM_RANGE(0xd060, 0xd3ff) AM_RAM - AM_RANGE(0xd800, 0xdbff) AM_MIRROR(0x400) AM_RAM_WRITE(fastfred_videoram_w) AM_BASE(&fastfred_videoram) - AM_RANGE(0xe000, 0xe000) AM_WRITEONLY AM_BASE(&fastfred_background_color) + AM_RANGE(0xd800, 0xdbff) AM_MIRROR(0x400) AM_RAM_WRITE(fastfred_videoram_w) AM_BASE_MEMBER(fastfred_state, videoram) + AM_RANGE(0xe000, 0xe000) AM_WRITEONLY AM_BASE_MEMBER(fastfred_state, background_color) AM_RANGE(0xe800, 0xe800) AM_READ_PORT("DSW1") AM_RANGE(0xe801, 0xe801) AM_READ_PORT("DSW2") AM_RANGE(0xe802, 0xe802) AM_READ_PORT("BUTTONS") @@ -220,10 +221,10 @@ static ADDRESS_MAP_START( imago_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0xb000, 0xb3ff) AM_RAM // same fg videoram (which one of the 2 is really used?) AM_RANGE(0xb800, 0xbfff) AM_RAM_WRITE(imago_sprites_dma_w) AM_RANGE(0xc000, 0xc7ff) AM_RAM - AM_RANGE(0xc800, 0xcbff) AM_RAM_WRITE(imago_fg_videoram_w) AM_BASE(&imago_fg_videoram) - AM_RANGE(0xd000, 0xd3ff) AM_RAM_WRITE(fastfred_videoram_w) AM_BASE(&fastfred_videoram) - AM_RANGE(0xd800, 0xd83f) AM_RAM_WRITE(fastfred_attributes_w) AM_BASE(&fastfred_attributesram) - AM_RANGE(0xd840, 0xd85f) AM_RAM AM_BASE(&fastfred_spriteram) AM_SIZE(&fastfred_spriteram_size) + AM_RANGE(0xc800, 0xcbff) AM_RAM_WRITE(imago_fg_videoram_w) AM_BASE_MEMBER(fastfred_state, imago_fg_videoram) + AM_RANGE(0xd000, 0xd3ff) AM_RAM_WRITE(fastfred_videoram_w) AM_BASE_MEMBER(fastfred_state, videoram) + AM_RANGE(0xd800, 0xd83f) AM_RAM_WRITE(fastfred_attributes_w) AM_BASE_MEMBER(fastfred_state, attributesram) + AM_RANGE(0xd840, 0xd85f) AM_RAM AM_BASE_MEMBER(fastfred_state, spriteram) AM_SIZE_MEMBER(fastfred_state, spriteram_size) AM_RANGE(0xd860, 0xd8ff) AM_RAM // Unused, but initialized AM_RANGE(0xe000, 0xe000) AM_READ_PORT("BUTTONS") AM_RANGE(0xe800, 0xe800) AM_READ_PORT("JOYS") @@ -616,7 +617,7 @@ GFXDECODE_END #define CLOCK 18432000 /* The crystal is 18.432MHz */ -static MACHINE_CONFIG_START( fastfred, driver_device ) +static MACHINE_CONFIG_START( fastfred, fastfred_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu", Z80, CLOCK/6) /* 3.072 MHz */ @@ -976,48 +977,55 @@ ROM_END static DRIVER_INIT( flyboy ) { + fastfred_state *state = machine->driver_data(); memory_install_read8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xc085, 0xc099, 0, 0, flyboy_custom1_io_r); memory_install_read8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xc8fb, 0xc900, 0, 0, flyboy_custom2_io_r); - fastfred_hardware_type = 1; + state->hardware_type = 1; } static DRIVER_INIT( flyboyb ) { - fastfred_hardware_type = 1; + fastfred_state *state = machine->driver_data(); + state->hardware_type = 1; } static DRIVER_INIT( fastfred ) { + fastfred_state *state = machine->driver_data(); memory_install_read8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xc800, 0xcfff, 0, 0, fastfred_custom_io_r); memory_nop_write(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xc800, 0xcfff, 0, 0); - fastfred_hardware_type = 1; + state->hardware_type = 1; } static DRIVER_INIT( jumpcoas ) { + fastfred_state *state = machine->driver_data(); memory_install_read8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xc800, 0xcfff, 0, 0, jumpcoas_custom_io_r); memory_nop_write(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xc800, 0xcfff, 0, 0); - fastfred_hardware_type = 0; + state->hardware_type = 0; } static DRIVER_INIT( boggy84b ) { + fastfred_state *state = machine->driver_data(); memory_install_read8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xc800, 0xcfff, 0, 0, jumpcoas_custom_io_r); memory_nop_write(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xc800, 0xcfff, 0, 0); - fastfred_hardware_type = 2; + state->hardware_type = 2; } static DRIVER_INIT( boggy84 ) { + fastfred_state *state = machine->driver_data(); memory_install_read8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xc800, 0xcfff, 0, 0, boggy84_custom_io_r); memory_nop_write(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xc800, 0xcfff, 0, 0); - fastfred_hardware_type = 2; + state->hardware_type = 2; } static DRIVER_INIT( imago ) { - fastfred_hardware_type = 3; + fastfred_state *state = machine->driver_data(); + state->hardware_type = 3; } GAME( 1982, flyboy, 0, fastfred, flyboy, flyboy, ROT90, "Kaneko", "Fly-Boy", 0 ) diff --git a/src/mame/drivers/firebeat.c b/src/mame/drivers/firebeat.c index 3d104fcbe82..41e35171653 100644 --- a/src/mame/drivers/firebeat.c +++ b/src/mame/drivers/firebeat.c @@ -121,7 +121,6 @@ #include "firebeat.lh" - typedef struct { UINT32 *vram; @@ -130,26 +129,72 @@ typedef struct UINT32 visible_area; } GCU_REGS; -static UINT8 extend_board_irq_enable; -static UINT8 extend_board_irq_active; +typedef struct +{ + UINT8 identifier[8]; + UINT8 password[8]; + UINT8 data[0x30]; +} IBUTTON_SUBKEY; + +typedef struct +{ + IBUTTON_SUBKEY subkey[3]; +} IBUTTON; + + + +class firebeat_state : public driver_device +{ +public: + firebeat_state(running_machine &machine, const driver_device_config_base &config) + : driver_device(machine, config) { } + + UINT8 extend_board_irq_enable; + UINT8 extend_board_irq_active; + emu_timer *keyboard_timer; + fujitsu_29f016a_device *flash[3]; + GCU_REGS gcu[2]; + int tick; + int layer; + UINT8 atapi_regs[16]; + SCSIInstance *atapi_device_data[2]; + UINT16 atapi_data[32*1024]; + UINT8 atapi_scsi_packet[32*1024]; + int atapi_data_ptr; + int atapi_xferlen; + int atapi_xfermod; + int atapi_cdata_wait; + int atapi_drivesel; + UINT8 temp_data[64*1024]; + int cab_data_ptr; + const int * cur_cab_data; + int keyboard_state[2]; + UINT8 spu_shared_ram[0x400]; + UINT32 *work_ram; + IBUTTON ibutton; + int ibutton_state; + int ibutton_read_subkey_ptr; + UINT8 ibutton_subkey_data[0x40]; +}; + + -static emu_timer *keyboard_timer; -static fujitsu_29f016a_device *flash[3]; -static GCU_REGS gcu[2]; static VIDEO_START(firebeat) { - gcu[0].vram = auto_alloc_array(machine, UINT32, 0x2000000/4); - gcu[1].vram = auto_alloc_array(machine, UINT32, 0x2000000/4); - memset(gcu[0].vram, 0, 0x2000000); - memset(gcu[1].vram, 0, 0x2000000); + firebeat_state *state = machine->driver_data(); + state->gcu[0].vram = auto_alloc_array(machine, UINT32, 0x2000000/4); + state->gcu[1].vram = auto_alloc_array(machine, UINT32, 0x2000000/4); + memset(state->gcu[0].vram, 0, 0x2000000); + memset(state->gcu[1].vram, 0, 0x2000000); } -static void gcu_draw_object(int chip, bitmap_t *bitmap, const rectangle *cliprect, UINT32 *cmd) +static void gcu_draw_object(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int chip, UINT32 *cmd) { + firebeat_state *state = machine->driver_data(); // 0x00: xxx----- -------- -------- -------- command type // 0x00: -------- xxxxxxxx xxxxxxxx xxxxxxxx object data address in vram @@ -179,7 +224,7 @@ static void gcu_draw_object(int chip, bitmap_t *bitmap, const rectangle *cliprec int i, j; int u, v; - UINT16 *vr = (UINT16*)gcu[chip].vram; + UINT16 *vr = (UINT16*)state->gcu[chip].vram; if (xscale == 0 || yscale == 0) { @@ -348,8 +393,9 @@ static void gcu_fill_rect(bitmap_t *bitmap, const rectangle *cliprect, UINT32 *c } } -static void gcu_draw_character(int chip, bitmap_t *bitmap, const rectangle *cliprect, UINT32 *cmd) +static void gcu_draw_character(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int chip, UINT32 *cmd) { + firebeat_state *state = machine->driver_data(); // 0x00: xxx----- -------- -------- -------- command type // 0x00: -------- xxxxxxxx xxxxxxxx xxxxxxxx character data address in vram @@ -368,7 +414,7 @@ static void gcu_draw_character(int chip, bitmap_t *bitmap, const rectangle *clip UINT32 address = cmd[0] & 0xffffff; UINT16 color[4]; - UINT16 *vr = (UINT16*)gcu[chip].vram; + UINT16 *vr = (UINT16*)state->gcu[chip].vram; color[0] = (cmd[2] >> 16) & 0xffff; color[1] = (cmd[2] >> 0) & 0xffff; @@ -396,8 +442,9 @@ static void gcu_draw_character(int chip, bitmap_t *bitmap, const rectangle *clip } } -static void gcu_exec_display_list(int chip, bitmap_t *bitmap, const rectangle *cliprect, UINT32 address) +static void gcu_exec_display_list(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int chip, UINT32 address) { + firebeat_state *state = machine->driver_data(); int counter = 0; int end = 0; @@ -407,10 +454,10 @@ static void gcu_exec_display_list(int chip, bitmap_t *bitmap, const rectangle *c { int command; UINT32 cmd[4]; - cmd[0] = gcu[chip].vram[i+0]; - cmd[1] = gcu[chip].vram[i+1]; - cmd[2] = gcu[chip].vram[i+2]; - cmd[3] = gcu[chip].vram[i+3]; + cmd[0] = state->gcu[chip].vram[i+0]; + cmd[1] = state->gcu[chip].vram[i+1]; + cmd[2] = state->gcu[chip].vram[i+2]; + cmd[3] = state->gcu[chip].vram[i+3]; command = (cmd[0] >> 29) & 0x7; @@ -423,7 +470,7 @@ static void gcu_exec_display_list(int chip, bitmap_t *bitmap, const rectangle *c case 0x1: // Branch { - gcu_exec_display_list(chip, bitmap, cliprect, cmd[0] & 0xffffff); + gcu_exec_display_list(machine, bitmap, cliprect, chip, cmd[0] & 0xffffff); break; } @@ -446,13 +493,13 @@ static void gcu_exec_display_list(int chip, bitmap_t *bitmap, const rectangle *c case 0x5: // Draw object { - gcu_draw_object(chip, bitmap, cliprect, cmd); + gcu_draw_object(machine, bitmap, cliprect, chip, cmd); break; } case 0x7: // Draw 8x8 Character (2-bits per pixel) { - gcu_draw_character(chip, bitmap, cliprect, cmd); + gcu_draw_character(machine, bitmap, cliprect, chip, cmd); break; } @@ -466,10 +513,9 @@ static void gcu_exec_display_list(int chip, bitmap_t *bitmap, const rectangle *c }; } -static int tick = 0; -static int layer = 0; static VIDEO_UPDATE(firebeat) { + firebeat_state *state = screen->machine->driver_data(); int chip; if (screen == screen->machine->m_devicelist.find(SCREEN, 0)) @@ -481,40 +527,40 @@ static VIDEO_UPDATE(firebeat) if (mame_stricmp(screen->machine->gamedrv->name, "popn7") == 0) { - gcu_exec_display_list(chip, bitmap, cliprect, 0x1f80000); + gcu_exec_display_list(screen->machine, bitmap, cliprect, chip, 0x1f80000); } else { - if (layer >= 2) + if (state->layer >= 2) { - gcu_exec_display_list(chip, bitmap, cliprect, 0x8000); - gcu_exec_display_list(chip, bitmap, cliprect, 0x0000); - gcu_exec_display_list(chip, bitmap, cliprect, 0x10000); + gcu_exec_display_list(screen->machine, bitmap, cliprect, chip, 0x8000); + gcu_exec_display_list(screen->machine, bitmap, cliprect, chip, 0x0000); + gcu_exec_display_list(screen->machine, bitmap, cliprect, chip, 0x10000); } - else if (layer == 0) + else if (state->layer == 0) { - gcu_exec_display_list(chip, bitmap, cliprect, 0x200000); + gcu_exec_display_list(screen->machine, bitmap, cliprect, chip, 0x200000); - //gcu_exec_display_list(chip, bitmap, cliprect, 0x186040); + //gcu_exec_display_list(screen->machine, bitmap, cliprect, chip, 0x186040); } - else if (layer == 1) + else if (state->layer == 1) { - gcu_exec_display_list(chip, bitmap, cliprect, 0x1d0800); + gcu_exec_display_list(screen->machine, bitmap, cliprect, chip, 0x1d0800); - gcu_exec_display_list(chip, bitmap, cliprect, 0x1a9440); + gcu_exec_display_list(screen->machine, bitmap, cliprect, chip, 0x1a9440); } } - tick++; - if (tick >= 5) + state->tick++; + if (state->tick >= 5) { - tick = 0; + state->tick = 0; if (input_code_pressed(screen->machine, KEYCODE_0)) { - layer++; - if (layer > 2) + state->layer++; + if (state->layer > 2) { - layer = 0; + state->layer = 0; } } @@ -526,10 +572,10 @@ static VIDEO_UPDATE(firebeat) for (i=0; i < 0x2000000/4; i++) { - fputc((gcu[0].vram[i] >> 24) & 0xff, file); - fputc((gcu[0].vram[i] >> 16) & 0xff, file); - fputc((gcu[0].vram[i] >> 8) & 0xff, file); - fputc((gcu[0].vram[i] >> 0) & 0xff, file); + fputc((state->gcu[0].vram[i] >> 24) & 0xff, file); + fputc((state->gcu[0].vram[i] >> 16) & 0xff, file); + fputc((state->gcu[0].vram[i] >> 8) & 0xff, file); + fputc((state->gcu[0].vram[i] >> 0) & 0xff, file); } fclose(file); @@ -537,10 +583,10 @@ static VIDEO_UPDATE(firebeat) for (i=0; i < 0x2000000/4; i++) { - fputc((gcu[1].vram[i] >> 24) & 0xff, file); - fputc((gcu[1].vram[i] >> 16) & 0xff, file); - fputc((gcu[1].vram[i] >> 8) & 0xff, file); - fputc((gcu[1].vram[i] >> 0) & 0xff, file); + fputc((state->gcu[1].vram[i] >> 24) & 0xff, file); + fputc((state->gcu[1].vram[i] >> 16) & 0xff, file); + fputc((state->gcu[1].vram[i] >> 8) & 0xff, file); + fputc((state->gcu[1].vram[i] >> 0) & 0xff, file); } fclose(file); @@ -551,14 +597,15 @@ static VIDEO_UPDATE(firebeat) return 0; } -static UINT32 GCU_r(int chip, UINT32 offset, UINT32 mem_mask) +static UINT32 GCU_r(running_machine *machine, int chip, UINT32 offset, UINT32 mem_mask) { + firebeat_state *state = machine->driver_data(); int reg = offset * 4; /* VRAM Read */ if (reg >= 0x80 && reg < 0x100) { - return gcu[chip].vram[gcu[chip].vram_read_address + ((reg/4) - 0x20)]; + return state->gcu[chip].vram[state->gcu[chip].vram_read_address + ((reg/4) - 0x20)]; } switch(reg) @@ -576,12 +623,13 @@ static UINT32 GCU_r(int chip, UINT32 offset, UINT32 mem_mask) static void GCU_w(running_machine *machine, int chip, UINT32 offset, UINT32 data, UINT32 mem_mask) { + firebeat_state *state = machine->driver_data(); int reg = offset * 4; if (reg != 0x70 && chip == 0) { - //printf("%s:gcu%d_w: %08X, %08X, %08X at %08X\n", machine->describe_context(), chip, data, offset, mem_mask); - //logerror("%s:gcu%d_w: %08X, %08X, %08X at %08X\n", cmachine->describe_context(), hip, data, offset, mem_mask); + //printf("%s:state->gcu%d_w: %08X, %08X, %08X at %08X\n", machine->describe_context(), chip, data, offset, mem_mask); + //logerror("%s:state->gcu%d_w: %08X, %08X, %08X at %08X\n", cmachine->describe_context(), hip, data, offset, mem_mask); } switch(reg) @@ -598,7 +646,7 @@ static void GCU_w(running_machine *machine, int chip, UINT32 offset, UINT32 data //case 0x38: //case 0x3c: { - COMBINE_DATA( &gcu[chip].visible_area ); + COMBINE_DATA( &state->gcu[chip].visible_area ); if (ACCESSING_BITS_0_15) { screen_device *screen = downcast(machine->m_devicelist.find(SCREEN, chip)); @@ -608,8 +656,8 @@ static void GCU_w(running_machine *machine, int chip, UINT32 offset, UINT32 data rectangle visarea = screen->visible_area(); int width, height; - width = (gcu[chip].visible_area & 0xffff); - height = (gcu[chip].visible_area >> 16) & 0xffff; + width = (state->gcu[chip].visible_area & 0xffff); + height = (state->gcu[chip].visible_area >> 16) & 0xffff; visarea.max_x = width-1; visarea.max_y = height-1; @@ -627,11 +675,11 @@ static void GCU_w(running_machine *machine, int chip, UINT32 offset, UINT32 data // break; case 0x5c: /* VRAM Read Address */ - gcu[chip].vram_read_address = (data & 0xffffff) / 2; + state->gcu[chip].vram_read_address = (data & 0xffffff) / 2; break; case 0x60: /* VRAM FIFO Write Address */ - gcu[chip].vram_write_fifo_address = (data & 0xffffff) / 2; + state->gcu[chip].vram_write_fifo_address = (data & 0xffffff) / 2; // printf("gcu%d_w: %08X, %08X, %08X\n", chip, data, offset, mem_mask); break; @@ -642,8 +690,8 @@ static void GCU_w(running_machine *machine, int chip, UINT32 offset, UINT32 data } case 0x70: /* VRAM FIFO Write */ - gcu[chip].vram[gcu[chip].vram_write_fifo_address] = data; - gcu[chip].vram_write_fifo_address++; + state->gcu[chip].vram[state->gcu[chip].vram_write_fifo_address] = data; + state->gcu[chip].vram_write_fifo_address++; break; default: @@ -654,7 +702,7 @@ static void GCU_w(running_machine *machine, int chip, UINT32 offset, UINT32 data static READ32_HANDLER(gcu0_r) { - return GCU_r(0, offset, mem_mask); + return GCU_r(space->machine, 0, offset, mem_mask); } static WRITE32_HANDLER(gcu0_w) @@ -664,7 +712,7 @@ static WRITE32_HANDLER(gcu0_w) static READ32_HANDLER(gcu1_r) { - return GCU_r(1, offset, mem_mask); + return GCU_r(space->machine, 1, offset, mem_mask); } static WRITE32_HANDLER(gcu1_w) @@ -708,57 +756,60 @@ static READ32_HANDLER( sensor_r ) static READ32_HANDLER(flashram_r) { + firebeat_state *state = space->machine->driver_data(); UINT32 r = 0; if (ACCESSING_BITS_24_31) { - r |= (flash[0]->read((offset*4)+0) & 0xff) << 24; + r |= (state->flash[0]->read((offset*4)+0) & 0xff) << 24; } if (ACCESSING_BITS_16_23) { - r |= (flash[0]->read((offset*4)+1) & 0xff) << 16; + r |= (state->flash[0]->read((offset*4)+1) & 0xff) << 16; } if (ACCESSING_BITS_8_15) { - r |= (flash[0]->read((offset*4)+2) & 0xff) << 8; + r |= (state->flash[0]->read((offset*4)+2) & 0xff) << 8; } if (ACCESSING_BITS_0_7) { - r |= (flash[0]->read((offset*4)+3) & 0xff) << 0; + r |= (state->flash[0]->read((offset*4)+3) & 0xff) << 0; } return r; } static WRITE32_HANDLER(flashram_w) { + firebeat_state *state = space->machine->driver_data(); if (ACCESSING_BITS_24_31) { - flash[0]->write((offset*4)+0, (data >> 24) & 0xff); + state->flash[0]->write((offset*4)+0, (data >> 24) & 0xff); } if (ACCESSING_BITS_16_23) { - flash[0]->write((offset*4)+1, (data >> 16) & 0xff); + state->flash[0]->write((offset*4)+1, (data >> 16) & 0xff); } if (ACCESSING_BITS_8_15) { - flash[0]->write((offset*4)+2, (data >> 8) & 0xff); + state->flash[0]->write((offset*4)+2, (data >> 8) & 0xff); } if (ACCESSING_BITS_0_7) { - flash[0]->write((offset*4)+3, (data >> 0) & 0xff); + state->flash[0]->write((offset*4)+3, (data >> 0) & 0xff); } } static READ32_HANDLER(soundflash_r) { + firebeat_state *state = space->machine->driver_data(); UINT32 r = 0; fujitsu_29f016a_device *chip; if (offset >= 0 && offset < 0x200000/4) { - chip = flash[1]; + chip = state->flash[1]; } else { - chip = flash[2]; + chip = state->flash[2]; } offset &= 0x7ffff; @@ -784,14 +835,15 @@ static READ32_HANDLER(soundflash_r) static WRITE32_HANDLER(soundflash_w) { + firebeat_state *state = space->machine->driver_data(); fujitsu_29f016a_device *chip; if (offset >= 0 && offset < 0x200000/4) { - chip = flash[1]; + chip = state->flash[1]; } else { - chip = flash[2]; + chip = state->flash[2]; } offset &= 0x7ffff; @@ -827,8 +879,6 @@ static WRITE32_HANDLER(soundflash_w) #define ATAPI_CYCLES_PER_SECTOR (32000) // plenty of time to allow DMA setup etc. BIOS requires this be at least 2000, individual games may vary. -static UINT8 atapi_regs[16]; -static SCSIInstance *atapi_device_data[2]; #define ATAPI_STAT_BSY 0x80 #define ATAPI_STAT_DRDY 0x40 @@ -851,10 +901,6 @@ static SCSIInstance *atapi_device_data[2]; #define ATAPI_REG_DRIVESEL 6 #define ATAPI_REG_CMDSTATUS 7 -static UINT16 atapi_data[32*1024]; -static UINT8 atapi_scsi_packet[32*1024]; -static int atapi_data_ptr, atapi_xferlen, atapi_xfermod, atapi_cdata_wait; -static int atapi_drivesel; static void atapi_cause_irq(running_machine *machine) { @@ -868,96 +914,99 @@ static void atapi_clear_irq(running_machine *machine) static void atapi_exit(running_machine& machine) { - SCSIDeleteInstance(atapi_device_data[1]); - SCSIDeleteInstance(atapi_device_data[0]); + firebeat_state *state = machine.driver_data(); + SCSIDeleteInstance(state->atapi_device_data[1]); + SCSIDeleteInstance(state->atapi_device_data[0]); } static void atapi_init(running_machine *machine) { - memset(atapi_regs, 0, sizeof(atapi_regs)); + firebeat_state *state = machine->driver_data(); + memset(state->atapi_regs, 0, sizeof(state->atapi_regs)); - atapi_regs[ATAPI_REG_CMDSTATUS] = 0; - atapi_regs[ATAPI_REG_ERRFEAT] = 1; - atapi_regs[ATAPI_REG_COUNTLOW] = 0x14; - atapi_regs[ATAPI_REG_COUNTHIGH] = 0xeb; + state->atapi_regs[ATAPI_REG_CMDSTATUS] = 0; + state->atapi_regs[ATAPI_REG_ERRFEAT] = 1; + state->atapi_regs[ATAPI_REG_COUNTLOW] = 0x14; + state->atapi_regs[ATAPI_REG_COUNTHIGH] = 0xeb; - atapi_data_ptr = 0; - atapi_cdata_wait = 0; + state->atapi_data_ptr = 0; + state->atapi_cdata_wait = 0; // allocate two SCSI CD-ROM devices - SCSIAllocInstance( machine, SCSI_DEVICE_CDROM, &atapi_device_data[0], "scsi0" ); + SCSIAllocInstance( machine, SCSI_DEVICE_CDROM, &state->atapi_device_data[0], "scsi0" ); // TODO: the slave drive can be either CD-ROM, DVD-ROM or HDD - SCSIAllocInstance( machine, SCSI_DEVICE_CDROM, &atapi_device_data[1], "scsi1" ); + SCSIAllocInstance( machine, SCSI_DEVICE_CDROM, &state->atapi_device_data[1], "scsi1" ); machine->add_notifier(MACHINE_NOTIFY_EXIT, atapi_exit); } -static void atapi_reset(void) +static void atapi_reset(running_machine *machine) { + firebeat_state *state = machine->driver_data(); logerror("ATAPI reset\n"); - atapi_regs[ATAPI_REG_CMDSTATUS] = 0; - atapi_regs[ATAPI_REG_ERRFEAT] = 1; - atapi_regs[ATAPI_REG_COUNTLOW] = 0x14; - atapi_regs[ATAPI_REG_COUNTHIGH] = 0xeb; + state->atapi_regs[ATAPI_REG_CMDSTATUS] = 0; + state->atapi_regs[ATAPI_REG_ERRFEAT] = 1; + state->atapi_regs[ATAPI_REG_COUNTLOW] = 0x14; + state->atapi_regs[ATAPI_REG_COUNTHIGH] = 0xeb; - atapi_data_ptr = 0; - atapi_cdata_wait = 0; + state->atapi_data_ptr = 0; + state->atapi_cdata_wait = 0; } static UINT16 atapi_command_reg_r(running_machine *machine, int reg) { + firebeat_state *state = machine->driver_data(); int i, data; - static UINT8 temp_data[64*1024]; // printf("ATAPI: Command reg read %d\n", reg); if (reg == ATAPI_REG_DATA) { // assert IRQ and drop DRQ - if (atapi_data_ptr == 0) + if (state->atapi_data_ptr == 0) { //printf("ATAPI: dropping DRQ\n"); atapi_cause_irq(machine); - atapi_regs[ATAPI_REG_CMDSTATUS] = 0; + state->atapi_regs[ATAPI_REG_CMDSTATUS] = 0; // get the data from the device - SCSIReadData( atapi_device_data[atapi_drivesel], temp_data, atapi_xferlen ); + SCSIReadData( state->atapi_device_data[state->atapi_drivesel], state->temp_data, state->atapi_xferlen ); // fix it up in an endian-safe way - for (i = 0; i < atapi_xferlen; i += 2) + for (i = 0; i < state->atapi_xferlen; i += 2) { - atapi_data[i/2] = temp_data[i+0] | temp_data[i+1]<<8; + state->atapi_data[i/2] = state->temp_data[i+0] | state->temp_data[i+1]<<8; } } - data = atapi_data[atapi_data_ptr]; -// printf("ATAPI: %d, packet read = %04x\n", atapi_data_ptr, atapi_data[atapi_data_ptr]); - atapi_data_ptr++; + data = state->atapi_data[state->atapi_data_ptr]; +// printf("ATAPI: %d, packet read = %04x\n", state->atapi_data_ptr, state->atapi_data[state->atapi_data_ptr]); + state->atapi_data_ptr++; - if (atapi_xfermod && atapi_data_ptr == (atapi_xferlen/2)) + if (state->atapi_xfermod && state->atapi_data_ptr == (state->atapi_xferlen/2)) { //printf("ATAPI: DRQ interrupt\n"); atapi_cause_irq(machine); - atapi_regs[ATAPI_REG_CMDSTATUS] |= ATAPI_STAT_DRQ; - atapi_data_ptr = 0; + state->atapi_regs[ATAPI_REG_CMDSTATUS] |= ATAPI_STAT_DRQ; + state->atapi_data_ptr = 0; - if (atapi_xfermod > 63488) + if (state->atapi_xfermod > 63488) { - atapi_xfermod = atapi_xfermod - 63488; - atapi_xferlen = 63488; + state->atapi_xfermod = state->atapi_xfermod - 63488; + state->atapi_xferlen = 63488; } else { - atapi_xferlen = atapi_xfermod; - atapi_xfermod = 0; + state->atapi_xferlen = state->atapi_xfermod; + state->atapi_xfermod = 0; } - //printf("ATAPI Transfer: %d, %d, %d\n", atapi_transfer_length, atapi_xfermod, atapi_xferlen); + //printf("ATAPI Transfer: %d, %d, %d\n", atapi_transfer_length, state->atapi_xfermod, state->atapi_xferlen); - atapi_regs[ATAPI_REG_COUNTLOW] = atapi_xferlen & 0xff; - atapi_regs[ATAPI_REG_COUNTHIGH] = (atapi_xferlen>>8)&0xff; + state->atapi_regs[ATAPI_REG_COUNTLOW] = state->atapi_xferlen & 0xff; + state->atapi_regs[ATAPI_REG_COUNTHIGH] = (state->atapi_xferlen>>8)&0xff; } return data; } @@ -965,51 +1014,52 @@ static UINT16 atapi_command_reg_r(running_machine *machine, int reg) { if (reg == ATAPI_REG_CMDSTATUS) atapi_clear_irq(machine); - return atapi_regs[reg]; + return state->atapi_regs[reg]; } } static void atapi_command_reg_w(running_machine *machine, int reg, UINT16 data) { + firebeat_state *state = machine->driver_data(); int i; if (reg == ATAPI_REG_DATA) { // printf("%s:ATAPI: packet write %04x\n", device->machine->describe_context(), data); - atapi_data[atapi_data_ptr] = data; - atapi_data_ptr++; + state->atapi_data[state->atapi_data_ptr] = data; + state->atapi_data_ptr++; - if (atapi_cdata_wait) + if (state->atapi_cdata_wait) { -// printf("ATAPI: waiting, ptr %d wait %d\n", atapi_data_ptr, atapi_cdata_wait); - if (atapi_data_ptr == atapi_cdata_wait) +// printf("ATAPI: waiting, ptr %d wait %d\n", state->atapi_data_ptr, state->atapi_cdata_wait); + if (state->atapi_data_ptr == state->atapi_cdata_wait) { // decompose SCSI packet into proper byte order - for (i = 0; i < atapi_cdata_wait; i += 2) + for (i = 0; i < state->atapi_cdata_wait; i += 2) { - atapi_scsi_packet[i] = atapi_data[i/2]&0xff; - atapi_scsi_packet[i+1] = atapi_data[i/2]>>8; + state->atapi_scsi_packet[i] = state->atapi_data[i/2]&0xff; + state->atapi_scsi_packet[i+1] = state->atapi_data[i/2]>>8; } // send it to the device - SCSIWriteData( atapi_device_data[atapi_drivesel], atapi_scsi_packet, atapi_cdata_wait ); + SCSIWriteData( state->atapi_device_data[state->atapi_drivesel], state->atapi_scsi_packet, state->atapi_cdata_wait ); // assert IRQ atapi_cause_irq(machine); // not sure here, but clear DRQ at least? - atapi_regs[ATAPI_REG_CMDSTATUS] = 0; + state->atapi_regs[ATAPI_REG_CMDSTATUS] = 0; } } - if ((!atapi_cdata_wait) && (atapi_data_ptr == 6)) + if ((!state->atapi_cdata_wait) && (state->atapi_data_ptr == 6)) { int phase; // reset data pointer for reading SCSI results - atapi_data_ptr = 0; + state->atapi_data_ptr = 0; - atapi_regs[ATAPI_REG_CMDSTATUS] |= ATAPI_STAT_BSY; + state->atapi_regs[ATAPI_REG_CMDSTATUS] |= ATAPI_STAT_BSY; // assert IRQ atapi_cause_irq(machine); @@ -1017,50 +1067,50 @@ static void atapi_command_reg_w(running_machine *machine, int reg, UINT16 data) // decompose SCSI packet into proper byte order for (i = 0; i < 16; i += 2) { - atapi_scsi_packet[i+0] = atapi_data[i/2]&0xff; - atapi_scsi_packet[i+1] = atapi_data[i/2]>>8; + state->atapi_scsi_packet[i+0] = state->atapi_data[i/2]&0xff; + state->atapi_scsi_packet[i+1] = state->atapi_data[i/2]>>8; } // send it to the SCSI device - SCSISetCommand( atapi_device_data[atapi_drivesel], atapi_scsi_packet, 12 ); - SCSIExecCommand( atapi_device_data[atapi_drivesel], &atapi_xferlen ); - SCSIGetPhase( atapi_device_data[atapi_drivesel], &phase ); + SCSISetCommand( state->atapi_device_data[state->atapi_drivesel], state->atapi_scsi_packet, 12 ); + SCSIExecCommand( state->atapi_device_data[state->atapi_drivesel], &state->atapi_xferlen ); + SCSIGetPhase( state->atapi_device_data[state->atapi_drivesel], &phase ); - if (atapi_xferlen != -1) + if (state->atapi_xferlen != -1) { - logerror("ATAPI: SCSI command %02x returned %d bytes from the device\n", atapi_data[0]&0xff, atapi_xferlen); + logerror("ATAPI: SCSI command %02x returned %d bytes from the device\n", state->atapi_data[0]&0xff, state->atapi_xferlen); // store the returned command length in the ATAPI regs, splitting into // multiple transfers if necessary - atapi_xfermod = 0; - if (atapi_xferlen > 63488) + state->atapi_xfermod = 0; + if (state->atapi_xferlen > 63488) { - atapi_xfermod = atapi_xferlen - 63488; - atapi_xferlen = 63488; + state->atapi_xfermod = state->atapi_xferlen - 63488; + state->atapi_xferlen = 63488; } -// printf("ATAPI Transfer: %d, %d\n", atapi_xfermod, atapi_xferlen); +// printf("ATAPI Transfer: %d, %d\n", state->atapi_xfermod, state->atapi_xferlen); - atapi_regs[ATAPI_REG_COUNTLOW] = atapi_xferlen & 0xff; - atapi_regs[ATAPI_REG_COUNTHIGH] = (atapi_xferlen>>8)&0xff; + state->atapi_regs[ATAPI_REG_COUNTLOW] = state->atapi_xferlen & 0xff; + state->atapi_regs[ATAPI_REG_COUNTHIGH] = (state->atapi_xferlen>>8)&0xff; switch( phase ) { case SCSI_PHASE_DATAOUT: - atapi_data_ptr = 0; - atapi_cdata_wait = atapi_xferlen; - logerror("ATAPI: Waiting for %x bytes of data\n", atapi_cdata_wait); + state->atapi_data_ptr = 0; + state->atapi_cdata_wait = state->atapi_xferlen; + logerror("ATAPI: Waiting for %x bytes of data\n", state->atapi_cdata_wait); break; } // perform special ATAPI processing of certain commands - switch (atapi_data[0]&0xff) + switch (state->atapi_data[0]&0xff) { case 0xa8: // READ (12) // indicate data ready: set DRQ and DMA ready, and IO in INTREASON - atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_DRQ | ATAPI_STAT_SERVDSC; - atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_IO; + state->atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_DRQ | ATAPI_STAT_SERVDSC; + state->atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_IO; fatalerror("ATAPI: DMA read command attempted\n"); break; @@ -1070,7 +1120,7 @@ static void atapi_command_reg_w(running_machine *machine, int reg, UINT16 data) case 0xa5: // PLAY AUDIO case 0x1b: case 0x4e: - atapi_regs[ATAPI_REG_CMDSTATUS] = 0; + state->atapi_regs[ATAPI_REG_CMDSTATUS] = 0; break; } } @@ -1078,23 +1128,23 @@ static void atapi_command_reg_w(running_machine *machine, int reg, UINT16 data) { // printf("ATAPI: SCSI device returned error!\n"); - atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_DRQ | ATAPI_STAT_CHECK; - atapi_regs[ATAPI_REG_ERRFEAT] = 0x50; // sense key = ILLEGAL REQUEST - atapi_regs[ATAPI_REG_COUNTLOW] = 0; - atapi_regs[ATAPI_REG_COUNTHIGH] = 0; + state->atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_DRQ | ATAPI_STAT_CHECK; + state->atapi_regs[ATAPI_REG_ERRFEAT] = 0x50; // sense key = ILLEGAL REQUEST + state->atapi_regs[ATAPI_REG_COUNTLOW] = 0; + state->atapi_regs[ATAPI_REG_COUNTHIGH] = 0; } } } else { data &= 0xff; - atapi_regs[reg] = data; + state->atapi_regs[reg] = data; // printf("ATAPI: Command reg %d = %02X\n", reg, data); switch(reg) { case ATAPI_REG_DRIVESEL: - atapi_drivesel = (data >> 4) & 0x1; + state->atapi_drivesel = (data >> 4) & 0x1; break; case ATAPI_REG_CMDSTATUS: @@ -1106,15 +1156,15 @@ static void atapi_command_reg_w(running_machine *machine, int reg, UINT16 data) break; case 0x08: /* ATAPI Soft Reset */ - atapi_reset(); + atapi_reset(machine); break; case 0xa0: /* ATAPI Packet */ - atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_BSY | ATAPI_STAT_DRQ; - atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_COMMAND; + state->atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_BSY | ATAPI_STAT_DRQ; + state->atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_COMMAND; - atapi_data_ptr = 0; - atapi_cdata_wait = 0; + state->atapi_data_ptr = 0; + state->atapi_cdata_wait = 0; break; default: @@ -1125,17 +1175,18 @@ static void atapi_command_reg_w(running_machine *machine, int reg, UINT16 data) } } -static UINT16 atapi_control_reg_r(int reg) +static UINT16 atapi_control_reg_r(running_machine *machine, int reg) { + firebeat_state *state = machine->driver_data(); UINT16 value; switch(reg) { case 0x6: { - value = atapi_regs[ATAPI_REG_CMDSTATUS]; - if (atapi_regs[ATAPI_REG_CMDSTATUS] & ATAPI_STAT_BSY) + value = state->atapi_regs[ATAPI_REG_CMDSTATUS]; + if (state->atapi_regs[ATAPI_REG_CMDSTATUS] & ATAPI_STAT_BSY) { - atapi_regs[ATAPI_REG_CMDSTATUS] ^= ATAPI_STAT_BSY; + state->atapi_regs[ATAPI_REG_CMDSTATUS] ^= ATAPI_STAT_BSY; } return value; } @@ -1148,7 +1199,7 @@ static UINT16 atapi_control_reg_r(int reg) return 0; } -static void atapi_control_reg_w(int reg, UINT16 data) +static void atapi_control_reg_w(running_machine *machine, int reg, UINT16 data) { switch(reg) { @@ -1156,7 +1207,7 @@ static void atapi_control_reg_w(int reg, UINT16 data) { if (data & 0x4) { - atapi_reset(); + atapi_reset(machine); } break; } @@ -1206,12 +1257,12 @@ static READ32_HANDLER( atapi_control_r ) if (ACCESSING_BITS_16_31) { - r = atapi_control_reg_r(offset*2); + r = atapi_control_reg_r(space->machine, offset*2); return ATAPI_ENDIAN(r) << 16; } else { - r = atapi_control_reg_r((offset*2) + 1); + r = atapi_control_reg_r(space->machine, (offset*2) + 1); return ATAPI_ENDIAN(r) << 0; } } @@ -1220,11 +1271,11 @@ static WRITE32_HANDLER( atapi_control_w ) { if (ACCESSING_BITS_16_31) { - atapi_control_reg_w(offset*2, ATAPI_ENDIAN(data >> 16) & 0xff); + atapi_control_reg_w(space->machine, offset*2, ATAPI_ENDIAN(data >> 16) & 0xff); } else { - atapi_control_reg_w((offset*2) + 1, ATAPI_ENDIAN(data >> 0) & 0xff); + atapi_control_reg_w(space->machine, (offset*2) + 1, ATAPI_ENDIAN(data >> 0) & 0xff); } } @@ -1286,11 +1337,10 @@ static void comm_uart_irq_callback(running_machine *machine, int channel, int va static const int cab_data[2] = { 0x0, 0x8 }; static const int kbm_cab_data[2] = { 0x2, 0x8 }; static const int ppd_cab_data[2] = { 0x1, 0x9 }; -static int cab_data_ptr = 0; -static const int * cur_cab_data; static READ32_HANDLER( cabinet_r ) { + firebeat_state *state = space->machine->driver_data(); UINT32 r = 0; // printf("cabinet_r: %08X, %08X\n", offset, mem_mask); @@ -1299,8 +1349,8 @@ static READ32_HANDLER( cabinet_r ) { case 0: { - r = cur_cab_data[cab_data_ptr & 1] << 28; - cab_data_ptr++; + r = state->cur_cab_data[state->cab_data_ptr & 1] << 28; + state->cab_data_ptr++; return r; } case 2: return 0x00000000; @@ -1348,11 +1398,12 @@ static WRITE32_HANDLER( midi_uart_w ) static void midi_uart_irq_callback(running_machine *machine, int channel, int value) { + firebeat_state *state = machine->driver_data(); if (channel == 0) { - if ((extend_board_irq_enable & 0x02) == 0 && value != CLEAR_LINE) + if ((state->extend_board_irq_enable & 0x02) == 0 && value != CLEAR_LINE) { - extend_board_irq_active |= 0x02; + state->extend_board_irq_active |= 0x02; cputag_set_input_line(machine, "maincpu", INPUT_LINE_IRQ1, ASSERT_LINE); } else @@ -1360,9 +1411,9 @@ static void midi_uart_irq_callback(running_machine *machine, int channel, int va } else { - if ((extend_board_irq_enable & 0x01) == 0 && value != CLEAR_LINE) + if ((state->extend_board_irq_enable & 0x01) == 0 && value != CLEAR_LINE) { - extend_board_irq_active |= 0x01; + state->extend_board_irq_active |= 0x01; cputag_set_input_line(machine, "maincpu", INPUT_LINE_IRQ1, ASSERT_LINE); } else @@ -1370,7 +1421,6 @@ static void midi_uart_irq_callback(running_machine *machine, int channel, int va } } -static int keyboard_state[2] = { 0, 0 }; static const int keyboard_notes[24] = { @@ -1402,6 +1452,7 @@ static const int keyboard_notes[24] = static TIMER_CALLBACK( keyboard_timer_callback ) { + firebeat_state *state = machine->driver_data(); static const int kb_uart_channel[2] = { 1, 0 }; static const char *const keynames[] = { "KEYBOARD_P1", "KEYBOARD_P2" }; int keyboard; @@ -1412,20 +1463,20 @@ static TIMER_CALLBACK( keyboard_timer_callback ) UINT32 kbstate = input_port_read(machine, keynames[keyboard]); int uart_channel = kb_uart_channel[keyboard]; - if (kbstate != keyboard_state[keyboard]) + if (kbstate != state->keyboard_state[keyboard]) { for (i=0; i < 24; i++) { int kbnote = keyboard_notes[i]; - if ((keyboard_state[keyboard] & (1 << i)) != 0 && (kbstate & (1 << i)) == 0) + if ((state->keyboard_state[keyboard] & (1 << i)) != 0 && (kbstate & (1 << i)) == 0) { // key was on, now off -> send Note Off message pc16552d_rx_data(machine, 1, uart_channel, 0x80); pc16552d_rx_data(machine, 1, uart_channel, kbnote); pc16552d_rx_data(machine, 1, uart_channel, 0x7f); } - else if ((keyboard_state[keyboard] & (1 << i)) == 0 && (kbstate & (1 << i)) != 0) + else if ((state->keyboard_state[keyboard] & (1 << i)) == 0 && (kbstate & (1 << i)) != 0) { // key was off, now on -> send Note On message pc16552d_rx_data(machine, 1, uart_channel, 0x90); @@ -1440,7 +1491,7 @@ static TIMER_CALLBACK( keyboard_timer_callback ) pc16552d_rx_data(machine, 1, uart_channel, 0xfe); } - keyboard_state[keyboard] = kbstate; + state->keyboard_state[keyboard] = kbstate; } } @@ -1454,11 +1505,12 @@ static TIMER_CALLBACK( keyboard_timer_callback ) static READ32_HANDLER( extend_board_irq_r) { + firebeat_state *state = space->machine->driver_data(); UINT32 r = 0; if (ACCESSING_BITS_24_31) { - r |= (~extend_board_irq_active) << 24; + r |= (~state->extend_board_irq_active) << 24; } return r; @@ -1466,13 +1518,14 @@ static READ32_HANDLER( extend_board_irq_r) static WRITE32_HANDLER( extend_board_irq_w ) { + firebeat_state *state = space->machine->driver_data(); // printf("extend_board_irq_w: %08X, %08X, %08X\n", data, offset, mem_mask); if (ACCESSING_BITS_24_31) { - extend_board_irq_active &= ~((data >> 24) & 0xff); + state->extend_board_irq_active &= ~((data >> 24) & 0xff); - extend_board_irq_enable = (data >> 24) & 0xff; + state->extend_board_irq_enable = (data >> 24) & 0xff; } } @@ -1616,27 +1669,27 @@ static WRITE32_HANDLER( lamp_output3_ppp_w ) /*****************************************************************************/ -static UINT8 spu_shared_ram[0x400]; static READ32_HANDLER(ppc_spu_share_r) { + firebeat_state *state = space->machine->driver_data(); UINT32 r = 0; if (ACCESSING_BITS_24_31) { - r |= spu_shared_ram[(offset * 4) + 0] << 24; + r |= state->spu_shared_ram[(offset * 4) + 0] << 24; } if (ACCESSING_BITS_16_23) { - r |= spu_shared_ram[(offset * 4) + 1] << 16; + r |= state->spu_shared_ram[(offset * 4) + 1] << 16; } if (ACCESSING_BITS_8_15) { - r |= spu_shared_ram[(offset * 4) + 2] << 8; + r |= state->spu_shared_ram[(offset * 4) + 2] << 8; } if (ACCESSING_BITS_0_7) { - r |= spu_shared_ram[(offset * 4) + 3] << 0; + r |= state->spu_shared_ram[(offset * 4) + 3] << 0; } return r; @@ -1644,33 +1697,36 @@ static READ32_HANDLER(ppc_spu_share_r) static WRITE32_HANDLER(ppc_spu_share_w) { + firebeat_state *state = space->machine->driver_data(); if (ACCESSING_BITS_24_31) { - spu_shared_ram[(offset * 4) + 0] = (data >> 24) & 0xff; + state->spu_shared_ram[(offset * 4) + 0] = (data >> 24) & 0xff; } if (ACCESSING_BITS_16_23) { - spu_shared_ram[(offset * 4) + 1] = (data >> 16) & 0xff; + state->spu_shared_ram[(offset * 4) + 1] = (data >> 16) & 0xff; } if (ACCESSING_BITS_8_15) { - spu_shared_ram[(offset * 4) + 2] = (data >> 8) & 0xff; + state->spu_shared_ram[(offset * 4) + 2] = (data >> 8) & 0xff; } if (ACCESSING_BITS_0_7) { - spu_shared_ram[(offset * 4) + 3] = (data >> 0) & 0xff; + state->spu_shared_ram[(offset * 4) + 3] = (data >> 0) & 0xff; } } #ifdef UNUSED_FUNCTION static READ16_HANDLER(m68k_spu_share_r) { - return spu_shared_ram[offset] << 8; + firebeat_state *state = space->machine->driver_data(); + return state->spu_shared_ram[offset] << 8; } static WRITE16_HANDLER(m68k_spu_share_w) { - spu_shared_ram[offset] = (data >> 8) & 0xff; + firebeat_state *state = space->machine->driver_data(); + state->spu_shared_ram[offset] = (data >> 8) & 0xff; } #endif @@ -1681,22 +1737,22 @@ static READ16_HANDLER(spu_unk_r) /*****************************************************************************/ -static UINT32 *work_ram; static MACHINE_START( firebeat ) { + firebeat_state *state = machine->driver_data(); /* set conservative DRC options */ ppcdrc_set_options(machine->device("maincpu"), PPCDRC_COMPATIBLE_OPTIONS); /* configure fast RAM regions for DRC */ - ppcdrc_add_fastram(machine->device("maincpu"), 0x00000000, 0x01ffffff, FALSE, work_ram); + ppcdrc_add_fastram(machine->device("maincpu"), 0x00000000, 0x01ffffff, FALSE, state->work_ram); - flash[0] = machine->device("flash0"); - flash[1] = machine->device("flash1"); - flash[2] = machine->device("flash2"); + state->flash[0] = machine->device("flash0"); + state->flash[1] = machine->device("flash1"); + state->flash[2] = machine->device("flash2"); } static ADDRESS_MAP_START( firebeat_map, ADDRESS_SPACE_PROGRAM, 32 ) - AM_RANGE(0x00000000, 0x01ffffff) AM_RAM AM_BASE(&work_ram) + AM_RANGE(0x00000000, 0x01ffffff) AM_RAM AM_BASE_MEMBER(firebeat_state, work_ram) AM_RANGE(0x70000000, 0x70000fff) AM_READWRITE(midi_uart_r, midi_uart_w) AM_RANGE(0x70006000, 0x70006003) AM_WRITE(extend_board_irq_w) AM_RANGE(0x70008000, 0x7000800f) AM_READ(keyboard_wheel_r) @@ -1728,13 +1784,14 @@ ADDRESS_MAP_END static READ8_DEVICE_HANDLER( soundram_r ) { + firebeat_state *state = device->machine->driver_data(); if (offset >= 0 && offset < 0x200000) { - return flash[1]->read(offset & 0x1fffff); + return state->flash[1]->read(offset & 0x1fffff); } else if (offset >= 0x200000 && offset < 0x400000) { - return flash[2]->read(offset & 0x1fffff); + return state->flash[2]->read(offset & 0x1fffff); } return 0; } @@ -1897,21 +1954,22 @@ static INTERRUPT_GEN(firebeat_interrupt) static MACHINE_RESET( firebeat ) { + firebeat_state *state = machine->driver_data(); void *cd; int i; UINT8 *sound = machine->region("ymz")->base(); for (i=0; i < 0x200000; i++) { - sound[i] = flash[1]->read(i); - sound[i+0x200000] = flash[2]->read(i); + sound[i] = state->flash[1]->read(i); + sound[i+0x200000] = state->flash[2]->read(i); } - SCSIGetDevice( atapi_device_data[1], &cd ); + SCSIGetDevice( state->atapi_device_data[1], &cd ); cdda_set_cdrom(machine->device("cdda"), cd); } -static MACHINE_CONFIG_START( firebeat, driver_device ) +static MACHINE_CONFIG_START( firebeat, firebeat_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu", PPC403GCX, 66000000) @@ -1955,7 +2013,7 @@ static MACHINE_CONFIG_START( firebeat, driver_device ) MACHINE_CONFIG_END -static MACHINE_CONFIG_START( firebeat2, driver_device ) +static MACHINE_CONFIG_START( firebeat2, firebeat_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu", PPC403GCX, 66000000) @@ -2015,32 +2073,16 @@ MACHINE_CONFIG_END /*****************************************************************************/ /* Security dongle is a Dallas DS1411 RS232 Adapter with a DS1991 Multikey iButton */ -typedef struct -{ - UINT8 identifier[8]; - UINT8 password[8]; - UINT8 data[0x30]; -} IBUTTON_SUBKEY; - -typedef struct -{ - IBUTTON_SUBKEY subkey[3]; -} IBUTTON; - enum { DS1991_STATE_NORMAL, DS1991_STATE_READ_SUBKEY, }; -static IBUTTON ibutton; -static int ibutton_state = DS1991_STATE_NORMAL; -static int ibutton_read_subkey_ptr = 0; -static UINT8 ibutton_subkey_data[0x40]; -static void set_ibutton(UINT8 *data) +static void set_ibutton(firebeat_state *state, UINT8 *data) { int i, j; @@ -2049,28 +2091,29 @@ static void set_ibutton(UINT8 *data) // identifier for (j=0; j < 8; j++) { - ibutton.subkey[i].identifier[j] = *data++; + state->ibutton.subkey[i].identifier[j] = *data++; } // password for (j=0; j < 8; j++) { - ibutton.subkey[i].password[j] = *data++; + state->ibutton.subkey[i].password[j] = *data++; } // data for (j=0; j < 48; j++) { - ibutton.subkey[i].data[j] = *data++; + state->ibutton.subkey[i].data[j] = *data++; } } } -static int ibutton_w(UINT8 data) +static int ibutton_w(running_machine *machine, UINT8 data) { + firebeat_state *state = machine->driver_data(); int r = -1; - switch (ibutton_state) + switch (state->ibutton_state) { case DS1991_STATE_NORMAL: { @@ -2099,14 +2142,14 @@ static int ibutton_w(UINT8 data) case 0x66: // DS1991 Read SubKey { r = 0x66; - ibutton_state = DS1991_STATE_READ_SUBKEY; - ibutton_read_subkey_ptr = 0; + state->ibutton_state = DS1991_STATE_READ_SUBKEY; + state->ibutton_read_subkey_ptr = 0; break; } case 0xcc: // DS1991 skip rom { r = 0xcc; - ibutton_state = DS1991_STATE_NORMAL; + state->ibutton_state = DS1991_STATE_NORMAL; break; } default: @@ -2120,7 +2163,7 @@ static int ibutton_w(UINT8 data) case DS1991_STATE_READ_SUBKEY: { - if (ibutton_read_subkey_ptr == 0) // Read SubKey, 2nd command byte + if (state->ibutton_read_subkey_ptr == 0) // Read SubKey, 2nd command byte { int subkey = (data >> 6) & 0x3; // printf("iButton SubKey %d\n", subkey); @@ -2128,27 +2171,27 @@ static int ibutton_w(UINT8 data) if (subkey < 3) { - memcpy(&ibutton_subkey_data[0], ibutton.subkey[subkey].identifier, 8); - memcpy(&ibutton_subkey_data[8], ibutton.subkey[subkey].password, 8); - memcpy(&ibutton_subkey_data[16], ibutton.subkey[subkey].data, 0x30); + memcpy(&state->ibutton_subkey_data[0], state->ibutton.subkey[subkey].identifier, 8); + memcpy(&state->ibutton_subkey_data[8], state->ibutton.subkey[subkey].password, 8); + memcpy(&state->ibutton_subkey_data[16], state->ibutton.subkey[subkey].data, 0x30); } else { - memset(&ibutton_subkey_data[0], 0, 0x40); + memset(&state->ibutton_subkey_data[0], 0, 0x40); } } - else if (ibutton_read_subkey_ptr == 1) // Read SubKey, 3rd command byte + else if (state->ibutton_read_subkey_ptr == 1) // Read SubKey, 3rd command byte { r = data; } else { - r = ibutton_subkey_data[ibutton_read_subkey_ptr-2]; + r = state->ibutton_subkey_data[state->ibutton_read_subkey_ptr-2]; } - ibutton_read_subkey_ptr++; - if (ibutton_read_subkey_ptr >= 0x42) + state->ibutton_read_subkey_ptr++; + if (state->ibutton_read_subkey_ptr >= 0x42) { - ibutton_state = DS1991_STATE_NORMAL; + state->ibutton_state = DS1991_STATE_NORMAL; } break; } @@ -2159,7 +2202,7 @@ static int ibutton_w(UINT8 data) static void security_w(device_t *device, UINT8 data) { - int r = ibutton_w(data); + int r = ibutton_w(device->machine, data); if (r >= 0) ppc4xx_spu_receive_byte(device->machine->device("maincpu"), r); } @@ -2179,6 +2222,7 @@ static void init_lights(running_machine *machine, write32_space_func out1, write static void init_firebeat(running_machine *machine) { + firebeat_state *state = machine->driver_data(); UINT8 *rom = machine->region("user2")->base(); atapi_init(machine); @@ -2186,14 +2230,14 @@ static void init_firebeat(running_machine *machine) pc16552d_init(machine, 0, 19660800, comm_uart_irq_callback, 0); // Network UART pc16552d_init(machine, 1, 24000000, midi_uart_irq_callback, 0); // MIDI UART - extend_board_irq_enable = 0x3f; - extend_board_irq_active = 0x00; + state->extend_board_irq_enable = 0x3f; + state->extend_board_irq_active = 0x00; - cur_cab_data = cab_data; + state->cur_cab_data = cab_data; ppc4xx_spu_set_tx_handler(machine->device("maincpu"), security_w); - set_ibutton(rom); + set_ibutton(state, rom); init_lights(machine, NULL, NULL, NULL); } @@ -2206,27 +2250,30 @@ static DRIVER_INIT(ppp) static DRIVER_INIT(ppd) { + firebeat_state *state = machine->driver_data(); init_firebeat(machine); init_lights(machine, lamp_output_ppp_w, lamp_output2_ppp_w, lamp_output3_ppp_w); - cur_cab_data = ppd_cab_data; + state->cur_cab_data = ppd_cab_data; } static void init_keyboard(running_machine *machine) { + firebeat_state *state = machine->driver_data(); // set keyboard timer - keyboard_timer = machine->scheduler().timer_alloc(FUNC(keyboard_timer_callback)); - keyboard_timer->adjust(attotime::from_msec(10), 0, attotime::from_msec(10)); + state->keyboard_timer = machine->scheduler().timer_alloc(FUNC(keyboard_timer_callback)); + state->keyboard_timer->adjust(attotime::from_msec(10), 0, attotime::from_msec(10)); } static DRIVER_INIT(kbm) { + firebeat_state *state = machine->driver_data(); init_firebeat(machine); init_lights(machine, lamp_output_kbm_w, NULL, NULL); init_keyboard(machine); - cur_cab_data = kbm_cab_data; + state->cur_cab_data = kbm_cab_data; } diff --git a/src/mame/drivers/gpworld.c b/src/mame/drivers/gpworld.c index 9495ca01f7f..b0031029358 100644 --- a/src/mame/drivers/gpworld.c +++ b/src/mame/drivers/gpworld.c @@ -43,25 +43,36 @@ Dumping Notes: #include "cpu/z80/z80.h" #include "machine/laserdsc.h" + +class gpworld_state : public driver_device +{ +public: + gpworld_state(running_machine &machine, const driver_device_config_base &config) + : driver_device(machine, config) { } + + UINT8 nmi_enable; + UINT8 start_lamp; + UINT8 ldp_read_latch; + UINT8 ldp_write_latch; + UINT8 brake_gas; + UINT8* tile_RAM; + UINT8* sprite_RAM; + UINT8* palette_RAM; + device_t *laserdisc; +}; + + /* Assumed to be the same as segald hardware */ #define GUESSED_CLOCK (5000000) -static UINT8 nmi_enable; -static UINT8 start_lamp; -static UINT8 ldp_read_latch; -static UINT8 ldp_write_latch; -static UINT8 brake_gas; -static UINT8* tile_RAM; -static UINT8* sprite_RAM; -static UINT8* palette_RAM; -static device_t *laserdisc; /* VIDEO GOODS */ static void gpworld_draw_tiles(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect) { + gpworld_state *state = machine->driver_data(); UINT8 characterX, characterY; /* Temporarily set to 64 wide to accommodate two screens */ @@ -71,7 +82,7 @@ static void gpworld_draw_tiles(running_machine *machine, bitmap_t *bitmap,const { int current_screen_character = (characterY*64) + characterX; - drawgfx_transpen(bitmap, cliprect, machine->gfx[0], tile_RAM[current_screen_character], + drawgfx_transpen(bitmap, cliprect, machine->gfx[0], state->tile_RAM[current_screen_character], characterY, 0, 0, characterX*8, characterY*8, 0); } } @@ -96,6 +107,7 @@ INLINE void draw_pixel(bitmap_t *bitmap,const rectangle *cliprect,int x,int y,in static void gpworld_draw_sprites(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect) { + gpworld_state *state = machine->driver_data(); const int SPR_Y_TOP = 0; const int SPR_Y_BOTTOM = 1; const int SPR_X_LO = 2; @@ -113,7 +125,7 @@ static void gpworld_draw_sprites(running_machine *machine, bitmap_t *bitmap, con /* Heisted from Daphne which heisted it from MAME */ for (i = 0; i < 0x800; i += 8) { - UINT8 *spr_reg = sprite_RAM + i; + UINT8 *spr_reg = state->sprite_RAM + i; if (spr_reg[SPR_Y_BOTTOM] && spr_reg[SPR_X_LO] != 0xff) { @@ -217,7 +229,8 @@ static VIDEO_UPDATE( gpworld ) static MACHINE_START( gpworld ) { - laserdisc = machine->device("laserdisc"); + gpworld_state *state = machine->driver_data(); + state->laserdisc = machine->device("laserdisc"); } @@ -225,12 +238,14 @@ static MACHINE_START( gpworld ) /* READS */ static READ8_HANDLER( ldp_read ) { - return ldp_read_latch; + gpworld_state *state = space->machine->driver_data(); + return state->ldp_read_latch; } static READ8_HANDLER( pedal_in ) { - if (brake_gas) + gpworld_state *state = space->machine->driver_data(); + if (state->brake_gas) return input_port_read(space->machine, "INACCEL"); return input_port_read(space->machine, "INBRAKE"); @@ -240,37 +255,41 @@ static READ8_HANDLER( pedal_in ) /* WRITES */ static WRITE8_HANDLER( ldp_write ) { - ldp_write_latch = data; + gpworld_state *state = space->machine->driver_data(); + state->ldp_write_latch = data; } static WRITE8_HANDLER( misc_io_write ) { - start_lamp = (data & 0x04) >> 1; - nmi_enable = (data & 0x40) >> 6; + gpworld_state *state = space->machine->driver_data(); + state->start_lamp = (data & 0x04) >> 1; + state->nmi_enable = (data & 0x40) >> 6; /* dunno = (data & 0x80) >> 7; */ //coin counter??? - logerror("NMI : %x (0x%x)\n", nmi_enable, data); + logerror("NMI : %x (0x%x)\n", state->nmi_enable, data); } static WRITE8_HANDLER( brake_gas_write ) { - brake_gas = data & 0x01; + gpworld_state *state = space->machine->driver_data(); + state->brake_gas = data & 0x01; } static WRITE8_HANDLER( palette_write ) { + gpworld_state *state = space->machine->driver_data(); /* This is all just a (bad) guess */ int pal_index, r, g, b, a; - palette_RAM[offset] = data; + state->palette_RAM[offset] = data; /* "Round down" to the nearest palette entry */ pal_index = offset & 0xffe; - g = (palette_RAM[pal_index] & 0xf0) << 0; - b = (palette_RAM[pal_index] & 0x0f) << 4; - r = (palette_RAM[pal_index+1] & 0x0f) << 4; - a = (palette_RAM[pal_index+1] & 0x80) ? 0 : 255; /* guess */ + g = (state->palette_RAM[pal_index] & 0xf0) << 0; + b = (state->palette_RAM[pal_index] & 0x0f) << 4; + r = (state->palette_RAM[pal_index+1] & 0x0f) << 4; + a = (state->palette_RAM[pal_index+1] & 0x80) ? 0 : 255; /* guess */ /* logerror("PAL WRITE index : %x rgb : %d %d %d (real %x) at %x\n", pal_index, r,g,b, data, offset); */ @@ -280,9 +299,9 @@ static WRITE8_HANDLER( palette_write ) /* PROGRAM MAP */ static ADDRESS_MAP_START( mainmem, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x0000,0xbfff) AM_ROM - AM_RANGE(0xc000,0xc7ff) AM_RAM AM_BASE(&sprite_RAM) - AM_RANGE(0xc800,0xcfff) AM_WRITE(palette_write) AM_BASE(&palette_RAM) /* The memory test reads at 0xc800 */ - AM_RANGE(0xd000,0xd7ff) AM_RAM AM_BASE(&tile_RAM) + AM_RANGE(0xc000,0xc7ff) AM_RAM AM_BASE_MEMBER(gpworld_state, sprite_RAM) + AM_RANGE(0xc800,0xcfff) AM_WRITE(palette_write) AM_BASE_MEMBER(gpworld_state, palette_RAM) /* The memory test reads at 0xc800 */ + AM_RANGE(0xd000,0xd7ff) AM_RAM AM_BASE_MEMBER(gpworld_state, tile_RAM) AM_RANGE(0xd800,0xd800) AM_READWRITE(ldp_read,ldp_write) /* AM_RANGE(0xd801,0xd801) AM_READ(???) */ AM_RANGE(0xda00,0xda00) AM_READ_PORT("INWHEEL") //8255 here.... @@ -412,11 +431,12 @@ static TIMER_CALLBACK( irq_stop ) static INTERRUPT_GEN( vblank_callback_gpworld ) { + gpworld_state *state = device->machine->driver_data(); /* Do an NMI if the enabled bit is set */ - if (nmi_enable) + if (state->nmi_enable) { - laserdisc_data_w(laserdisc,ldp_write_latch); - ldp_read_latch = laserdisc_data_r(laserdisc); + laserdisc_data_w(state->laserdisc,state->ldp_write_latch); + state->ldp_read_latch = laserdisc_data_r(state->laserdisc); cpu_set_input_line(device, INPUT_LINE_NMI, PULSE_LINE); } @@ -441,7 +461,7 @@ static GFXDECODE_START( gpworld ) GFXDECODE_END /* DRIVER */ -static MACHINE_CONFIG_START( gpworld, driver_device ) +static MACHINE_CONFIG_START( gpworld, gpworld_state ) /* main cpu */ MCFG_CPU_ADD("maincpu", Z80, GUESSED_CLOCK) @@ -507,10 +527,11 @@ ROM_END static DRIVER_INIT( gpworld ) { - nmi_enable = 0; - start_lamp = 0; - brake_gas = 0; - ldp_write_latch = ldp_read_latch = 0; + gpworld_state *state = machine->driver_data(); + state->nmi_enable = 0; + state->start_lamp = 0; + state->brake_gas = 0; + state->ldp_write_latch = state->ldp_read_latch = 0; } diff --git a/src/mame/drivers/gticlub.c b/src/mame/drivers/gticlub.c index 7f9525c047e..eccad474d9a 100644 --- a/src/mame/drivers/gticlub.c +++ b/src/mame/drivers/gticlub.c @@ -237,9 +237,6 @@ Hang Pilot (uses an unknown but similar video board) 12W static UINT32 *work_ram; -UINT8 gticlub_led_reg0; -UINT8 gticlub_led_reg1; - static WRITE32_HANDLER( paletteram32_w ) { @@ -258,39 +255,6 @@ static void voodoo_vblank_1(device_t *device, int param) cputag_set_input_line(device->machine, "maincpu", INPUT_LINE_IRQ1, param ? ASSERT_LINE : CLEAR_LINE); } -static VIDEO_UPDATE( hangplt ) -{ - bitmap_fill(bitmap, cliprect, screen->machine->pens[0]); - - if (strcmp(screen->tag(), "lscreen") == 0) - { - device_t *k001604 = screen->machine->device("k001604_1"); - device_t *voodoo = screen->machine->device("voodoo0"); - - // k001604_draw_back_layer(k001604, bitmap, cliprect); - - voodoo_update(voodoo, bitmap, cliprect); - - k001604_draw_front_layer(k001604, bitmap, cliprect); - } - else if (strcmp(screen->tag(), "rscreen") == 0) - { - device_t *k001604 = screen->machine->device("k001604_2"); - device_t *voodoo = screen->machine->device("voodoo1"); - - // k001604_draw_back_layer(k001604, bitmap, cliprect); - - voodoo_update(voodoo, bitmap, cliprect); - - k001604_draw_front_layer(k001604, bitmap, cliprect); - } - - draw_7segment_led(bitmap, 3, 3, gticlub_led_reg0); - draw_7segment_led(bitmap, 9, 3, gticlub_led_reg1); - - return 0; -} - static READ32_HANDLER( gticlub_k001604_tile_r ) { device_t *k001604 = space->machine->device(get_cgboard_id() ? "k001604_2" : "k001604_1"); @@ -389,11 +353,8 @@ static WRITE8_HANDLER( sysreg_w ) switch (offset) { case 0: - gticlub_led_reg0 = data; - break; - case 1: - gticlub_led_reg1 = data; + gticlub_led_setreg(offset, data); break; case 3: @@ -1182,7 +1143,6 @@ static DRIVER_INIT(gticlub) init_konami_cgboard(machine, 1, CGBOARD_TYPE_GTICLUB); sharc_dataram_0 = auto_alloc_array(machine, UINT32, 0x100000/4); - gticlub_led_reg0 = gticlub_led_reg1 = 0x7f; K001005_preprocess_texture_data(machine->region("gfx1")->base(), machine->region("gfx1")->bytes(), 1); } @@ -1195,7 +1155,6 @@ static DRIVER_INIT(hangplt) sharc_dataram_0 = auto_alloc_array(machine, UINT32, 0x100000/4); sharc_dataram_1 = auto_alloc_array(machine, UINT32, 0x100000/4); - gticlub_led_reg0 = gticlub_led_reg1 = 0x7f; } /*************************************************************************/ diff --git a/src/mame/drivers/hexion.c b/src/mame/drivers/hexion.c index 857efeb8587..8a15cf5ff78 100644 --- a/src/mame/drivers/hexion.c +++ b/src/mame/drivers/hexion.c @@ -218,7 +218,7 @@ static INTERRUPT_GEN( hexion_interrupt ) cpu_set_input_line(device, 0, HOLD_LINE); } -static MACHINE_CONFIG_START( hexion, driver_device ) +static MACHINE_CONFIG_START( hexion, hexion_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu", Z80,24000000/4) /* Z80B 6 MHz */ diff --git a/src/mame/drivers/hornet.c b/src/mame/drivers/hornet.c index 55a29cdc88c..95c8068f185 100644 --- a/src/mame/drivers/hornet.c +++ b/src/mame/drivers/hornet.c @@ -322,13 +322,27 @@ #include "video/konicdev.h" #include "rendlay.h" -static UINT8 led_reg0, led_reg1; -static UINT32 *workram; -static UINT32 *sharc_dataram[2]; -static UINT8 *jvs_sdata; -static UINT32 jvs_sdata_ptr = 0; -static emu_timer *sound_irq_timer; +class hornet_state : public driver_device +{ +public: + hornet_state(running_machine &machine, const driver_device_config_base &config) + : driver_device(machine, config) { } + + UINT8 led_reg0; + UINT8 led_reg1; + UINT32 *workram; + UINT32 *sharc_dataram[2]; + UINT8 *jvs_sdata; + UINT32 jvs_sdata_ptr; + emu_timer *sound_irq_timer; + UINT16 gn680_latch; + UINT16 gn680_ret0; + UINT16 gn680_ret1; +}; + + + static READ32_HANDLER( hornet_k037122_sram_r ) { @@ -379,6 +393,7 @@ static void voodoo_vblank_1(device_t *device, int param) static VIDEO_UPDATE( hornet ) { + hornet_state *state = screen->machine->driver_data(); device_t *voodoo = screen->machine->device("voodoo0"); device_t *k037122 = screen->machine->device("k037122_1"); @@ -386,13 +401,14 @@ static VIDEO_UPDATE( hornet ) k037122_tile_draw(k037122, bitmap, cliprect); - draw_7segment_led(bitmap, 3, 3, led_reg0); - draw_7segment_led(bitmap, 9, 3, led_reg1); + draw_7segment_led(bitmap, 3, 3, state->led_reg0); + draw_7segment_led(bitmap, 9, 3, state->led_reg1); return 0; } static VIDEO_UPDATE( hornet_2board ) { + hornet_state *state = screen->machine->driver_data(); if (strcmp(screen->tag(), "lscreen") == 0) { device_t *k037122 = screen->machine->device("k037122_1"); @@ -412,8 +428,8 @@ static VIDEO_UPDATE( hornet_2board ) k037122_tile_draw(k037122, bitmap, cliprect); } - draw_7segment_led(bitmap, 3, 3, led_reg0); - draw_7segment_led(bitmap, 9, 3, led_reg1); + draw_7segment_led(bitmap, 3, 3, state->led_reg0); + draw_7segment_led(bitmap, 9, 3, state->led_reg1); return 0; } @@ -457,16 +473,17 @@ static READ8_HANDLER( sysreg_r ) static WRITE8_HANDLER( sysreg_w ) { + hornet_state *state = space->machine->driver_data(); device_t *adc12138 = space->machine->device("adc12138"); switch (offset) { case 0: /* LED Register 0 */ - led_reg0 = data; + state->led_reg0 = data; break; case 1: /* LED Register 1 */ - led_reg1 = data; + state->led_reg1 = data; break; case 2: /* Parallel data register */ @@ -568,18 +585,19 @@ static READ32_HANDLER( comm0_unk_r ) return 0xffffffff; } -static UINT16 gn680_latch, gn680_ret0, gn680_ret1; static READ32_HANDLER(gun_r) { - return gn680_ret0<<16 | gn680_ret1; + hornet_state *state = space->machine->driver_data(); + return state->gn680_ret0<<16 | state->gn680_ret1; } static WRITE32_HANDLER(gun_w) { + hornet_state *state = space->machine->driver_data(); if (mem_mask == 0xffff0000) { - gn680_latch = data>>16; + state->gn680_latch = data>>16; cputag_set_input_line(space->machine, "gn680", M68K_IRQ_6, HOLD_LINE); } } @@ -587,7 +605,7 @@ static WRITE32_HANDLER(gun_w) /*****************************************************************************/ static ADDRESS_MAP_START( hornet_map, ADDRESS_SPACE_PROGRAM, 32 ) - AM_RANGE(0x00000000, 0x003fffff) AM_RAM AM_BASE(&workram) /* Work RAM */ + AM_RANGE(0x00000000, 0x003fffff) AM_RAM AM_BASE_MEMBER(hornet_state, workram) /* Work RAM */ AM_RANGE(0x74000000, 0x740000ff) AM_READWRITE(hornet_k037122_reg_r, hornet_k037122_reg_w) AM_RANGE(0x74020000, 0x7403ffff) AM_READWRITE(hornet_k037122_sram_r, hornet_k037122_sram_w) AM_RANGE(0x74040000, 0x7407ffff) AM_READWRITE(hornet_k037122_char_r, hornet_k037122_char_w) @@ -631,20 +649,22 @@ static WRITE16_HANDLER(gn680_sysctrl) static READ16_HANDLER(gn680_latch_r) { + hornet_state *state = space->machine->driver_data(); cputag_set_input_line(space->machine, "gn680", M68K_IRQ_6, CLEAR_LINE); - return gn680_latch; + return state->gn680_latch; } static WRITE16_HANDLER(gn680_latch_w) { + hornet_state *state = space->machine->driver_data(); if (offset) { - gn680_ret1 = data; + state->gn680_ret1 = data; } else { - gn680_ret0 = data; + state->gn680_ret0 = data; } } @@ -664,27 +684,31 @@ ADDRESS_MAP_END static READ32_HANDLER( dsp_dataram0_r ) { - return sharc_dataram[0][offset] & 0xffff; + hornet_state *state = space->machine->driver_data(); + return state->sharc_dataram[0][offset] & 0xffff; } static WRITE32_HANDLER( dsp_dataram0_w ) { - sharc_dataram[0][offset] = data; + hornet_state *state = space->machine->driver_data(); + state->sharc_dataram[0][offset] = data; } static READ32_HANDLER( dsp_dataram1_r ) { - return sharc_dataram[1][offset] & 0xffff; + hornet_state *state = space->machine->driver_data(); + return state->sharc_dataram[1][offset] & 0xffff; } static WRITE32_HANDLER( dsp_dataram1_w ) { - sharc_dataram[1][offset] = data; + hornet_state *state = space->machine->driver_data(); + state->sharc_dataram[1][offset] = data; } static ADDRESS_MAP_START( sharc0_map, ADDRESS_SPACE_DATA, 32 ) AM_RANGE(0x0400000, 0x041ffff) AM_READWRITE(cgboard_0_shared_sharc_r, cgboard_0_shared_sharc_w) - AM_RANGE(0x0500000, 0x05fffff) AM_READWRITE(dsp_dataram0_r, dsp_dataram0_w) AM_BASE(&sharc_dataram[0]) + AM_RANGE(0x0500000, 0x05fffff) AM_READWRITE(dsp_dataram0_r, dsp_dataram0_w) AM_BASE_MEMBER(hornet_state, sharc_dataram[0]) AM_RANGE(0x1400000, 0x14fffff) AM_RAM AM_RANGE(0x2400000, 0x27fffff) AM_DEVREADWRITE("voodoo0", voodoo_r, voodoo_w) AM_RANGE(0x3400000, 0x34000ff) AM_READWRITE(cgboard_0_comm_sharc_r, cgboard_0_comm_sharc_w) @@ -694,7 +718,7 @@ ADDRESS_MAP_END static ADDRESS_MAP_START( sharc1_map, ADDRESS_SPACE_DATA, 32 ) AM_RANGE(0x0400000, 0x041ffff) AM_READWRITE(cgboard_1_shared_sharc_r, cgboard_1_shared_sharc_w) - AM_RANGE(0x0500000, 0x05fffff) AM_READWRITE(dsp_dataram1_r, dsp_dataram1_w) AM_BASE(&sharc_dataram[1]) + AM_RANGE(0x0500000, 0x05fffff) AM_READWRITE(dsp_dataram1_r, dsp_dataram1_w) AM_BASE_MEMBER(hornet_state, sharc_dataram[1]) AM_RANGE(0x1400000, 0x14fffff) AM_RAM AM_RANGE(0x2400000, 0x27fffff) AM_DEVREADWRITE("voodoo1", voodoo_r, voodoo_w) AM_RANGE(0x3400000, 0x34000ff) AM_READWRITE(cgboard_1_comm_sharc_r, cgboard_1_comm_sharc_w) @@ -834,21 +858,22 @@ static TIMER_CALLBACK( irq_off ); static MACHINE_START( hornet ) { - jvs_sdata_ptr = 0; - jvs_sdata = auto_alloc_array_clear(machine, UINT8, 1024); + hornet_state *state = machine->driver_data(); + state->jvs_sdata_ptr = 0; + state->jvs_sdata = auto_alloc_array_clear(machine, UINT8, 1024); /* set conservative DRC options */ ppcdrc_set_options(machine->device("maincpu"), PPCDRC_COMPATIBLE_OPTIONS); /* configure fast RAM regions for DRC */ - ppcdrc_add_fastram(machine->device("maincpu"), 0x00000000, 0x003fffff, FALSE, workram); + ppcdrc_add_fastram(machine->device("maincpu"), 0x00000000, 0x003fffff, FALSE, state->workram); - state_save_register_global(machine, led_reg0); - state_save_register_global(machine, led_reg1); - state_save_register_global_pointer(machine, jvs_sdata, 1024); - state_save_register_global(machine, jvs_sdata_ptr); + state_save_register_global(machine, state->led_reg0); + state_save_register_global(machine, state->led_reg1); + state_save_register_global_pointer(machine, state->jvs_sdata, 1024); + state_save_register_global(machine, state->jvs_sdata_ptr); - sound_irq_timer = machine->scheduler().timer_alloc(FUNC(irq_off)); + state->sound_irq_timer = machine->scheduler().timer_alloc(FUNC(irq_off)); } static MACHINE_RESET( hornet ) @@ -883,10 +908,11 @@ static TIMER_CALLBACK( irq_off ) static void sound_irq_callback( running_machine *machine, int irq ) { + hornet_state *state = machine->driver_data(); int line = (irq == 0) ? INPUT_LINE_IRQ1 : INPUT_LINE_IRQ2; cputag_set_input_line(machine, "audiocpu", line, ASSERT_LINE); - sound_irq_timer->adjust(attotime::from_usec(1), line); + state->sound_irq_timer->adjust(attotime::from_usec(1), line); } static const k056800_interface hornet_k056800_interface = @@ -919,7 +945,7 @@ static const k037122_interface hornet_k037122_intf_r = "rscreen", 1 }; -static MACHINE_CONFIG_START( hornet, driver_device ) +static MACHINE_CONFIG_START( hornet, hornet_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu", PPC403GA, 64000000/2) /* PowerPC 403GA 32MHz */ @@ -1063,12 +1089,13 @@ static void jamma_jvs_cmd_exec(running_machine *machine); static void jamma_jvs_w(device_t *device, UINT8 data) { - if (jvs_sdata_ptr == 0 && data != 0xe0) + hornet_state *state = device->machine->driver_data(); + if (state->jvs_sdata_ptr == 0 && data != 0xe0) return; - jvs_sdata[jvs_sdata_ptr] = data; - jvs_sdata_ptr++; + state->jvs_sdata[state->jvs_sdata_ptr] = data; + state->jvs_sdata_ptr++; - if (jvs_sdata_ptr >= 3 && jvs_sdata_ptr >= 3 + jvs_sdata[2]) + if (state->jvs_sdata_ptr >= 3 && state->jvs_sdata_ptr >= 3 + state->jvs_sdata[2]) jamma_jvs_cmd_exec(device->machine); } @@ -1125,6 +1152,7 @@ static int jvs_decode_data(UINT8 *in, UINT8 *out, int length) static void jamma_jvs_cmd_exec(running_machine *machine) { + hornet_state *state = machine->driver_data(); UINT8 sync, node, byte_num; UINT8 data[1024], rdata[1024]; #if 0 @@ -1133,19 +1161,19 @@ static void jamma_jvs_cmd_exec(running_machine *machine) int rdata_ptr; int sum; - sync = jvs_sdata[0]; - node = jvs_sdata[1]; - byte_num = jvs_sdata[2]; + sync = state->jvs_sdata[0]; + node = state->jvs_sdata[1]; + byte_num = state->jvs_sdata[2]; #if 0 length = #endif - jvs_decode_data(&jvs_sdata[3], data, byte_num-1); + jvs_decode_data(&state->jvs_sdata[3], data, byte_num-1); #if 0 printf("jvs input data:\n"); for (i=0; i < byte_num; i++) { - printf("%02X ", jvs_sdata[3+i]); + printf("%02X ", state->jvs_sdata[3+i]); } printf("\n"); @@ -1194,7 +1222,7 @@ static void jamma_jvs_cmd_exec(running_machine *machine) sum += jvs_encode_data(machine, rdata, rdata_ptr); ppc4xx_spu_receive_byte(machine->device("maincpu"), sum - 1); // checksum - jvs_sdata_ptr = 0; + state->jvs_sdata_ptr = 0; } /*****************************************************************************/ @@ -1202,21 +1230,23 @@ static void jamma_jvs_cmd_exec(running_machine *machine) static DRIVER_INIT(hornet) { + hornet_state *state = machine->driver_data(); init_konami_cgboard(machine, 1, CGBOARD_TYPE_HORNET); set_cgboard_texture_bank(machine, 0, "bank5", machine->region("user5")->base()); - led_reg0 = led_reg1 = 0x7f; + state->led_reg0 = state->led_reg1 = 0x7f; ppc4xx_spu_set_tx_handler(machine->device("maincpu"), jamma_jvs_w); } static DRIVER_INIT(hornet_2board) { + hornet_state *state = machine->driver_data(); init_konami_cgboard(machine, 2, CGBOARD_TYPE_HORNET); set_cgboard_texture_bank(machine, 0, "bank5", machine->region("user5")->base()); set_cgboard_texture_bank(machine, 1, "bank6", machine->region("user5")->base()); - led_reg0 = led_reg1 = 0x7f; + state->led_reg0 = state->led_reg1 = 0x7f; ppc4xx_spu_set_tx_handler(machine->device("maincpu"), jamma_jvs_w); } diff --git a/src/mame/drivers/konamim2.c b/src/mame/drivers/konamim2.c index 0e1778e2e9a..7fe4ce646fe 100644 --- a/src/mame/drivers/konamim2.c +++ b/src/mame/drivers/konamim2.c @@ -190,13 +190,44 @@ Notes: #include "cdrom.h" #include "cpu/powerpc/ppc.h" -static UINT64 *main_ram; -static UINT32 vdl0_address; -static UINT32 vdl1_address; +typedef struct +{ + UINT32 dst_addr; + int length; + UINT32 next_dst_addr; + int next_length; + int dma_done; +} CDE_DMA; + +class konamim2_state : public driver_device +{ +public: + konamim2_state(running_machine &machine, const driver_device_config_base &config) + : driver_device(machine, config) { } + + UINT64 *main_ram; + UINT32 vdl0_address; + UINT32 vdl1_address; + UINT32 irq_enable; + UINT32 irq_active; + UINT64 unk3; + UINT32 unk20004; + int counter1; + int cde_num_status_bytes; + UINT32 cde_status_bytes[16]; + int cde_status_byte_ptr; + UINT32 cde_command_bytes[16]; + int cde_command_byte_ptr; + int cde_response; + int cde_drive_state; + int cde_enable_qchannel_reports; + int cde_enable_seek_reports; + int cde_qchannel_offset; + cdrom_toc cde_toc; + CDE_DMA cde_dma[2]; +}; -static UINT32 irq_enable; -static UINT32 irq_active; static VIDEO_START( m2 ) { @@ -204,17 +235,18 @@ static VIDEO_START( m2 ) static VIDEO_UPDATE( m2 ) { + konamim2_state *state = screen->machine->driver_data(); int i, j; UINT32 fb_start = 0xffffffff; - if (vdl0_address != 0) + if (state->vdl0_address != 0) { - fb_start = *(UINT32*)&main_ram[(vdl0_address - 0x40000000) / 8] - 0x40000000; + fb_start = *(UINT32*)&state->main_ram[(state->vdl0_address - 0x40000000) / 8] - 0x40000000; } if (fb_start <= 0x800000) { - UINT16 *frame = (UINT16*)&main_ram[fb_start/8]; + UINT16 *frame = (UINT16*)&state->main_ram[fb_start/8]; for (j=0; j < 384; j++) { UINT16 *fb = &frame[(j*512)]; @@ -234,11 +266,12 @@ static VIDEO_UPDATE( m2 ) static READ64_HANDLER(irq_enable_r) { + konamim2_state *state = space->machine->driver_data(); UINT64 r = 0; if (ACCESSING_BITS_32_63) { - r |= (UINT64)(irq_enable) << 32; + r |= (UINT64)(state->irq_enable) << 32; } return r; @@ -246,19 +279,21 @@ static READ64_HANDLER(irq_enable_r) static WRITE64_HANDLER(irq_enable_w) { + konamim2_state *state = space->machine->driver_data(); if (ACCESSING_BITS_32_63) { - irq_enable |= (UINT32)(data >> 32); + state->irq_enable |= (UINT32)(data >> 32); } } static READ64_HANDLER(irq_active_r) { + konamim2_state *state = space->machine->driver_data(); UINT64 r = 0; if (ACCESSING_BITS_32_63) { - r |= (UINT64)(irq_active) << 32; + r |= (UINT64)(state->irq_active) << 32; } return r; @@ -283,16 +318,16 @@ static READ64_HANDLER(unk2_r) } #endif -static UINT64 unk3; static READ64_HANDLER(unk3_r) { + konamim2_state *state = space->machine->driver_data(); //return U64(0xffffffffffffffff); - return unk3; + return state->unk3; } -static UINT32 unk20004 = 0; static READ64_HANDLER(unk4_r) { + konamim2_state *state = space->machine->driver_data(); UINT64 r = 0; // logerror("unk4_r: %08X, %08X%08X at %08X\n", offset, (UINT32)(mem_mask>>32), (UINT32)(mem_mask), cpu_get_pc(space->cpu)); @@ -303,13 +338,14 @@ static READ64_HANDLER(unk4_r) } if (ACCESSING_BITS_0_31) { - r |= unk20004 & ~0x800000; + r |= state->unk20004 & ~0x800000; } return r; } static WRITE64_HANDLER(unk4_w) { + konamim2_state *state = space->machine->driver_data(); // logerror("unk4_w: %08X%08X, %08X, %08X%08X at %08X\n", (UINT32)(data >> 32), (UINT32)(data), // offset, (UINT32)(mem_mask>>32), (UINT32)(mem_mask), cpu_get_pc(space->cpu)); @@ -321,16 +357,16 @@ static WRITE64_HANDLER(unk4_w) cputag_set_input_line(space->machine, "sub", INPUT_LINE_IRQ0, ASSERT_LINE); } - unk20004 = (UINT32)(data); + state->unk20004 = (UINT32)(data); return; } } -static int counter1 = 0; static READ64_HANDLER(unk30000_r) { - counter1++; - return (UINT64)(counter1 & 0x7f) << 32; + konamim2_state *state = space->machine->driver_data(); + state->counter1++; + return (UINT64)(state->counter1 & 0x7f) << 32; } static READ64_HANDLER(unk30030_r) @@ -344,23 +380,25 @@ static READ64_HANDLER(unk30030_r) static WRITE64_HANDLER(video_w) { + konamim2_state *state = space->machine->driver_data(); if (ACCESSING_BITS_32_63) { - vdl0_address = (UINT32)(data >> 32); + state->vdl0_address = (UINT32)(data >> 32); } if (ACCESSING_BITS_0_31) { - vdl1_address = (UINT32)(data); + state->vdl1_address = (UINT32)(data); } } static WRITE64_HANDLER(video_irq_ack_w) { + konamim2_state *state = space->machine->driver_data(); if (ACCESSING_BITS_32_63) { if ((data >> 32) & 0x8000) { - irq_active &= ~0x800000; + state->irq_active &= ~0x800000; } } } @@ -409,12 +447,13 @@ static WRITE64_HANDLER(unk4000418_w) static WRITE64_HANDLER(reset_w) { + konamim2_state *state = space->machine->driver_data(); if (ACCESSING_BITS_32_63) { if (data & U64(0x100000000)) { cputag_set_input_line(space->machine, "maincpu", INPUT_LINE_RESET, PULSE_LINE); - unk3 = 0; + state->unk3 = 0; } } } @@ -423,46 +462,26 @@ static WRITE64_HANDLER(reset_w) /*****************************************************************************/ /* CDE */ -typedef struct -{ - UINT32 dst_addr; - int length; - UINT32 next_dst_addr; - int next_length; - int dma_done; -} CDE_DMA; - #define CDE_DRIVE_STATE_PAUSED 0x02 #define CDE_DRIVE_STATE_SEEK_DONE 0x03 -static int cde_num_status_bytes = 0; -static UINT32 cde_status_bytes[16]; -static int cde_status_byte_ptr = 0; -static UINT32 cde_command_bytes[16]; -static int cde_command_byte_ptr = 0; -static int cde_response = 0; -static int cde_drive_state = 0; -static int cde_enable_qchannel_reports = 0; -static int cde_enable_seek_reports = 0; -static int cde_qchannel_offset = 0; -static cdrom_toc cde_toc; -static CDE_DMA cde_dma[2]; static void cde_init(running_machine *machine) { + konamim2_state *state = machine->driver_data(); cdrom_file *cd = cdrom_open(get_disk_handle(machine, "cdrom")); const cdrom_toc *toc = cdrom_get_toc(cd); if (cd) { - memcpy(&cde_toc, toc, sizeof(cdrom_toc)); + memcpy(&state->cde_toc, toc, sizeof(cdrom_toc)); } /* @@ -480,208 +499,210 @@ static void cde_init(running_machine *machine) cdrom_close(cd); } - cde_drive_state = CDE_DRIVE_STATE_PAUSED; + state->cde_drive_state = CDE_DRIVE_STATE_PAUSED; - cde_num_status_bytes = 0; - cde_status_byte_ptr = 0; - cde_command_byte_ptr = 0; + state->cde_num_status_bytes = 0; + state->cde_status_byte_ptr = 0; + state->cde_command_byte_ptr = 0; - cde_response = 0; + state->cde_response = 0; - cde_enable_qchannel_reports = 0; - cde_enable_seek_reports = 0; + state->cde_enable_qchannel_reports = 0; + state->cde_enable_seek_reports = 0; - cde_qchannel_offset = 0; + state->cde_qchannel_offset = 0; } -static void cde_handle_command(void) +static void cde_handle_command(running_machine *machine) { - switch (cde_command_bytes[0]) + konamim2_state *state = machine->driver_data(); + switch (state->cde_command_bytes[0]) { case 0x04: // Set Speed { - cde_num_status_bytes = 1; + state->cde_num_status_bytes = 1; - cde_status_bytes[0] = 0x04; - cde_status_byte_ptr = 0; + state->cde_status_bytes[0] = 0x04; + state->cde_status_byte_ptr = 0; - mame_printf_debug("CDE: SET SPEED %02X, %02X\n", cde_command_bytes[1], cde_command_bytes[2]); + mame_printf_debug("CDE: SET SPEED %02X, %02X\n", state->cde_command_bytes[1], state->cde_command_bytes[2]); break; } case 0x06: // Audio Format / Data Format { - cde_num_status_bytes = 1; + state->cde_num_status_bytes = 1; - cde_status_bytes[0] = 0x06; - cde_status_byte_ptr = 0; + state->cde_status_bytes[0] = 0x06; + state->cde_status_byte_ptr = 0; - if (cde_command_bytes[1] == 0x00) // Audio Format + if (state->cde_command_bytes[1] == 0x00) // Audio Format { mame_printf_debug("CDE: AUDIO FORMAT\n"); } - else if (cde_command_bytes[1] == 0x78) // Data Format + else if (state->cde_command_bytes[1] == 0x78) // Data Format { mame_printf_debug("CDE: DATA FORMAT\n"); } else { - fatalerror("CDE: unknown command %02X, %02X\n", cde_command_bytes[0], cde_command_bytes[1]); + fatalerror("CDE: unknown command %02X, %02X\n", state->cde_command_bytes[0], state->cde_command_bytes[1]); } break; } case 0x08: // Pause / Eject / Play { - cde_num_status_bytes = 1; + state->cde_num_status_bytes = 1; - cde_status_bytes[0] = 0x08; - cde_status_byte_ptr = 0; + state->cde_status_bytes[0] = 0x08; + state->cde_status_byte_ptr = 0; - if (cde_command_bytes[1] == 0x00) // Eject + if (state->cde_command_bytes[1] == 0x00) // Eject { mame_printf_debug("CDE: EJECT command\n"); } - else if (cde_command_bytes[1] == 0x02) // Pause + else if (state->cde_command_bytes[1] == 0x02) // Pause { mame_printf_debug("CDE: PAUSE command\n"); - cde_drive_state = CDE_DRIVE_STATE_PAUSED; + state->cde_drive_state = CDE_DRIVE_STATE_PAUSED; } - else if (cde_command_bytes[1] == 0x03) // Play + else if (state->cde_command_bytes[1] == 0x03) // Play { mame_printf_debug("CDE: PLAY command\n"); } else { - fatalerror("CDE: unknown command %02X, %02X\n", cde_command_bytes[0], cde_command_bytes[1]); + fatalerror("CDE: unknown command %02X, %02X\n", state->cde_command_bytes[0], state->cde_command_bytes[1]); } break; } case 0x09: // Seek { - cde_num_status_bytes = 1; + state->cde_num_status_bytes = 1; - cde_status_bytes[0] = 0x1b; - cde_status_byte_ptr = 0; + state->cde_status_bytes[0] = 0x1b; + state->cde_status_byte_ptr = 0; - cde_drive_state = CDE_DRIVE_STATE_SEEK_DONE; + state->cde_drive_state = CDE_DRIVE_STATE_SEEK_DONE; - mame_printf_debug("CDE: SEEK %08X\n", (cde_command_bytes[1] << 16) | (cde_command_bytes[2] << 8) | (cde_command_bytes[3])); + mame_printf_debug("CDE: SEEK %08X\n", (state->cde_command_bytes[1] << 16) | (state->cde_command_bytes[2] << 8) | (state->cde_command_bytes[3])); break; } case 0x0b: // Get Drive State { - cde_num_status_bytes = 0x3; + state->cde_num_status_bytes = 0x3; - cde_status_bytes[0] = 0x0b; - cde_status_bytes[1] = 0x1b; - cde_status_bytes[2] = cde_drive_state; - cde_status_byte_ptr = 0; + state->cde_status_bytes[0] = 0x0b; + state->cde_status_bytes[1] = 0x1b; + state->cde_status_bytes[2] = state->cde_drive_state; + state->cde_status_byte_ptr = 0; - if (cde_command_bytes[1] & 0x02) + if (state->cde_command_bytes[1] & 0x02) { - cde_enable_seek_reports = 1; + state->cde_enable_seek_reports = 1; } else { - cde_enable_seek_reports = 0; + state->cde_enable_seek_reports = 0; } - mame_printf_debug("CDE: GET DRIVE STATE %02X\n", cde_command_bytes[1]); + mame_printf_debug("CDE: GET DRIVE STATE %02X\n", state->cde_command_bytes[1]); break; } case 0x0c: // ? { - cde_num_status_bytes = 1; + state->cde_num_status_bytes = 1; - cde_status_bytes[0] = 0x0c; - cde_status_byte_ptr = 0; + state->cde_status_bytes[0] = 0x0c; + state->cde_status_byte_ptr = 0; - if (cde_command_bytes[1] == 0x02) + if (state->cde_command_bytes[1] == 0x02) { - cde_enable_qchannel_reports = 1; - cde_drive_state = CDE_DRIVE_STATE_PAUSED; + state->cde_enable_qchannel_reports = 1; + state->cde_drive_state = CDE_DRIVE_STATE_PAUSED; } - else if (cde_command_bytes[0] == 0x00) + else if (state->cde_command_bytes[0] == 0x00) { - cde_enable_qchannel_reports = 0; + state->cde_enable_qchannel_reports = 0; } - mame_printf_debug("CDE: UNKNOWN CMD 0x0c %02X\n", cde_command_bytes[1]); + mame_printf_debug("CDE: UNKNOWN CMD 0x0c %02X\n", state->cde_command_bytes[1]); break; } case 0x0d: // Get Switch State { - cde_num_status_bytes = 0x4; + state->cde_num_status_bytes = 0x4; - cde_status_bytes[0] = 0x0d; - cde_status_bytes[1] = 0x1d; - cde_status_bytes[2] = 0x02; - cde_status_byte_ptr = 0; + state->cde_status_bytes[0] = 0x0d; + state->cde_status_bytes[1] = 0x1d; + state->cde_status_bytes[2] = 0x02; + state->cde_status_byte_ptr = 0; - mame_printf_debug("CDE: GET SWITCH STATE %02X\n", cde_command_bytes[1]); + mame_printf_debug("CDE: GET SWITCH STATE %02X\n", state->cde_command_bytes[1]); break; } case 0x21: // Mech type { - cde_num_status_bytes = 0x8; + state->cde_num_status_bytes = 0x8; - cde_status_bytes[0] = 0x21; - cde_status_bytes[1] = 0xff; - cde_status_bytes[2] = 0x08; // Max Speed - cde_status_bytes[3] = 0xff; - cde_status_bytes[4] = 0xff; - cde_status_bytes[5] = 0xff; - cde_status_bytes[6] = 0xff; - cde_status_bytes[7] = 0xff; + state->cde_status_bytes[0] = 0x21; + state->cde_status_bytes[1] = 0xff; + state->cde_status_bytes[2] = 0x08; // Max Speed + state->cde_status_bytes[3] = 0xff; + state->cde_status_bytes[4] = 0xff; + state->cde_status_bytes[5] = 0xff; + state->cde_status_bytes[6] = 0xff; + state->cde_status_bytes[7] = 0xff; - cde_status_byte_ptr = 0; + state->cde_status_byte_ptr = 0; - mame_printf_debug("CDE: MECH TYPE %02X, %02X, %02X\n", cde_command_bytes[1], cde_command_bytes[2], cde_command_bytes[3]); + mame_printf_debug("CDE: MECH TYPE %02X, %02X, %02X\n", state->cde_command_bytes[1], state->cde_command_bytes[2], state->cde_command_bytes[3]); break; } case 0x83: // Read ID { - cde_num_status_bytes = 0xc; + state->cde_num_status_bytes = 0xc; - cde_status_bytes[0] = 0x03; - cde_status_bytes[1] = 0xff; - cde_status_bytes[2] = 0xff; - cde_status_bytes[3] = 0xff; - cde_status_bytes[4] = 0xff; - cde_status_bytes[5] = 0xff; - cde_status_bytes[6] = 0xff; - cde_status_bytes[7] = 0xff; - cde_status_bytes[8] = 0xff; - cde_status_bytes[9] = 0xff; - cde_status_bytes[10] = 0xff; - cde_status_bytes[11] = 0xff; + state->cde_status_bytes[0] = 0x03; + state->cde_status_bytes[1] = 0xff; + state->cde_status_bytes[2] = 0xff; + state->cde_status_bytes[3] = 0xff; + state->cde_status_bytes[4] = 0xff; + state->cde_status_bytes[5] = 0xff; + state->cde_status_bytes[6] = 0xff; + state->cde_status_bytes[7] = 0xff; + state->cde_status_bytes[8] = 0xff; + state->cde_status_bytes[9] = 0xff; + state->cde_status_bytes[10] = 0xff; + state->cde_status_bytes[11] = 0xff; - cde_status_byte_ptr = 0; + state->cde_status_byte_ptr = 0; mame_printf_debug("CDE: READ ID\n"); break; } default: { - fatalerror("CDE: unknown command %08X\n", cde_command_bytes[0]); + fatalerror("CDE: unknown command %08X\n", state->cde_command_bytes[0]); break; } } } -static void cde_handle_reports(void) +static void cde_handle_reports(running_machine *machine) { - switch (cde_command_bytes[0]) + konamim2_state *state = machine->driver_data(); + switch (state->cde_command_bytes[0]) { case 0x09: { - if (cde_enable_seek_reports) + if (state->cde_enable_seek_reports) { - cde_num_status_bytes = 0x2; - cde_status_bytes[0] = 0x02; + state->cde_num_status_bytes = 0x2; + state->cde_status_bytes[0] = 0x02; - cde_status_byte_ptr = 0; + state->cde_status_byte_ptr = 0; - cde_command_bytes[0] = 0x0c; + state->cde_command_bytes[0] = 0x0c; mame_printf_debug("CDE: SEEK REPORT\n"); } @@ -690,94 +711,94 @@ static void cde_handle_reports(void) case 0x0b: { - if (cde_enable_qchannel_reports) + if (state->cde_enable_qchannel_reports) { int track, num_tracks; - num_tracks = cde_toc.numtrks; - track = cde_qchannel_offset % (num_tracks+3); + num_tracks = state->cde_toc.numtrks; + track = state->cde_qchannel_offset % (num_tracks+3); - cde_num_status_bytes = 0xb; - cde_status_bytes[0] = 0x1c; + state->cde_num_status_bytes = 0xb; + state->cde_status_bytes[0] = 0x1c; /* - cde_status_bytes[1] = 0x0; // q-Mode - cde_status_bytes[2] = 0x0; // TNO - cde_status_bytes[3] = 0x0; // Index / Pointer - cde_status_bytes[4] = 0x0; // Min - cde_status_bytes[5] = 0x0; // Sec - cde_status_bytes[6] = 0x0; // Frac - cde_status_bytes[7] = 0x0; // Zero - cde_status_bytes[8] = 0x0; // A-Min - cde_status_bytes[9] = 0x0; // A-Sec - cde_status_bytes[10] = 0x0; // A-Frac + state->cde_status_bytes[1] = 0x0; // q-Mode + state->cde_status_bytes[2] = 0x0; // TNO + state->cde_status_bytes[3] = 0x0; // Index / Pointer + state->cde_status_bytes[4] = 0x0; // Min + state->cde_status_bytes[5] = 0x0; // Sec + state->cde_status_bytes[6] = 0x0; // Frac + state->cde_status_bytes[7] = 0x0; // Zero + state->cde_status_bytes[8] = 0x0; // A-Min + state->cde_status_bytes[9] = 0x0; // A-Sec + state->cde_status_bytes[10] = 0x0; // A-Frac */ if (track < num_tracks) { - int time = lba_to_msf(cde_toc.tracks[track].physframeofs); + int time = lba_to_msf(state->cde_toc.tracks[track].physframeofs); - cde_status_bytes[1] = 0x41; // q-Mode - cde_status_bytes[2] = 0x0; // TNO (Lead-in track) - cde_status_bytes[3] = track+1; // Pointer - cde_status_bytes[4] = 0x0; // Min - cde_status_bytes[5] = 0x0; // Sec - cde_status_bytes[6] = 0x0; // Frac - cde_status_bytes[7] = 0x0; // Zero - cde_status_bytes[8] = (time >> 16) & 0xff; // P-Min - cde_status_bytes[9] = (time >> 8) & 0xff; // P-Sec - cde_status_bytes[10] = time & 0xff; // P-Frac + state->cde_status_bytes[1] = 0x41; // q-Mode + state->cde_status_bytes[2] = 0x0; // TNO (Lead-in track) + state->cde_status_bytes[3] = track+1; // Pointer + state->cde_status_bytes[4] = 0x0; // Min + state->cde_status_bytes[5] = 0x0; // Sec + state->cde_status_bytes[6] = 0x0; // Frac + state->cde_status_bytes[7] = 0x0; // Zero + state->cde_status_bytes[8] = (time >> 16) & 0xff; // P-Min + state->cde_status_bytes[9] = (time >> 8) & 0xff; // P-Sec + state->cde_status_bytes[10] = time & 0xff; // P-Frac } else { if (track == num_tracks+0) { - cde_status_bytes[1] = 0x41; // q-Mode / Control - cde_status_bytes[2] = 0x0; // TNO (Lead-in track) - cde_status_bytes[3] = 0xa0; // Pointer - cde_status_bytes[4] = 0x0; // Min - cde_status_bytes[5] = 0x0; // Sec - cde_status_bytes[6] = 0x0; // Frac - cde_status_bytes[7] = 0x0; // Zero - cde_status_bytes[8] = 1; // P-Min - cde_status_bytes[9] = 0x0; // P-Sec - cde_status_bytes[10] = 0x0; // P-Frac + state->cde_status_bytes[1] = 0x41; // q-Mode / Control + state->cde_status_bytes[2] = 0x0; // TNO (Lead-in track) + state->cde_status_bytes[3] = 0xa0; // Pointer + state->cde_status_bytes[4] = 0x0; // Min + state->cde_status_bytes[5] = 0x0; // Sec + state->cde_status_bytes[6] = 0x0; // Frac + state->cde_status_bytes[7] = 0x0; // Zero + state->cde_status_bytes[8] = 1; // P-Min + state->cde_status_bytes[9] = 0x0; // P-Sec + state->cde_status_bytes[10] = 0x0; // P-Frac } else if (track == num_tracks+1) { - cde_status_bytes[1] = 0x41; // q-Mode / Control - cde_status_bytes[2] = 0x0; // TNO (Lead-in track) - cde_status_bytes[3] = 0xa1; // Pointer - cde_status_bytes[4] = 0x0; // Min - cde_status_bytes[5] = 0x0; // Sec - cde_status_bytes[6] = 0x0; // Frac - cde_status_bytes[7] = 0x0; // Zero - cde_status_bytes[8] = num_tracks; // P-Min - cde_status_bytes[9] = 0x0; // P-Sec - cde_status_bytes[10] = 0x0; // P-Frac + state->cde_status_bytes[1] = 0x41; // q-Mode / Control + state->cde_status_bytes[2] = 0x0; // TNO (Lead-in track) + state->cde_status_bytes[3] = 0xa1; // Pointer + state->cde_status_bytes[4] = 0x0; // Min + state->cde_status_bytes[5] = 0x0; // Sec + state->cde_status_bytes[6] = 0x0; // Frac + state->cde_status_bytes[7] = 0x0; // Zero + state->cde_status_bytes[8] = num_tracks; // P-Min + state->cde_status_bytes[9] = 0x0; // P-Sec + state->cde_status_bytes[10] = 0x0; // P-Frac } else { - int leadout_lba = cde_toc.tracks[num_tracks-1].physframeofs + cde_toc.tracks[num_tracks-1].frames; + int leadout_lba = state->cde_toc.tracks[num_tracks-1].physframeofs + state->cde_toc.tracks[num_tracks-1].frames; int leadout_time = lba_to_msf(leadout_lba); - cde_status_bytes[1] = 0x41; // q-Mode / Control - cde_status_bytes[2] = 0x0; // TNO (Lead-in track) - cde_status_bytes[3] = 0xa2; // Pointer - cde_status_bytes[4] = 0x0; // Min - cde_status_bytes[5] = 0x0; // Sec - cde_status_bytes[6] = 0x0; // Frac - cde_status_bytes[7] = 0x0; // Zero - cde_status_bytes[8] = (leadout_time >> 16) & 0xff; // P-Min - cde_status_bytes[9] = (leadout_time >> 8) & 0xff; // P-Sec - cde_status_bytes[10] = leadout_time & 0xff; // P-Frac + state->cde_status_bytes[1] = 0x41; // q-Mode / Control + state->cde_status_bytes[2] = 0x0; // TNO (Lead-in track) + state->cde_status_bytes[3] = 0xa2; // Pointer + state->cde_status_bytes[4] = 0x0; // Min + state->cde_status_bytes[5] = 0x0; // Sec + state->cde_status_bytes[6] = 0x0; // Frac + state->cde_status_bytes[7] = 0x0; // Zero + state->cde_status_bytes[8] = (leadout_time >> 16) & 0xff; // P-Min + state->cde_status_bytes[9] = (leadout_time >> 8) & 0xff; // P-Sec + state->cde_status_bytes[10] = leadout_time & 0xff; // P-Frac } } - cde_qchannel_offset++; + state->cde_qchannel_offset++; - cde_status_byte_ptr = 0; - cde_command_bytes[0] = 0x0c; + state->cde_status_byte_ptr = 0; + state->cde_command_bytes[0] = 0x0c; mame_printf_debug("CDE: QCHANNEL REPORT\n"); break; @@ -788,22 +809,23 @@ static void cde_handle_reports(void) static void cde_dma_transfer(address_space *space, int channel, int next) { + konamim2_state *state = space->machine->driver_data(); UINT32 address; //int length; int i; if (next) { - address = cde_dma[channel].next_dst_addr; - //length = cde_dma[channel].next_length; + address = state->cde_dma[channel].next_dst_addr; + //length = state->cde_dma[channel].next_length; } else { - address = cde_dma[channel].dst_addr; - //length = cde_dma[channel].length; + address = state->cde_dma[channel].dst_addr; + //length = state->cde_dma[channel].length; } - for (i=0; i < cde_dma[channel].next_length; i++) + for (i=0; i < state->cde_dma[channel].next_length; i++) { space->write_byte(address, 0xff); // TODO: do the real transfer... address++; @@ -812,6 +834,7 @@ static void cde_dma_transfer(address_space *space, int channel, int next) static READ64_HANDLER(cde_r) { + konamim2_state *state = space->machine->driver_data(); UINT32 r = 0; int reg = offset * 2; @@ -829,36 +852,36 @@ static READ64_HANDLER(cde_r) { r = 0x100038; - r |= cde_dma[0].dma_done ? 0x400 : 0; - r |= cde_dma[1].dma_done ? 0x800 : 0; + r |= state->cde_dma[0].dma_done ? 0x400 : 0; + r |= state->cde_dma[1].dma_done ? 0x800 : 0; break; } case 0x02c/4: { - r = cde_status_bytes[cde_status_byte_ptr++]; + r = state->cde_status_bytes[state->cde_status_byte_ptr++]; - if (cde_status_byte_ptr <= cde_num_status_bytes) + if (state->cde_status_byte_ptr <= state->cde_num_status_bytes) { r |= 0x100; } else { //if (cde_enable_reports && - // !cde_response && - // cde_command_bytes[0] != ((cde_report_type >> 8) & 0xff)) + // !state->cde_response && + // state->cde_command_bytes[0] != ((cde_report_type >> 8) & 0xff)) - if (!cde_response) + if (!state->cde_response) { - cde_handle_reports(); + cde_handle_reports(space->machine); - // cde_command_byte_ptr = 0; - // cde_command_bytes[cde_command_byte_ptr++] = 0x1c; + // state->cde_command_byte_ptr = 0; + // state->cde_command_bytes[state->cde_command_byte_ptr++] = 0x1c; - // cde_response = 1; + // state->cde_response = 1; } } - // printf("status byte %d\n", cde_status_byte_ptr); + // printf("status byte %d\n", state->cde_status_byte_ptr); break; } @@ -887,6 +910,7 @@ static READ64_HANDLER(cde_r) static WRITE64_HANDLER(cde_w) { + konamim2_state *state = space->machine->driver_data(); int reg = offset * 2; UINT32 d; @@ -908,28 +932,28 @@ static WRITE64_HANDLER(cde_w) if (d == 0x0180) { - if (cde_response) + if (state->cde_response) { - cde_handle_command(); + cde_handle_command(space->machine); - cde_response = 0; + state->cde_response = 0; } - cde_command_byte_ptr = 0; + state->cde_command_byte_ptr = 0; } - else if (cde_command_byte_ptr == 0) + else if (state->cde_command_byte_ptr == 0) { - cde_num_status_bytes = 1; + state->cde_num_status_bytes = 1; - cde_status_bytes[0] = d & 0xff; - cde_status_byte_ptr = 0; + state->cde_status_bytes[0] = d & 0xff; + state->cde_status_byte_ptr = 0; - cde_response = 1; + state->cde_response = 1; } if (d != 0x180) { - cde_command_bytes[cde_command_byte_ptr++] = d; + state->cde_command_bytes[state->cde_command_byte_ptr++] = d; } break; @@ -941,13 +965,13 @@ static WRITE64_HANDLER(cde_w) if (d & 0x20) { - cde_dma[0].dma_done = 1; + state->cde_dma[0].dma_done = 1; cde_dma_transfer(space, 0, 0); } if (d & 0x40) { - cde_dma[0].dma_done = 1; + state->cde_dma[0].dma_done = 1; cde_dma_transfer(space, 0, 1); } @@ -957,28 +981,28 @@ static WRITE64_HANDLER(cde_w) { mame_printf_debug("CDE: DMA0 dst addr %08X\n", d); - cde_dma[0].dst_addr = d; + state->cde_dma[0].dst_addr = d; break; } case 0x30c/4: // DMA Channel 0 length? { mame_printf_debug("CDE: DMA0 length %08X\n", d); - cde_dma[0].length = d; + state->cde_dma[0].length = d; break; } case 0x318/4: // DMA Channel 0 next destination address { mame_printf_debug("CDE: DMA0 next dst addr %08X\n", d); - cde_dma[0].next_dst_addr = d; + state->cde_dma[0].next_dst_addr = d; break; } case 0x31c/4: // DMA Channel 0 next length? { mame_printf_debug("CDE: DMA0 next length %08X\n", d); - cde_dma[0].next_length = d; + state->cde_dma[0].next_length = d; break; } @@ -991,28 +1015,28 @@ static WRITE64_HANDLER(cde_w) { mame_printf_debug("CDE: DMA1 dst addr %08X\n", d); - cde_dma[1].dst_addr = d; + state->cde_dma[1].dst_addr = d; break; } case 0x32c/4: // DMA Channel 1 length? { mame_printf_debug("CDE: DMA1 length %08X\n", d); - cde_dma[1].length = d; + state->cde_dma[1].length = d; break; } case 0x338/4: // DMA Channel 1 next destination address { mame_printf_debug("CDE: DMA1 next dst addr %08X\n", d); - cde_dma[1].next_dst_addr = d; + state->cde_dma[1].next_dst_addr = d; break; } case 0x33c/4: // DMA Channel 1 next length? { mame_printf_debug("CDE: DMA1 next length %08X\n", d); - cde_dma[1].next_length = d; + state->cde_dma[1].next_length = d; break; } @@ -1020,12 +1044,12 @@ static WRITE64_HANDLER(cde_w) { if (d & 0x80000000) { - irq_active &= ~0x8; + state->irq_active &= ~0x8; } if (d & 0x60000000) { - cde_dma[0].dma_done = 0; - cde_dma[1].dma_done = 0; + state->cde_dma[0].dma_done = 0; + state->cde_dma[1].dma_done = 0; } break; } @@ -1102,7 +1126,7 @@ static ADDRESS_MAP_START( m2_main, ADDRESS_SPACE_PROGRAM, 64 ) AM_RANGE(0x10000000, 0x10000007) AM_READ(cpu_r) AM_RANGE(0x10000008, 0x10001007) AM_NOP // ??? AM_RANGE(0x20000000, 0x201fffff) AM_ROM AM_SHARE("share2") - AM_RANGE(0x40000000, 0x407fffff) AM_RAM AM_SHARE("share3") AM_BASE(&main_ram) + AM_RANGE(0x40000000, 0x407fffff) AM_RAM AM_SHARE("share3") AM_BASE_MEMBER(konamim2_state, main_ram) AM_RANGE(0xfff00000, 0xffffffff) AM_ROM AM_REGION("boot", 0) AM_SHARE("share2") ADDRESS_MAP_END @@ -1117,20 +1141,21 @@ static const powerpc_config ppc602_config = static INTERRUPT_GEN(m2) { - if (irq_enable & 0x800000) + konamim2_state *state = device->machine->driver_data(); + if (state->irq_enable & 0x800000) { - irq_active |= 0x800000; + state->irq_active |= 0x800000; } - /*if (irq_enable & 0x8) + /*if (state->irq_enable & 0x8) { - irq_active |= 0x8; + state->irq_active |= 0x8; }*/ cpu_set_input_line(device, INPUT_LINE_IRQ0, ASSERT_LINE); } -static MACHINE_CONFIG_START( m2, driver_device ) +static MACHINE_CONFIG_START( m2, konamim2_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu", PPC602, 33000000) /* actually PPC602, 66MHz */ @@ -1257,8 +1282,9 @@ ROM_END static DRIVER_INIT( m2 ) { - unk3 = U64(0xffffffffffffffff); - unk20004 = 0; + konamim2_state *state = machine->driver_data(); + state->unk3 = U64(0xffffffffffffffff); + state->unk20004 = 0; cde_init(machine); } diff --git a/src/mame/drivers/model1.c b/src/mame/drivers/model1.c index 0b501d9802f..988dc50bc6b 100644 --- a/src/mame/drivers/model1.c +++ b/src/mame/drivers/model1.c @@ -627,7 +627,6 @@ Notes: #include "emu.h" #include "cpu/v60/v60.h" #include "deprecat.h" -#include "includes/system16.h" #include "video/segaic24.h" #include "cpu/m68000/m68000.h" #include "cpu/mb86233/mb86233.h" @@ -636,10 +635,7 @@ Notes: #include "machine/nvram.h" #include "includes/model1.h" -static int model1_sound_irq; -#define FIFO_SIZE (8) -static int to_68k[FIFO_SIZE], fifo_wptr, fifo_rptr; static READ16_HANDLER( io_r ) { @@ -683,19 +679,20 @@ static WRITE16_HANDLER( bank_w ) } -static int last_irq; static void irq_raise(running_machine *machine, int level) { + model1_state *state = machine->driver_data(); // logerror("irq: raising %d\n", level); // irq_status |= (1 << level); - last_irq = level; + state->last_irq = level; cputag_set_input_line(machine, "maincpu", 0, HOLD_LINE); } static IRQ_CALLBACK(irq_callback) { - return last_irq; + model1_state *state = device->machine->driver_data(); + return state->last_irq; } // vf // 1 = fe3ed4 @@ -719,16 +716,17 @@ static void irq_init(running_machine *machine) static INTERRUPT_GEN(model1_interrupt) { + model1_state *state = device->machine->driver_data(); if (cpu_getiloops(device)) { irq_raise(device->machine, 1); } else { - irq_raise(device->machine, model1_sound_irq); + irq_raise(device->machine, state->sound_irq); // if the FIFO has something in it, signal the 68k too - if (fifo_rptr != fifo_wptr) + if (state->fifo_rptr != state->fifo_wptr) { cputag_set_input_line(device->machine, "audiocpu", 2, HOLD_LINE); } @@ -737,33 +735,35 @@ static INTERRUPT_GEN(model1_interrupt) static MACHINE_RESET(model1) { + model1_state *state = machine->driver_data(); memory_set_bankptr(machine, "bank1", machine->region("maincpu")->base() + 0x1000000); irq_init(machine); model1_tgp_reset(machine, !strcmp(machine->gamedrv->name, "swa") || !strcmp(machine->gamedrv->name, "wingwar") || !strcmp(machine->gamedrv->name, "wingwaru") || !strcmp(machine->gamedrv->name, "wingwarj")); if (!strcmp(machine->gamedrv->name, "swa")) { - model1_sound_irq = 0; + state->sound_irq = 0; } else { - model1_sound_irq = 3; + state->sound_irq = 3; } // init the sound FIFO - fifo_rptr = fifo_wptr = 0; - memset(to_68k, 0, sizeof(to_68k)); + state->fifo_rptr = state->fifo_wptr = 0; + memset(state->to_68k, 0, sizeof(state->to_68k)); } static MACHINE_RESET(model1_vr) { + model1_state *state = machine->driver_data(); memory_set_bankptr(machine, "bank1", machine->region("maincpu")->base() + 0x1000000); irq_init(machine); model1_vr_tgp_reset(machine); - model1_sound_irq = 3; + state->sound_irq = 3; // init the sound FIFO - fifo_rptr = fifo_wptr = 0; - memset(to_68k, 0, sizeof(to_68k)); + state->fifo_rptr = state->fifo_wptr = 0; + memset(state->to_68k, 0, sizeof(state->to_68k)); } static READ16_HANDLER( network_ctl_r ) @@ -780,19 +780,21 @@ static WRITE16_HANDLER( network_ctl_w ) static WRITE16_HANDLER(md1_w) { - COMBINE_DATA(model1_display_list1+offset); + model1_state *state = space->machine->driver_data(); + COMBINE_DATA(state->display_list1+offset); if(0 && offset) return; - if(1 && model1_dump) + if(1 && state->dump) logerror("TGP: md1_w %x, %04x @ %04x (%x)\n", offset, data, mem_mask, cpu_get_pc(space->cpu)); } static WRITE16_HANDLER(md0_w) { - COMBINE_DATA(model1_display_list0+offset); + model1_state *state = space->machine->driver_data(); + COMBINE_DATA(state->display_list0+offset); if(0 && offset) return; - if(1 && model1_dump) + if(1 && state->dump) logerror("TGP: md0_w %x, %04x @ %04x (%x)\n", offset, data, mem_mask, cpu_get_pc(space->cpu)); } @@ -804,37 +806,37 @@ static WRITE16_HANDLER(p_w) logerror("XVIDEO: p_w %x, %04x @ %04x (%x)\n", offset, data, mem_mask, cpu_get_pc(space->cpu)); } -static UINT16 *mr; static WRITE16_HANDLER(mr_w) { - COMBINE_DATA(mr+offset); + model1_state *state = space->machine->driver_data(); + COMBINE_DATA(state->mr+offset); if(0 && offset == 0x1138/2) logerror("MR.w %x, %04x @ %04x (%x)\n", offset*2+0x500000, data, mem_mask, cpu_get_pc(space->cpu)); } -static UINT16 *mr2; static WRITE16_HANDLER(mr2_w) { - COMBINE_DATA(mr2+offset); + model1_state *state = space->machine->driver_data(); + COMBINE_DATA(state->mr2+offset); #if 0 if(0 && offset == 0x6e8/2) { logerror("MR.w %x, %04x @ %04x (%x)\n", offset*2+0x400000, data, mem_mask, cpu_get_pc(space->cpu)); } if(offset/2 == 0x3680/4) - logerror("MW f80[r25], %04x%04x (%x)\n", mr2[0x3680/2+1], mr2[0x3680/2], cpu_get_pc(space->cpu)); + logerror("MW f80[r25], %04x%04x (%x)\n", state->mr2[0x3680/2+1], state->mr2[0x3680/2], cpu_get_pc(space->cpu)); if(offset/2 == 0x06ca/4) - logerror("MW fca[r19], %04x%04x (%x)\n", mr2[0x06ca/2+1], mr2[0x06ca/2], cpu_get_pc(space->cpu)); + logerror("MW fca[r19], %04x%04x (%x)\n", state->mr2[0x06ca/2+1], state->mr2[0x06ca/2], cpu_get_pc(space->cpu)); if(offset/2 == 0x1eca/4) - logerror("MW fca[r22], %04x%04x (%x)\n", mr2[0x1eca/2+1], mr2[0x1eca/2], cpu_get_pc(space->cpu)); + logerror("MW fca[r22], %04x%04x (%x)\n", state->mr2[0x1eca/2+1], state->mr2[0x1eca/2], cpu_get_pc(space->cpu)); #endif // wingwar scene position, pc=e1ce -> d735 if(offset/2 == 0x1f08/4) - logerror("MW 8[r10], %f (%x)\n", *(float *)(mr2+0x1f08/2), cpu_get_pc(space->cpu)); + logerror("MW 8[r10], %f (%x)\n", *(float *)(state->mr2+0x1f08/2), cpu_get_pc(space->cpu)); if(offset/2 == 0x1f0c/4) - logerror("MW c[r10], %f (%x)\n", *(float *)(mr2+0x1f0c/2), cpu_get_pc(space->cpu)); + logerror("MW c[r10], %f (%x)\n", *(float *)(state->mr2+0x1f0c/2), cpu_get_pc(space->cpu)); if(offset/2 == 0x1f10/4) - logerror("MW 10[r10], %f (%x)\n", *(float *)(mr2+0x1f10/2), cpu_get_pc(space->cpu)); + logerror("MW 10[r10], %f (%x)\n", *(float *)(state->mr2+0x1f10/2), cpu_get_pc(space->cpu)); } static READ16_HANDLER( snd_68k_ready_r ) @@ -852,9 +854,10 @@ static READ16_HANDLER( snd_68k_ready_r ) static WRITE16_HANDLER( snd_latch_to_68k_w ) { - to_68k[fifo_wptr] = data; - fifo_wptr++; - if (fifo_wptr >= FIFO_SIZE) fifo_wptr = 0; + model1_state *state = space->machine->driver_data(); + state->to_68k[state->fifo_wptr] = data; + state->fifo_wptr++; + if (state->fifo_wptr >= ARRAY_LENGTH(state->to_68k)) state->fifo_wptr = 0; // signal the 68000 that there's data waiting cputag_set_input_line(space->machine, "audiocpu", 2, HOLD_LINE); @@ -867,11 +870,11 @@ static ADDRESS_MAP_START( model1_mem, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x100000, 0x1fffff) AM_ROMBANK("bank1") AM_RANGE(0x200000, 0x2fffff) AM_ROM - AM_RANGE(0x400000, 0x40ffff) AM_RAM_WRITE(mr2_w) AM_BASE(&mr2) - AM_RANGE(0x500000, 0x53ffff) AM_RAM_WRITE(mr_w) AM_BASE(&mr) + AM_RANGE(0x400000, 0x40ffff) AM_RAM_WRITE(mr2_w) AM_BASE_MEMBER(model1_state, mr2) + AM_RANGE(0x500000, 0x53ffff) AM_RAM_WRITE(mr_w) AM_BASE_MEMBER(model1_state, mr) - AM_RANGE(0x600000, 0x60ffff) AM_RAM_WRITE(md0_w) AM_BASE(&model1_display_list0) - AM_RANGE(0x610000, 0x61ffff) AM_RAM_WRITE(md1_w) AM_BASE(&model1_display_list1) + AM_RANGE(0x600000, 0x60ffff) AM_RAM_WRITE(md0_w) AM_BASE_MEMBER(model1_state, display_list0) + AM_RANGE(0x610000, 0x61ffff) AM_RAM_WRITE(md1_w) AM_BASE_MEMBER(model1_state, display_list1) AM_RANGE(0x680000, 0x680003) AM_READWRITE(model1_listctl_r, model1_listctl_w) AM_RANGE(0x700000, 0x70ffff) AM_READWRITE(sys24_tile_r, sys24_tile_w) @@ -882,7 +885,7 @@ static ADDRESS_MAP_START( model1_mem, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x780000, 0x7fffff) AM_READWRITE(sys24_char_r, sys24_char_w) AM_RANGE(0x900000, 0x903fff) AM_RAM_WRITE(p_w) AM_BASE_GENERIC(paletteram) - AM_RANGE(0x910000, 0x91bfff) AM_RAM AM_BASE(&model1_color_xlat) + AM_RANGE(0x910000, 0x91bfff) AM_RAM AM_BASE_MEMBER(model1_state, color_xlat) AM_RANGE(0xc00000, 0xc0003f) AM_READ(io_r) AM_WRITENOP @@ -915,11 +918,11 @@ static ADDRESS_MAP_START( model1_vr_mem, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x100000, 0x1fffff) AM_ROMBANK("bank1") AM_RANGE(0x200000, 0x2fffff) AM_ROM - AM_RANGE(0x400000, 0x40ffff) AM_RAM_WRITE(mr2_w) AM_BASE(&mr2) - AM_RANGE(0x500000, 0x53ffff) AM_RAM_WRITE(mr_w) AM_BASE(&mr) + AM_RANGE(0x400000, 0x40ffff) AM_RAM_WRITE(mr2_w) AM_BASE_MEMBER(model1_state, mr2) + AM_RANGE(0x500000, 0x53ffff) AM_RAM_WRITE(mr_w) AM_BASE_MEMBER(model1_state, mr) - AM_RANGE(0x600000, 0x60ffff) AM_RAM_WRITE(md0_w) AM_BASE(&model1_display_list0) - AM_RANGE(0x610000, 0x61ffff) AM_RAM_WRITE(md1_w) AM_BASE(&model1_display_list1) + AM_RANGE(0x600000, 0x60ffff) AM_RAM_WRITE(md0_w) AM_BASE_MEMBER(model1_state, display_list0) + AM_RANGE(0x610000, 0x61ffff) AM_RAM_WRITE(md1_w) AM_BASE_MEMBER(model1_state, display_list1) AM_RANGE(0x680000, 0x680003) AM_READWRITE(model1_listctl_r, model1_listctl_w) AM_RANGE(0x700000, 0x70ffff) AM_READWRITE(sys24_tile_r, sys24_tile_w) @@ -930,7 +933,7 @@ static ADDRESS_MAP_START( model1_vr_mem, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x780000, 0x7fffff) AM_READWRITE(sys24_char_r, sys24_char_w) AM_RANGE(0x900000, 0x903fff) AM_RAM_WRITE(p_w) AM_BASE_GENERIC(paletteram) - AM_RANGE(0x910000, 0x91bfff) AM_RAM AM_BASE(&model1_color_xlat) + AM_RANGE(0x910000, 0x91bfff) AM_RAM AM_BASE_MEMBER(model1_state, color_xlat) AM_RANGE(0xc00000, 0xc0003f) AM_READ(io_r) AM_WRITENOP @@ -960,12 +963,13 @@ ADDRESS_MAP_END static READ16_HANDLER( m1_snd_68k_latch_r ) { + model1_state *state = space->machine->driver_data(); UINT16 retval; - retval = to_68k[fifo_rptr]; + retval = state->to_68k[state->fifo_rptr]; - fifo_rptr++; - if (fifo_rptr >= FIFO_SIZE) fifo_rptr = 0; + state->fifo_rptr++; + if (state->fifo_rptr >= ARRAY_LENGTH(state->to_68k)) state->fifo_rptr = 0; return retval; } @@ -1497,7 +1501,7 @@ ROM_START( wingwarj ) ROM_END -static MACHINE_CONFIG_START( model1, driver_device ) +static MACHINE_CONFIG_START( model1, model1_state ) MCFG_CPU_ADD("maincpu", V60, 16000000) MCFG_CPU_PROGRAM_MAP(model1_mem) MCFG_CPU_IO_MAP(model1_io) @@ -1537,7 +1541,7 @@ static MACHINE_CONFIG_START( model1, driver_device ) MCFG_SOUND_ROUTE(1, "rspeaker", 1.0) MACHINE_CONFIG_END -static MACHINE_CONFIG_START( model1_vr, driver_device ) +static MACHINE_CONFIG_START( model1_vr, model1_state ) MCFG_CPU_ADD("maincpu", V60, 16000000) MCFG_CPU_PROGRAM_MAP(model1_vr_mem) MCFG_CPU_IO_MAP(model1_vr_io) diff --git a/src/mame/drivers/model2.c b/src/mame/drivers/model2.c index ef7a4ca1cfa..fab8ed485fb 100644 --- a/src/mame/drivers/model2.c +++ b/src/mame/drivers/model2.c @@ -101,22 +101,6 @@ #include "sound/2612intf.h" #include "includes/model2.h" -UINT32 *model2_bufferram, *model2_colorxlat; -static UINT32 *model2_workram; -UINT32 *model2_textureram0, *model2_textureram1, *model2_lumaram; -UINT32 *model2_paletteram32; -static UINT32 model2_intreq; -static UINT32 model2_intena; -static UINT32 model2_coproctl, model2_coprocnt, model2_geoctl, model2_geocnt; -static UINT16 *model2_soundram = NULL; - -static UINT32 model2_timervals[4], model2_timerorig[4]; -static int model2_timerrun[4]; -static timer_device *model2_timers[4]; -static int model2_ctrlmode; -static int analog_channel; - -static UINT32 *tgp_program; enum { DSP_TYPE_TGP = 1, @@ -124,38 +108,33 @@ enum { DSP_TYPE_TGPX4 = 3, }; -static int dsp_type; - - #define COPRO_FIFOIN_SIZE 32000 -static int copro_fifoin_rpos, copro_fifoin_wpos; -static UINT32 copro_fifoin_data[COPRO_FIFOIN_SIZE]; -static int copro_fifoin_num = 0; static int copro_fifoin_pop(device_t *device, UINT32 *result) { + model2_state *state = device->machine->driver_data(); UINT32 r; - if (copro_fifoin_num == 0) + if (state->copro_fifoin_num == 0) { - if (dsp_type == DSP_TYPE_TGP) + if (state->dsp_type == DSP_TYPE_TGP) return 0; fatalerror("Copro FIFOIN underflow (at %08X)", cpu_get_pc(device)); return 0; } - r = copro_fifoin_data[copro_fifoin_rpos++]; + r = state->copro_fifoin_data[state->copro_fifoin_rpos++]; - if (copro_fifoin_rpos == COPRO_FIFOIN_SIZE) + if (state->copro_fifoin_rpos == COPRO_FIFOIN_SIZE) { - copro_fifoin_rpos = 0; + state->copro_fifoin_rpos = 0; } - copro_fifoin_num--; - if (dsp_type == DSP_TYPE_SHARC) + state->copro_fifoin_num--; + if (state->dsp_type == DSP_TYPE_SHARC) { - if (copro_fifoin_num == 0) + if (state->copro_fifoin_num == 0) { sharc_set_flag_input(device, 0, ASSERT_LINE); } @@ -172,7 +151,8 @@ static int copro_fifoin_pop(device_t *device, UINT32 *result) static void copro_fifoin_push(device_t *device, UINT32 data) { - if (copro_fifoin_num == COPRO_FIFOIN_SIZE) + model2_state *state = device->machine->driver_data(); + if (state->copro_fifoin_num == COPRO_FIFOIN_SIZE) { fatalerror("Copro FIFOIN overflow (at %08X)", cpu_get_pc(device)); return; @@ -180,16 +160,16 @@ static void copro_fifoin_push(device_t *device, UINT32 data) //mame_printf_debug("COPRO FIFOIN at %08X, %08X, %f\n", cpu_get_pc(device), data, *(float*)&data); - copro_fifoin_data[copro_fifoin_wpos++] = data; - if (copro_fifoin_wpos == COPRO_FIFOIN_SIZE) + state->copro_fifoin_data[state->copro_fifoin_wpos++] = data; + if (state->copro_fifoin_wpos == COPRO_FIFOIN_SIZE) { - copro_fifoin_wpos = 0; + state->copro_fifoin_wpos = 0; } - copro_fifoin_num++; + state->copro_fifoin_num++; // clear FIFO empty flag on SHARC - if (dsp_type == DSP_TYPE_SHARC) + if (state->dsp_type == DSP_TYPE_SHARC) { sharc_set_flag_input(device, 0, CLEAR_LINE); } @@ -197,14 +177,12 @@ static void copro_fifoin_push(device_t *device, UINT32 data) #define COPRO_FIFOOUT_SIZE 32000 -static int copro_fifoout_rpos, copro_fifoout_wpos; -static UINT32 copro_fifoout_data[COPRO_FIFOOUT_SIZE]; -static int copro_fifoout_num = 0; static UINT32 copro_fifoout_pop(address_space *space) { + model2_state *state = space->machine->driver_data(); UINT32 r; - if (copro_fifoout_num == 0) + if (state->copro_fifoout_num == 0) { /* Reading from empty FIFO causes the i960 to enter wait state */ i960_stall(space->cpu); @@ -215,21 +193,21 @@ static UINT32 copro_fifoout_pop(address_space *space) return 0; } - r = copro_fifoout_data[copro_fifoout_rpos++]; + r = state->copro_fifoout_data[state->copro_fifoout_rpos++]; - if (copro_fifoout_rpos == COPRO_FIFOOUT_SIZE) + if (state->copro_fifoout_rpos == COPRO_FIFOOUT_SIZE) { - copro_fifoout_rpos = 0; + state->copro_fifoout_rpos = 0; } - copro_fifoout_num--; + state->copro_fifoout_num--; -// logerror("COPRO FIFOOUT POP %08X, %f, %d\n", r, *(float*)&r,copro_fifoout_num); +// logerror("COPRO FIFOOUT POP %08X, %f, %d\n", r, *(float*)&r,state->copro_fifoout_num); // set SHARC flag 1: 0 if space available, 1 if FIFO full - if (dsp_type == DSP_TYPE_SHARC) + if (state->dsp_type == DSP_TYPE_SHARC) { - if (copro_fifoout_num == COPRO_FIFOOUT_SIZE) + if (state->copro_fifoout_num == COPRO_FIFOOUT_SIZE) { sharc_set_flag_input(space->machine->device("dsp"), 1, ASSERT_LINE); } @@ -244,27 +222,28 @@ static UINT32 copro_fifoout_pop(address_space *space) static void copro_fifoout_push(device_t *device, UINT32 data) { - //if (copro_fifoout_wpos == copro_fifoout_rpos) - if (copro_fifoout_num == COPRO_FIFOOUT_SIZE) + model2_state *state = device->machine->driver_data(); + //if (state->copro_fifoout_wpos == state->copro_fifoout_rpos) + if (state->copro_fifoout_num == COPRO_FIFOOUT_SIZE) { fatalerror("Copro FIFOOUT overflow (at %08X)", cpu_get_pc(device)); return; } -// logerror("COPRO FIFOOUT PUSH %08X, %f, %d\n", data, *(float*)&data,copro_fifoout_num); +// logerror("COPRO FIFOOUT PUSH %08X, %f, %d\n", data, *(float*)&data,state->copro_fifoout_num); - copro_fifoout_data[copro_fifoout_wpos++] = data; - if (copro_fifoout_wpos == COPRO_FIFOOUT_SIZE) + state->copro_fifoout_data[state->copro_fifoout_wpos++] = data; + if (state->copro_fifoout_wpos == COPRO_FIFOOUT_SIZE) { - copro_fifoout_wpos = 0; + state->copro_fifoout_wpos = 0; } - copro_fifoout_num++; + state->copro_fifoout_num++; // set SHARC flag 1: 0 if space available, 1 if FIFO full - if (dsp_type == DSP_TYPE_SHARC) + if (state->dsp_type == DSP_TYPE_SHARC) { - if (copro_fifoout_num == COPRO_FIFOOUT_SIZE) + if (state->copro_fifoout_num == COPRO_FIFOOUT_SIZE) { sharc_set_flag_input(device, 1, ASSERT_LINE); @@ -282,112 +261,127 @@ static void copro_fifoout_push(device_t *device, UINT32 data) /* Timers - these count down at 25 MHz and pull IRQ2 when they hit 0 */ static READ32_HANDLER( timers_r ) { + model2_state *state = space->machine->driver_data(); i960_noburst(space->cpu); // if timer is running, calculate current value - if (model2_timerrun[offset]) + if (state->timerrun[offset]) { // get elapsed time, convert to units of 25 MHz - UINT32 cur = (model2_timers[offset]->time_elapsed() * 25000000).as_double(); + UINT32 cur = (state->timers[offset]->time_elapsed() * 25000000).as_double(); // subtract units from starting value - model2_timervals[offset] = model2_timerorig[offset] - cur; + state->timervals[offset] = state->timerorig[offset] - cur; } - return model2_timervals[offset]; + return state->timervals[offset]; } static WRITE32_HANDLER( timers_w ) { + model2_state *state = space->machine->driver_data(); attotime period; i960_noburst(space->cpu); - COMBINE_DATA(&model2_timervals[offset]); + COMBINE_DATA(&state->timervals[offset]); - model2_timerorig[offset] = model2_timervals[offset]; - period = attotime::from_hz(25000000) * model2_timerorig[offset]; - model2_timers[offset]->adjust(period); - model2_timerrun[offset] = 1; + state->timerorig[offset] = state->timervals[offset]; + period = attotime::from_hz(25000000) * state->timerorig[offset]; + state->timers[offset]->adjust(period); + state->timerrun[offset] = 1; } static TIMER_DEVICE_CALLBACK( model2_timer_cb ) { + model2_state *state = timer.machine->driver_data(); int tnum = (int)(FPTR)ptr; int bit = tnum + 2; - model2_timers[tnum]->reset(); + state->timers[tnum]->reset(); - model2_intreq |= (1<intreq |= (1<intena & (1<timervals[tnum] = 0; + state->timerrun[tnum] = 0; +} + +static MACHINE_START(model2) +{ + model2_state *state = machine->driver_data(); + state->copro_fifoin_data = auto_alloc_array_clear(machine, UINT32, COPRO_FIFOIN_SIZE); + state->copro_fifoout_data = auto_alloc_array_clear(machine, UINT32, COPRO_FIFOOUT_SIZE); } static MACHINE_RESET(model2_common) { + model2_state *state = machine->driver_data(); int i; - model2_intreq = 0; - model2_intena = 0; - model2_coproctl = 0; - model2_coprocnt = 0; - model2_geoctl = 0; - model2_geocnt = 0; - model2_ctrlmode = 0; - analog_channel = 0; + state->intreq = 0; + state->intena = 0; + state->coproctl = 0; + state->coprocnt = 0; + state->geoctl = 0; + state->geocnt = 0; + state->ctrlmode = 0; + state->analog_channel = 0; - model2_timervals[0] = 0xfffff; - model2_timervals[1] = 0xfffff; - model2_timervals[2] = 0xfffff; - model2_timervals[3] = 0xfffff; + state->timervals[0] = 0xfffff; + state->timervals[1] = 0xfffff; + state->timervals[2] = 0xfffff; + state->timervals[3] = 0xfffff; - model2_timerrun[0] = model2_timerrun[1] = model2_timerrun[2] = model2_timerrun[3] = 0; + state->timerrun[0] = state->timerrun[1] = state->timerrun[2] = state->timerrun[3] = 0; - model2_timers[0] = machine->device("timer0"); - model2_timers[1] = machine->device("timer1"); - model2_timers[2] = machine->device("timer2"); - model2_timers[3] = machine->device("timer3"); + state->timers[0] = machine->device("timer0"); + state->timers[1] = machine->device("timer1"); + state->timers[2] = machine->device("timer2"); + state->timers[3] = machine->device("timer3"); for (i=0; i<4; i++) - model2_timers[i]->reset(); + state->timers[i]->reset(); } static MACHINE_RESET(model2o) { + model2_state *state = machine->driver_data(); MACHINE_RESET_CALL(model2_common); // hold TGP in halt until we have code cputag_set_input_line(machine, "tgp", INPUT_LINE_HALT, ASSERT_LINE); - dsp_type = DSP_TYPE_TGP; + state->dsp_type = DSP_TYPE_TGP; } static MACHINE_RESET(model2_scsp) { + model2_state *state = machine->driver_data(); memory_set_bankptr(machine, "bank4", machine->region("scsp")->base() + 0x200000); memory_set_bankptr(machine, "bank5", machine->region("scsp")->base() + 0x600000); // copy the 68k vector table into RAM - memcpy(model2_soundram, machine->region("audiocpu")->base() + 0x80000, 16); + memcpy(state->soundram, machine->region("audiocpu")->base() + 0x80000, 16); machine->device("audiocpu")->reset(); } static MACHINE_RESET(model2) { + model2_state *state = machine->driver_data(); MACHINE_RESET_CALL(model2_common); MACHINE_RESET_CALL(model2_scsp); // hold TGP in halt until we have code cputag_set_input_line(machine, "tgp", INPUT_LINE_HALT, ASSERT_LINE); - dsp_type = DSP_TYPE_TGP; + state->dsp_type = DSP_TYPE_TGP; } static MACHINE_RESET(model2b) { + model2_state *state = machine->driver_data(); MACHINE_RESET_CALL(model2_common); MACHINE_RESET_CALL(model2_scsp); @@ -398,15 +392,16 @@ static MACHINE_RESET(model2b) // clear FIFOOUT buffer full flag on SHARC cputag_set_input_line(machine, "dsp", SHARC_INPUT_FLAG1, CLEAR_LINE); - dsp_type = DSP_TYPE_SHARC; + state->dsp_type = DSP_TYPE_SHARC; } static MACHINE_RESET(model2c) { + model2_state *state = machine->driver_data(); MACHINE_RESET_CALL(model2_common); MACHINE_RESET_CALL(model2_scsp); - dsp_type = DSP_TYPE_TGPX4; + state->dsp_type = DSP_TYPE_TGPX4; } static void chcolor(running_machine *machine, pen_t color, UINT16 data) @@ -416,19 +411,21 @@ static void chcolor(running_machine *machine, pen_t color, UINT16 data) static WRITE32_HANDLER( pal32_w ) { - COMBINE_DATA(model2_paletteram32 + offset); + model2_state *state = space->machine->driver_data(); + COMBINE_DATA(state->paletteram32 + offset); if(ACCESSING_BITS_0_15) - chcolor(space->machine, offset * 2, model2_paletteram32[offset]); + chcolor(space->machine, offset * 2, state->paletteram32[offset]); if(ACCESSING_BITS_16_31) - chcolor(space->machine, offset * 2 + 1, model2_paletteram32[offset] >> 16); + chcolor(space->machine, offset * 2 + 1, state->paletteram32[offset] >> 16); } static WRITE32_HANDLER( ctrl0_w ) { + model2_state *state = space->machine->driver_data(); if(ACCESSING_BITS_0_7) { eeprom_device *device = space->machine->device("eeprom"); - model2_ctrlmode = data & 0x01; + state->ctrlmode = data & 0x01; eeprom_write_bit(device, data & 0x20); eeprom_set_clock_line(device, (data & 0x80) ? ASSERT_LINE : CLEAR_LINE); eeprom_set_cs_line(device, (data & 0x40) ? CLEAR_LINE : ASSERT_LINE); @@ -437,15 +434,17 @@ static WRITE32_HANDLER( ctrl0_w ) static WRITE32_HANDLER( analog_2b_w ) { - analog_channel = (data >> 16) & 0x07; + model2_state *state = space->machine->driver_data(); + state->analog_channel = (data >> 16) & 0x07; } static READ32_HANDLER( fifoctl_r ) { + model2_state *state = space->machine->driver_data(); UINT32 r = 0; - if (copro_fifoout_num == 0) + if (state->copro_fifoout_num == 0) { r |= 1; } @@ -461,9 +460,10 @@ static READ32_HANDLER( videoctl_r ) static CUSTOM_INPUT( _1c00000_r ) { + model2_state *state = field->port->machine->driver_data(); UINT32 ret = input_port_read(field->port->machine, "IN0"); - if(model2_ctrlmode == 0) + if(state->ctrlmode == 0) { return ret; } @@ -476,12 +476,13 @@ static CUSTOM_INPUT( _1c00000_r ) static CUSTOM_INPUT( _1c0001c_r ) { + model2_state *state = field->port->machine->driver_data(); UINT32 iptval = 0x00ff; - if(analog_channel < 4) + if(state->analog_channel < 4) { static const char *const ports[] = { "ANA0", "ANA1", "ANA2", "ANA3" }; - iptval = input_port_read_safe(field->port->machine, ports[analog_channel], 0); - ++analog_channel; + iptval = input_port_read_safe(field->port->machine, ports[state->analog_channel], 0); + ++state->analog_channel; } return iptval; } @@ -555,7 +556,6 @@ static CUSTOM_INPUT( _1c0001c_r ) */ -static UINT16 cmd_data; static CUSTOM_INPUT( rchase2_devices_r ) { @@ -564,19 +564,20 @@ static CUSTOM_INPUT( rchase2_devices_r ) static WRITE32_HANDLER( rchase2_devices_w ) { + model2_state *state = space->machine->driver_data(); /* 0x00040000 start 1 lamp 0x00080000 start 2 lamp */ if(mem_mask == 0x0000ffff) - cmd_data = data; + state->cmd_data = data; } -static UINT8 driveio_comm_data; static WRITE32_HANDLER( srallyc_devices_w ) { + model2_state *state = space->machine->driver_data(); /* 0x00040000 start 1 lamp 0x00200000 vr lamp @@ -585,7 +586,7 @@ static WRITE32_HANDLER( srallyc_devices_w ) if(mem_mask == 0x000000ff || mem_mask == 0x0000ffff) { - driveio_comm_data = data & 0xff; + state->driveio_comm_data = data & 0xff; cputag_set_input_line(space->machine, "drivecpu", 0, HOLD_LINE); } } @@ -601,10 +602,11 @@ static READ32_HANDLER(copro_prg_r) static WRITE32_HANDLER(copro_prg_w) { - if (model2_coproctl & 0x80000000) + model2_state *state = space->machine->driver_data(); + if (state->coproctl & 0x80000000) { - logerror("copro_prg_w: %08X: %08X\n", model2_coprocnt, data); - model2_coprocnt++; + logerror("copro_prg_w: %08X: %08X\n", state->coprocnt, data); + state->coprocnt++; } else { @@ -614,20 +616,21 @@ static WRITE32_HANDLER(copro_prg_w) static WRITE32_HANDLER( copro_ctl1_w ) { + model2_state *state = space->machine->driver_data(); // did hi bit change? - if ((data ^ model2_coproctl) == 0x80000000) + if ((data ^ state->coproctl) == 0x80000000) { if (data & 0x80000000) { logerror("Start copro upload\n"); - model2_coprocnt = 0; + state->coprocnt = 0; } else { - logerror("Boot copro, %d dwords\n", model2_coprocnt); - if (dsp_type != DSP_TYPE_TGPX4) + logerror("Boot copro, %d dwords\n", state->coprocnt); + if (state->dsp_type != DSP_TYPE_TGPX4) { - if (dsp_type == DSP_TYPE_SHARC) + if (state->dsp_type == DSP_TYPE_SHARC) cputag_set_input_line(space->machine, "dsp", INPUT_LINE_HALT, CLEAR_LINE); else cputag_set_input_line(space->machine, "tgp", INPUT_LINE_HALT, CLEAR_LINE); @@ -635,17 +638,18 @@ static WRITE32_HANDLER( copro_ctl1_w ) } } - model2_coproctl = data; + state->coproctl = data; } static WRITE32_HANDLER(copro_function_port_w) { + model2_state *state = space->machine->driver_data(); UINT32 d = data & 0x800fffff; UINT32 a = (offset >> 2) & 0xff; d |= a << 23; //logerror("copro_function_port_w: %08X, %08X, %08X\n", data, offset, mem_mask); - if (dsp_type == DSP_TYPE_SHARC) + if (state->dsp_type == DSP_TYPE_SHARC) copro_fifoin_push(space->machine->device("dsp"), d); else copro_fifoin_push(space->machine->device("tgp"), d); @@ -659,33 +663,33 @@ static READ32_HANDLER(copro_fifo_r) static WRITE32_HANDLER(copro_fifo_w) { - if (model2_coproctl & 0x80000000) + model2_state *state = space->machine->driver_data(); + if (state->coproctl & 0x80000000) { - if (dsp_type == DSP_TYPE_SHARC) + if (state->dsp_type == DSP_TYPE_SHARC) { - sharc_external_dma_write(space->machine->device("dsp"), model2_coprocnt, data & 0xffff); + sharc_external_dma_write(space->machine->device("dsp"), state->coprocnt, data & 0xffff); } - else if (dsp_type == DSP_TYPE_TGP) + else if (state->dsp_type == DSP_TYPE_TGP) { - tgp_program[model2_coprocnt] = data; + state->tgp_program[state->coprocnt] = data; } - model2_coprocnt++; + state->coprocnt++; } else { //mame_printf_debug("copro_fifo_w: %08X, %08X, %08X at %08X\n", data, offset, mem_mask, cpu_get_pc(space->cpu)); - if (dsp_type == DSP_TYPE_SHARC) + if (state->dsp_type == DSP_TYPE_SHARC) copro_fifoin_push(space->machine->device("dsp"), data); else copro_fifoin_push(space->machine->device("tgp"), data); } } -static int iop_write_num = 0; -static UINT32 iop_data = 0; static WRITE32_HANDLER(copro_sharc_iop_w) { + model2_state *state = space->machine->driver_data(); /* FIXME: clean this up */ if ((strcmp(space->machine->gamedrv->name, "schamp" ) == 0) || (strcmp(space->machine->gamedrv->name, "sfight" ) == 0) || @@ -701,16 +705,16 @@ static WRITE32_HANDLER(copro_sharc_iop_w) } else { - if ((iop_write_num & 1) == 0) + if ((state->iop_write_num & 1) == 0) { - iop_data = data & 0xffff; + state->iop_data = data & 0xffff; } else { - iop_data |= (data & 0xffff) << 16; - sharc_external_iop_write(space->machine->device("dsp"), offset, iop_data); + state->iop_data |= (data & 0xffff) << 16; + sharc_external_iop_write(space->machine->device("dsp"), offset, state->iop_data); } - iop_write_num++; + state->iop_write_num++; } } @@ -721,49 +725,49 @@ static WRITE32_HANDLER(copro_sharc_iop_w) /*****************************************************************************/ /* GEO */ -UINT32 geo_read_start_address = 0; -UINT32 geo_write_start_address = 0; static WRITE32_HANDLER( geo_ctl1_w ) { + model2_state *state = space->machine->driver_data(); // did hi bit change? - if ((data ^ model2_geoctl) == 0x80000000) + if ((data ^ state->geoctl) == 0x80000000) { if (data & 0x80000000) { - logerror("Start geo upload\n"); - model2_geocnt = 0; + logerror("Start state->geo upload\n"); + state->geocnt = 0; } else { - logerror("Boot geo, %d dwords\n", model2_geocnt); + logerror("Boot state->geo, %d dwords\n", state->geocnt); } } - model2_geoctl = data; + state->geoctl = data; } #ifdef UNUSED_FUNCTION static WRITE32_HANDLER( geo_sharc_ctl1_w ) { + model2_state *state = space->machine->driver_data(); // did hi bit change? - if ((data ^ model2_geoctl) == 0x80000000) + if ((data ^ state->geoctl) == 0x80000000) { if (data & 0x80000000) { - logerror("Start geo upload\n"); - model2_geocnt = 0; + logerror("Start state->geo upload\n"); + state->geocnt = 0; } else { - logerror("Boot geo, %d dwords\n", model2_geocnt); + logerror("Boot state->geo, %d dwords\n", state->geocnt); cputag_set_input_line(space->machine, "dsp2", INPUT_LINE_HALT, CLEAR_LINE); //cpu_spinuntil_time(space->cpu, attotime::from_usec(1000)); // Give the SHARC enough time to boot itself } } - model2_geoctl = data; + state->geoctl = data; } static READ32_HANDLER(geo_sharc_fifo_r) @@ -781,11 +785,12 @@ static READ32_HANDLER(geo_sharc_fifo_r) static WRITE32_HANDLER(geo_sharc_fifo_w) { - if (model2_geoctl & 0x80000000) + model2_state *state = space->machine->driver_data(); + if (state->geoctl & 0x80000000) { - sharc_external_dma_write(space->machine->device("dsp2"), model2_geocnt, data & 0xffff); + sharc_external_dma_write(space->machine->device("dsp2"), state->geocnt, data & 0xffff); - model2_geocnt++; + state->geocnt++; } else { @@ -793,36 +798,35 @@ static WRITE32_HANDLER(geo_sharc_fifo_w) } } -static int geo_iop_write_num = 0; -static UINT32 geo_iop_data = 0; static WRITE32_HANDLER(geo_sharc_iop_w) { + model2_state *state = space->machine->driver_data(); if ((strcmp(space->machine->gamedrv->name, "schamp" ) == 0)) { sharc_external_iop_write(space->machine->device("dsp2"), offset, data); } else { - if ((geo_iop_write_num & 1) == 0) + if ((state->geo_iop_write_num & 1) == 0) { - geo_iop_data = data & 0xffff; + state->geo_iop_data = data & 0xffff; } else { - geo_iop_data |= (data & 0xffff) << 16; - sharc_external_iop_write(space->machine->device("dsp2"), offset, geo_iop_data); + state->geo_iop_data |= (data & 0xffff) << 16; + sharc_external_iop_write(space->machine->device("dsp2"), offset, state->geo_iop_data); } - geo_iop_write_num++; + state->geo_iop_write_num++; } } #endif -static void push_geo_data(UINT32 data) +static void push_geo_data(model2_state *state, UINT32 data) { - //mame_printf_debug("push_geo_data: %08X: %08X\n", 0x900000+geo_write_start_address, data); - model2_bufferram[geo_write_start_address/4] = data; - geo_write_start_address += 4; + //mame_printf_debug("push_geo_data: %08X: %08X\n", 0x900000+state->geo_write_start_address, data); + state->bufferram[state->geo_write_start_address/4] = data; + state->geo_write_start_address += 4; } static READ32_HANDLER(geo_prg_r) @@ -832,28 +836,30 @@ static READ32_HANDLER(geo_prg_r) static WRITE32_HANDLER(geo_prg_w) { - if (model2_geoctl & 0x80000000) + model2_state *state = space->machine->driver_data(); + if (state->geoctl & 0x80000000) { - //logerror("geo_prg_w: %08X: %08X\n", model2_geocnt, data); - model2_geocnt++; + //logerror("geo_prg_w: %08X: %08X\n", state->geocnt, data); + state->geocnt++; } else { - //mame_printf_debug("GEO: %08X: push %08X\n", geo_write_start_address, data); - push_geo_data(data); + //mame_printf_debug("GEO: %08X: push %08X\n", state->geo_write_start_address, data); + push_geo_data(state, data); } } static READ32_HANDLER( geo_r ) { + model2_state *state = space->machine->driver_data(); int address = offset * 4; if (address == 0x2008) { - return geo_write_start_address; + return state->geo_write_start_address; } else if (address == 0x3008) { - return geo_read_start_address; + return state->geo_read_start_address; } // fatalerror("geo_r: %08X, %08X\n", address, mem_mask); @@ -864,6 +870,7 @@ static READ32_HANDLER( geo_r ) static WRITE32_HANDLER( geo_w ) { + model2_state *state = space->machine->driver_data(); int address = offset * 4; if (address < 0x1000) @@ -877,7 +884,7 @@ static WRITE32_HANDLER( geo_w ) for (i=0; i < 4; i++) { mame_printf_debug(" %08X: %08X %08X %08X %08X\n", 0x900000+(a*4)+(i*16), - model2_bufferram[a+(i*4)+0], model2_bufferram[a+(i*4)+1], model2_bufferram[a+(i*4)+2], model2_bufferram[a+(i*4)+3]); + state->bufferram[a+(i*4)+0], state->bufferram[a+(i*4)+1], state->bufferram[a+(i*4)+2], state->bufferram[a+(i*4)+3]); } } else @@ -901,7 +908,7 @@ static WRITE32_HANDLER( geo_w ) UINT32 r = 0; r |= data & 0x800fffff; r |= ((address >> 4) & 0x3f) << 23; - push_geo_data(r); + push_geo_data(state, r); } else { @@ -910,19 +917,19 @@ static WRITE32_HANDLER( geo_w ) UINT32 r = 0; r |= data & 0x000fffff; r |= ((address >> 4) & 0x3f) << 23; - push_geo_data(r); + push_geo_data(state, r); } } } else if (address == 0x1008) { //mame_printf_debug("GEO: Write Start Address: %08X\n", data); - geo_write_start_address = data & 0xfffff; + state->geo_write_start_address = data & 0xfffff; } else if (address == 0x3008) { //mame_printf_debug("GEO: Read Start Address: %08X\n", data); - geo_read_start_address = data & 0xfffff; + state->geo_read_start_address = data & 0xfffff; } else { @@ -960,30 +967,31 @@ static READ32_HANDLER(desert_unk_r) static READ32_HANDLER(model2_irq_r) { + model2_state *state = space->machine->driver_data(); i960_noburst(space->cpu); if (offset) { - return model2_intena; + return state->intena; } - return model2_intreq; + return state->intreq; } static WRITE32_HANDLER(model2_irq_w) { + model2_state *state = space->machine->driver_data(); i960_noburst(space->cpu); if (offset) { - COMBINE_DATA(&model2_intena); + COMBINE_DATA(&state->intena); return; } - model2_intreq &= data; + state->intreq &= data; } -static int to_68k; static int snd_68k_ready_r(address_space *space) { @@ -1000,12 +1008,13 @@ static int snd_68k_ready_r(address_space *space) static void snd_latch_to_68k_w(address_space *space, int data) { + model2_state *state = space->machine->driver_data(); if (!snd_68k_ready_r(space)) { cpu_spinuntil_time(space->cpu, attotime::from_usec(40)); } - to_68k = data; + state->to_68k = data; cputag_set_input_line(space->machine, "audiocpu", 2, HOLD_LINE); @@ -1059,12 +1068,10 @@ static const UINT8 DCOPKey1326[]= { 0x43,0x66,0x54,0x11,0x99,0xfe,0xcc,0x8e,0xdd,0x87,0x11,0x89,0x22,0xdf,0x44,0x09 }; -static int protstate, protpos; -static UINT8 protram[256]; static READ32_HANDLER( model2_prot_r ) { - static int a = 0; + model2_state *state = space->machine->driver_data(); UINT32 retval = 0; if (offset == 0x10000/4) @@ -1074,19 +1081,19 @@ static READ32_HANDLER( model2_prot_r ) } else if (offset == 0x1000e/4) { - retval = protram[protstate+1] | protram[protstate]<<8; + retval = state->protram[state->protstate+1] | state->protram[state->protstate]<<8; retval <<= 16; - protstate+=2; + state->protstate+=2; } else if (offset == 0x7ff8/4) { - retval = protram[protstate+1] | protram[protstate]<<8; - protstate+=2; + retval = state->protram[state->protstate+1] | state->protram[state->protstate]<<8; + state->protstate+=2; } else if (offset == 0x400c/4) { - a = !a; - if (a) + state->prot_a = !state->prot_a; + if (state->prot_a) return 0xffff; else return 0xfff0; @@ -1098,6 +1105,7 @@ static READ32_HANDLER( model2_prot_r ) static WRITE32_HANDLER( model2_prot_w ) { + model2_state *state = space->machine->driver_data(); if (mem_mask == 0xffff0000) { data >>= 16; @@ -1105,7 +1113,7 @@ static WRITE32_HANDLER( model2_prot_w ) if (offset == 0x10008/4) { - protpos = data; + state->protpos = data; } else if (offset == 0x1000c/4) { @@ -1113,13 +1121,13 @@ static WRITE32_HANDLER( model2_prot_w ) { // dynamcop case 0x7700: - strcpy((char *)protram+2, "UCHIDA MOMOKA "); + strcpy((char *)state->protram+2, "UCHIDA MOMOKA "); break; // dynamcop case 0x1326: - protstate = 0; - memcpy(protram+2, DCOPKey1326, sizeof(DCOPKey1326)); + state->protstate = 0; + memcpy(state->protram+2, DCOPKey1326, sizeof(DCOPKey1326)); break; // zerogun @@ -1138,18 +1146,18 @@ static WRITE32_HANDLER( model2_prot_w ) case 0x98CC: case 0x3422: case 0x10: - protstate = 0; - memcpy(protram+2, ZGUNProt+((2*protpos)/12)*8, sizeof(ZGUNProt)); + state->protstate = 0; + memcpy(state->protram+2, ZGUNProt+((2*state->protpos)/12)*8, sizeof(ZGUNProt)); break; // pltkids case 0x7140: - protstate = 0; - strcpy((char *)protram+2, "98-PILOT "); + state->protstate = 0; + strcpy((char *)state->protram+2, "98-PILOT "); break; default: - protstate = 0; + state->protstate = 0; break; } } @@ -1157,8 +1165,8 @@ static WRITE32_HANDLER( model2_prot_w ) { if (data == 0) { - protstate = 0; - strcpy((char *)protram, " TECMO LTD. DEAD OR ALIVE 1996.10.22 VER. 1.00"); + state->protstate = 0; + strcpy((char *)state->protram, " TECMO LTD. DEAD OR ALIVE 1996.10.22 VER. 1.00"); } } else logerror("Unhandled Protection WRITE %x @ %x mask %x (PC=%x)\n", data, offset, mem_mask, cpu_get_pc(space->cpu)); @@ -1167,10 +1175,10 @@ static WRITE32_HANDLER( model2_prot_w ) /* Daytona "To The MAXX" PIC protection simulation */ -static int model2_maxxstate = 0; static READ32_HANDLER( maxx_r ) { + model2_state *state = space->machine->driver_data(); UINT32 *ROM = (UINT32 *)space->machine->region("maincpu")->base(); if (offset <= 0x1f/4) @@ -1179,15 +1187,15 @@ static READ32_HANDLER( maxx_r ) if (mem_mask == 0xffff0000) { // 16-bit protection reads - model2_maxxstate++; - model2_maxxstate &= 0xf; - if (!model2_maxxstate) + state->maxxstate++; + state->maxxstate &= 0xf; + if (!state->maxxstate) { return 0x00070000; } else { - if (model2_maxxstate & 0x2) + if (state->maxxstate & 0x2) { return 0; } @@ -1212,12 +1220,11 @@ static READ32_HANDLER( maxx_r ) /* Network board emulation */ -static UINT32 model2_netram[0x8000/4]; -static int zflagi, zflag, sysres; static READ32_HANDLER( network_r ) { + model2_state *state = space->machine->driver_data(); if ((mem_mask == 0xffffffff) || (mem_mask == 0x0000ffff) || (mem_mask == 0xffff0000)) { return 0xffffffff; @@ -1225,16 +1232,16 @@ static READ32_HANDLER( network_r ) if (offset < 0x4000/4) { - return model2_netram[offset]; + return state->netram[offset]; } if (mem_mask == 0x00ff0000) { - return sysres<<16; + return state->sysres<<16; } else if (mem_mask == 0x000000ff) { - return zflagi; + return state->zflagi; } return 0xffffffff; @@ -1242,28 +1249,29 @@ static READ32_HANDLER( network_r ) static WRITE32_HANDLER( network_w ) { + model2_state *state = space->machine->driver_data(); if ((mem_mask == 0xffffffff) || (mem_mask == 0x0000ffff) || (mem_mask == 0xffff0000)) { - COMBINE_DATA(&model2_netram[offset+0x4000/4]); + COMBINE_DATA(&state->netram[offset+0x4000/4]); return; } if (offset < 0x4000/4) { - COMBINE_DATA(&model2_netram[offset]); + COMBINE_DATA(&state->netram[offset]); return; } if (mem_mask == 0x00ff0000) { - sysres = data>>16; + state->sysres = data>>16; } else if (mem_mask == 0x000000ff) { - zflagi = data; - zflag = 0; - if (data & 0x01) zflag |= 0x80; - if (data & 0x80) zflag |= 0x01; + state->zflagi = data; + state->zflag = 0; + if (data & 0x01) state->zflag |= 0x80; + if (data & 0x80) state->zflag |= 0x01; } } @@ -1294,56 +1302,59 @@ static WRITE32_HANDLER(mode_w) static WRITE32_HANDLER(model2o_tex_w0) { + model2_state *state = space->machine->driver_data(); if ( (offset & 1) == 0 ) { - model2_textureram0[offset>>1] &= 0xffff0000; - model2_textureram0[offset>>1] |= data & 0xffff; + state->textureram0[offset>>1] &= 0xffff0000; + state->textureram0[offset>>1] |= data & 0xffff; } else { - model2_textureram0[offset>>1] &= 0x0000ffff; - model2_textureram0[offset>>1] |= (data & 0xffff) << 16; + state->textureram0[offset>>1] &= 0x0000ffff; + state->textureram0[offset>>1] |= (data & 0xffff) << 16; } } static WRITE32_HANDLER(model2o_tex_w1) { + model2_state *state = space->machine->driver_data(); if ( (offset & 1) == 0 ) { - model2_textureram1[offset>>1] &= 0xffff0000; - model2_textureram1[offset>>1] |= data & 0xffff; + state->textureram1[offset>>1] &= 0xffff0000; + state->textureram1[offset>>1] |= data & 0xffff; } else { - model2_textureram1[offset>>1] &= 0x0000ffff; - model2_textureram1[offset>>1] |= (data & 0xffff) << 16; + state->textureram1[offset>>1] &= 0x0000ffff; + state->textureram1[offset>>1] |= (data & 0xffff) << 16; } } static WRITE32_HANDLER(model2o_luma_w) { + model2_state *state = space->machine->driver_data(); if ( (offset & 1) == 0 ) { - model2_lumaram[offset>>1] &= 0xffff0000; - model2_lumaram[offset>>1] |= data & 0xffff; + state->lumaram[offset>>1] &= 0xffff0000; + state->lumaram[offset>>1] |= data & 0xffff; } else { - model2_lumaram[offset>>1] &= 0x0000ffff; - model2_lumaram[offset>>1] |= (data & 0xffff) << 16; + state->lumaram[offset>>1] &= 0x0000ffff; + state->lumaram[offset>>1] |= (data & 0xffff) << 16; } } static WRITE32_HANDLER(model2_3d_zclip_w) { - model2_3d_set_zclip( data & 0xFF ); + model2_3d_set_zclip( space->machine, data & 0xFF ); } /* common map for all Model 2 versions */ static ADDRESS_MAP_START( model2_base_mem, ADDRESS_SPACE_PROGRAM, 32 ) AM_RANGE(0x00000000, 0x001fffff) AM_ROM AM_WRITENOP - AM_RANGE(0x00500000, 0x005fffff) AM_RAM AM_BASE(&model2_workram) + AM_RANGE(0x00500000, 0x005fffff) AM_RAM AM_BASE_MEMBER(model2_state, workram) AM_RANGE(0x00800000, 0x00803fff) AM_READWRITE(geo_r, geo_w) //AM_RANGE(0x00800010, 0x00800013) AM_WRITENOP @@ -1352,7 +1363,7 @@ static ADDRESS_MAP_START( model2_base_mem, ADDRESS_SPACE_PROGRAM, 32 ) //AM_RANGE(0x00880000, 0x00883fff) AM_WRITE(copro_w) - AM_RANGE(0x00900000, 0x0097ffff) AM_RAM AM_BASE(&model2_bufferram) + AM_RANGE(0x00900000, 0x0097ffff) AM_RAM AM_BASE_MEMBER(model2_state, bufferram) AM_RANGE(0x00980004, 0x00980007) AM_READ(fifoctl_r) @@ -1371,8 +1382,8 @@ static ADDRESS_MAP_START( model2_base_mem, ADDRESS_SPACE_PROGRAM, 32 ) AM_RANGE(0x01100000, 0x0110ffff) AM_READWRITE(sys24_tile32_r, sys24_tile32_w) AM_MIRROR(0x10000) AM_RANGE(0x01180000, 0x011fffff) AM_READWRITE(sys24_char32_r, sys24_char32_w) AM_MIRROR(0x100000) - AM_RANGE(0x01800000, 0x01803fff) AM_RAM_WRITE(pal32_w) AM_BASE(&model2_paletteram32) - AM_RANGE(0x01810000, 0x0181bfff) AM_RAM AM_BASE(&model2_colorxlat) + AM_RANGE(0x01800000, 0x01803fff) AM_RAM_WRITE(pal32_w) AM_BASE_MEMBER(model2_state, paletteram32) + AM_RANGE(0x01810000, 0x0181bfff) AM_RAM AM_BASE_MEMBER(model2_state, colorxlat) AM_RANGE(0x0181c000, 0x0181c003) AM_WRITE(model2_3d_zclip_w) AM_RANGE(0x01a10000, 0x01a1ffff) AM_READWRITE(network_r, network_w) AM_RANGE(0x01d00000, 0x01d03fff) AM_RAM AM_SHARE("backup1") // Backup sram @@ -1402,9 +1413,9 @@ static ADDRESS_MAP_START( model2o_mem, ADDRESS_SPACE_PROGRAM, 32 ) AM_RANGE(0x00980008, 0x0098000b) AM_WRITE( geo_ctl1_w ) AM_RANGE(0x009c0000, 0x009cffff) AM_READWRITE( model2_serial_r, model2o_serial_w ) - AM_RANGE(0x12000000, 0x121fffff) AM_RAM_WRITE(model2o_tex_w0) AM_MIRROR(0x200000) AM_BASE(&model2_textureram0) // texture RAM 0 - AM_RANGE(0x12400000, 0x125fffff) AM_RAM_WRITE(model2o_tex_w1) AM_MIRROR(0x200000) AM_BASE(&model2_textureram1) // texture RAM 1 - AM_RANGE(0x12800000, 0x1281ffff) AM_RAM_WRITE(model2o_luma_w) AM_BASE(&model2_lumaram) // polygon "luma" RAM + AM_RANGE(0x12000000, 0x121fffff) AM_RAM_WRITE(model2o_tex_w0) AM_MIRROR(0x200000) AM_BASE_MEMBER(model2_state, textureram0) // texture RAM 0 + AM_RANGE(0x12400000, 0x125fffff) AM_RAM_WRITE(model2o_tex_w1) AM_MIRROR(0x200000) AM_BASE_MEMBER(model2_state, textureram1) // texture RAM 1 + AM_RANGE(0x12800000, 0x1281ffff) AM_RAM_WRITE(model2o_luma_w) AM_BASE_MEMBER(model2_state, lumaram) // polygon "luma" RAM AM_RANGE(0x01c00000, 0x01c00003) AM_READ_PORT("1c00000") AM_RANGE(0x01c00004, 0x01c00007) AM_READ_PORT("1c00004") @@ -1432,9 +1443,9 @@ static ADDRESS_MAP_START( model2a_crx_mem, ADDRESS_SPACE_PROGRAM, 32 ) AM_RANGE(0x00980008, 0x0098000b) AM_WRITE( geo_ctl1_w ) AM_RANGE(0x009c0000, 0x009cffff) AM_READWRITE( model2_serial_r, model2_serial_w ) - AM_RANGE(0x12000000, 0x121fffff) AM_RAM_WRITE(model2o_tex_w0) AM_MIRROR(0x200000) AM_BASE(&model2_textureram0) // texture RAM 0 - AM_RANGE(0x12400000, 0x125fffff) AM_RAM_WRITE(model2o_tex_w1) AM_MIRROR(0x200000) AM_BASE(&model2_textureram1) // texture RAM 1 - AM_RANGE(0x12800000, 0x1281ffff) AM_RAM_WRITE(model2o_luma_w) AM_BASE(&model2_lumaram) // polygon "luma" RAM + AM_RANGE(0x12000000, 0x121fffff) AM_RAM_WRITE(model2o_tex_w0) AM_MIRROR(0x200000) AM_BASE_MEMBER(model2_state, textureram0) // texture RAM 0 + AM_RANGE(0x12400000, 0x125fffff) AM_RAM_WRITE(model2o_tex_w1) AM_MIRROR(0x200000) AM_BASE_MEMBER(model2_state, textureram1) // texture RAM 1 + AM_RANGE(0x12800000, 0x1281ffff) AM_RAM_WRITE(model2o_luma_w) AM_BASE_MEMBER(model2_state, lumaram) // polygon "luma" RAM AM_RANGE(0x01c00000, 0x01c00003) AM_READ_PORT("1c00000") AM_WRITE( ctrl0_w ) AM_RANGE(0x01c00004, 0x01c00007) AM_READ_PORT("1c00004") @@ -1466,9 +1477,9 @@ static ADDRESS_MAP_START( model2b_crx_mem, ADDRESS_SPACE_PROGRAM, 32 ) AM_RANGE(0x009c0000, 0x009cffff) AM_READWRITE( model2_serial_r, model2_serial_w ) - AM_RANGE(0x11000000, 0x111fffff) AM_RAM AM_BASE(&model2_textureram0) // texture RAM 0 (2b/2c) - AM_RANGE(0x11200000, 0x113fffff) AM_RAM AM_BASE(&model2_textureram1) // texture RAM 1 (2b/2c) - AM_RANGE(0x11400000, 0x1140ffff) AM_RAM AM_BASE(&model2_lumaram) // polygon "luma" RAM (2b/2c) + AM_RANGE(0x11000000, 0x111fffff) AM_RAM AM_BASE_MEMBER(model2_state, textureram0) // texture RAM 0 (2b/2c) + AM_RANGE(0x11200000, 0x113fffff) AM_RAM AM_BASE_MEMBER(model2_state, textureram1) // texture RAM 1 (2b/2c) + AM_RANGE(0x11400000, 0x1140ffff) AM_RAM AM_BASE_MEMBER(model2_state, lumaram) // polygon "luma" RAM (2b/2c) AM_RANGE(0x01c00000, 0x01c00003) AM_READ_PORT("1c00000") AM_WRITE( ctrl0_w ) @@ -1493,9 +1504,9 @@ static ADDRESS_MAP_START( model2c_crx_mem, ADDRESS_SPACE_PROGRAM, 32 ) AM_RANGE(0x00980008, 0x0098000b) AM_WRITE( geo_ctl1_w ) AM_RANGE(0x009c0000, 0x009cffff) AM_READWRITE( model2_serial_r, model2_serial_w ) - AM_RANGE(0x11000000, 0x111fffff) AM_RAM AM_BASE(&model2_textureram0) // texture RAM 0 (2b/2c) - AM_RANGE(0x11200000, 0x113fffff) AM_RAM AM_BASE(&model2_textureram1) // texture RAM 1 (2b/2c) - AM_RANGE(0x11400000, 0x1140ffff) AM_RAM AM_BASE(&model2_lumaram) // polygon "luma" RAM (2b/2c) + AM_RANGE(0x11000000, 0x111fffff) AM_RAM AM_BASE_MEMBER(model2_state, textureram0) // texture RAM 0 (2b/2c) + AM_RANGE(0x11200000, 0x113fffff) AM_RAM AM_BASE_MEMBER(model2_state, textureram1) // texture RAM 1 (2b/2c) + AM_RANGE(0x11400000, 0x1140ffff) AM_RAM AM_BASE_MEMBER(model2_state, lumaram) // polygon "luma" RAM (2b/2c) AM_RANGE(0x01c00000, 0x01c00003) AM_READ_PORT("1c00000") AM_WRITE( ctrl0_w ) AM_RANGE(0x01c00004, 0x01c00007) AM_READ_PORT("1c00004") @@ -1777,18 +1788,19 @@ INPUT_PORTS_END static INTERRUPT_GEN(model2_interrupt) { + model2_state *state = device->machine->driver_data(); switch (cpu_getiloops(device)) { case 0: - model2_intreq |= (1<<10); - if (model2_intena & (1<<10)) + state->intreq |= (1<<10); + if (state->intena & (1<<10)) { cpu_set_input_line(device, I960_IRQ3, ASSERT_LINE); } break; case 1: - model2_intreq |= (1<<0); - if (model2_intena & (1<<0)) + state->intreq |= (1<<0); + if (state->intena & (1<<0)) { cpu_set_input_line(device, I960_IRQ0, ASSERT_LINE); } @@ -1798,22 +1810,23 @@ static INTERRUPT_GEN(model2_interrupt) static INTERRUPT_GEN(model2c_interrupt) { + model2_state *state = device->machine->driver_data(); switch (cpu_getiloops(device)) { case 0: - model2_intreq |= (1<<10); - if (model2_intena & (1<<10)) + state->intreq |= (1<<10); + if (state->intena & (1<<10)) cpu_set_input_line(device, I960_IRQ3, ASSERT_LINE); break; case 1: - model2_intreq |= (1<<2); - if (model2_intena & (1<<2)) + state->intreq |= (1<<2); + if (state->intena & (1<<2)) cpu_set_input_line(device, I960_IRQ2, ASSERT_LINE); break; case 2: - model2_intreq |= (1<<0); - if (model2_intena & (1<<0)) + state->intreq |= (1<<0); + if (state->intena & (1<<0)) cpu_set_input_line(device, I960_IRQ0, ASSERT_LINE); break; } @@ -1823,7 +1836,8 @@ static INTERRUPT_GEN(model2c_interrupt) static READ16_HANDLER( m1_snd_68k_latch_r ) { - return to_68k; + model2_state *state = space->machine->driver_data(); + return state->to_68k; } static READ16_HANDLER( m1_snd_v60_ready_r ) @@ -1880,7 +1894,7 @@ static WRITE16_HANDLER( model2snd_ctrl ) } static ADDRESS_MAP_START( model2_snd, ADDRESS_SPACE_PROGRAM, 16 ) - AM_RANGE(0x000000, 0x07ffff) AM_RAM AM_REGION("audiocpu", 0) AM_BASE(&model2_soundram) + AM_RANGE(0x000000, 0x07ffff) AM_RAM AM_REGION("audiocpu", 0) AM_BASE_MEMBER(model2_state, soundram) AM_RANGE(0x100000, 0x100fff) AM_DEVREADWRITE("scsp", scsp_r, scsp_w) AM_RANGE(0x400000, 0x400001) AM_WRITE(model2snd_ctrl) AM_RANGE(0x600000, 0x67ffff) AM_ROM AM_REGION("audiocpu", 0x80000) @@ -1889,13 +1903,13 @@ static ADDRESS_MAP_START( model2_snd, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0xe00000, 0xffffff) AM_ROMBANK("bank5") ADDRESS_MAP_END -static int scsp_last_line = 0; static void scsp_irq(device_t *device, int irq) { + model2_state *state = device->machine->driver_data(); if (irq > 0) { - scsp_last_line = irq; + state->scsp_last_line = irq; cputag_set_input_line(device->machine, "audiocpu", irq, ASSERT_LINE); } else @@ -1930,13 +1944,15 @@ static WRITE32_HANDLER(copro_sharc_output_fifo_w) static READ32_HANDLER(copro_sharc_buffer_r) { - return model2_bufferram[offset & 0x7fff]; + model2_state *state = space->machine->driver_data(); + return state->bufferram[offset & 0x7fff]; } static WRITE32_HANDLER(copro_sharc_buffer_w) { + model2_state *state = space->machine->driver_data(); //mame_printf_debug("sharc_buffer_w: %08X at %08X, %08X, %f\n", offset, cpu_get_pc(space->cpu), data, *(float*)&data); - model2_bufferram[offset & 0x7fff] = data; + state->bufferram[offset & 0x7fff] = data; } static ADDRESS_MAP_START( copro_sharc_map, ADDRESS_SPACE_DATA, 32 ) @@ -1956,16 +1972,18 @@ ADDRESS_MAP_END static READ32_HANDLER(copro_tgp_buffer_r) { - return model2_bufferram[offset & 0x7fff]; + model2_state *state = space->machine->driver_data(); + return state->bufferram[offset & 0x7fff]; } static WRITE32_HANDLER(copro_tgp_buffer_w) { - model2_bufferram[offset&0x7fff] = data; + model2_state *state = space->machine->driver_data(); + state->bufferram[offset&0x7fff] = data; } static ADDRESS_MAP_START( copro_tgp_map, ADDRESS_SPACE_PROGRAM, 32 ) - AM_RANGE(0x00000000, 0x00007fff) AM_RAM AM_BASE(&tgp_program) + AM_RANGE(0x00000000, 0x00007fff) AM_RAM AM_BASE_MEMBER(model2_state, tgp_program) AM_RANGE(0x00400000, 0x00407fff) AM_READWRITE(copro_tgp_buffer_r, copro_tgp_buffer_w) AM_RANGE(0xff800000, 0xff9fffff) AM_ROM AM_REGION("tgp", 0) ADDRESS_MAP_END @@ -1982,7 +2000,7 @@ static const mb86233_cpu_core tgp_config = /* original Model 2 */ -static MACHINE_CONFIG_START( model2o, driver_device ) +static MACHINE_CONFIG_START( model2o, model2_state ) MCFG_CPU_ADD("maincpu", I960, 25000000) MCFG_CPU_PROGRAM_MAP(model2o_mem) MCFG_CPU_VBLANK_INT_HACK(model2_interrupt,2) @@ -1994,6 +2012,7 @@ static MACHINE_CONFIG_START( model2o, driver_device ) MCFG_CPU_CONFIG(tgp_config) MCFG_CPU_PROGRAM_MAP(copro_tgp_map) + MCFG_MACHINE_START(model2) MCFG_MACHINE_RESET(model2o) MCFG_EEPROM_93C46_ADD("eeprom") @@ -2039,7 +2058,7 @@ static MACHINE_CONFIG_START( model2o, driver_device ) MACHINE_CONFIG_END /* 2A-CRX */ -static MACHINE_CONFIG_START( model2a, driver_device ) +static MACHINE_CONFIG_START( model2a, model2_state ) MCFG_CPU_ADD("maincpu", I960, 25000000) MCFG_CPU_PROGRAM_MAP(model2a_crx_mem) MCFG_CPU_VBLANK_INT_HACK(model2_interrupt,2) @@ -2051,6 +2070,7 @@ static MACHINE_CONFIG_START( model2a, driver_device ) MCFG_CPU_CONFIG(tgp_config) MCFG_CPU_PROGRAM_MAP(copro_tgp_map) + MCFG_MACHINE_START(model2) MCFG_MACHINE_RESET(model2) MCFG_EEPROM_93C46_ADD("eeprom") @@ -2089,7 +2109,8 @@ MACHINE_CONFIG_END static READ8_HANDLER( driveio_port_r ) { - return driveio_comm_data; + model2_state *state = space->machine->driver_data(); + return state->driveio_comm_data; } static WRITE8_HANDLER( driveio_port_w ) @@ -2134,7 +2155,7 @@ static const sharc_config sharc_cfg = }; /* 2B-CRX */ -static MACHINE_CONFIG_START( model2b, driver_device ) +static MACHINE_CONFIG_START( model2b, model2_state ) MCFG_CPU_ADD("maincpu", I960, 25000000) MCFG_CPU_PROGRAM_MAP(model2b_crx_mem) MCFG_CPU_VBLANK_INT_HACK(model2_interrupt,2) @@ -2152,6 +2173,7 @@ static MACHINE_CONFIG_START( model2b, driver_device ) MCFG_QUANTUM_TIME(attotime::from_hz(18000)) + MCFG_MACHINE_START(model2) MCFG_MACHINE_RESET(model2b) MCFG_EEPROM_93C46_ADD("eeprom") @@ -2189,7 +2211,7 @@ static MACHINE_CONFIG_START( model2b, driver_device ) MACHINE_CONFIG_END /* 2C-CRX */ -static MACHINE_CONFIG_START( model2c, driver_device ) +static MACHINE_CONFIG_START( model2c, model2_state ) MCFG_CPU_ADD("maincpu", I960, 25000000) MCFG_CPU_PROGRAM_MAP(model2c_crx_mem) MCFG_CPU_VBLANK_INT_HACK(model2c_interrupt,3) @@ -2197,6 +2219,7 @@ static MACHINE_CONFIG_START( model2c, driver_device ) MCFG_CPU_ADD("audiocpu", M68000, 12000000) MCFG_CPU_PROGRAM_MAP(model2_snd) + MCFG_MACHINE_START(model2) MCFG_MACHINE_RESET(model2c) MCFG_EEPROM_93C46_ADD("eeprom") @@ -4971,16 +4994,18 @@ ROM_END static DRIVER_INIT( genprot ) { + model2_state *state = machine->driver_data(); memory_install_readwrite32_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x01d80000, 0x01dfffff, 0, 0, model2_prot_r, model2_prot_w); - protstate = protpos = 0; + state->protstate = state->protpos = 0; } static DRIVER_INIT( pltkids ) { + model2_state *state = machine->driver_data(); UINT32 *ROM = (UINT32 *)machine->region("maincpu")->base(); memory_install_readwrite32_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x01d80000, 0x01dfffff, 0, 0, model2_prot_r, model2_prot_w); - protstate = protpos = 0; + state->protstate = state->protpos = 0; // fix bug in program: it destroys the interrupt table and never fixes it ROM[0x730/4] = 0x08000004; @@ -4988,10 +5013,11 @@ static DRIVER_INIT( pltkids ) static DRIVER_INIT( zerogun ) { + model2_state *state = machine->driver_data(); UINT32 *ROM = (UINT32 *)machine->region("maincpu")->base(); memory_install_readwrite32_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x01d80000, 0x01dfffff, 0, 0, model2_prot_r, model2_prot_w); - protstate = protpos = 0; + state->protstate = state->protpos = 0; // fix bug in program: it destroys the interrupt table and never fixes it ROM[0x700/4] = 0x08000004; @@ -5003,40 +5029,42 @@ static DRIVER_INIT( daytonam ) } /* very crude support for let the game set itself into stand-alone mode */ -static int jnet_time_out; static READ32_HANDLER( jaleco_network_r ) { + model2_state *state = space->machine->driver_data(); if(offset == 0x4000/4) { - if(model2_netram[offset] == 0x00000000) - jnet_time_out = 0; + if(state->netram[offset] == 0x00000000) + state->jnet_time_out = 0; - if((model2_netram[offset] & 0xffff) == 0x0001) - jnet_time_out++; + if((state->netram[offset] & 0xffff) == 0x0001) + state->jnet_time_out++; - if(jnet_time_out > 0x80) - model2_netram[offset]|= 0x00800000; + if(state->jnet_time_out > 0x80) + state->netram[offset]|= 0x00800000; - return model2_netram[offset]; + return state->netram[offset]; } - return model2_netram[offset]; + return state->netram[offset]; } static WRITE32_HANDLER( jaleco_network_w ) { - COMBINE_DATA(&model2_netram[offset]); + model2_state *state = space->machine->driver_data(); + COMBINE_DATA(&state->netram[offset]); } static DRIVER_INIT( sgt24h ) { + model2_state *state = machine->driver_data(); UINT32 *ROM = (UINT32 *)machine->region("maincpu")->base(); memory_install_readwrite32_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x01d80000, 0x01dfffff, 0, 0, model2_prot_r, model2_prot_w); memory_install_readwrite32_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x01a10000, 0x01a1ffff, 0, 0, jaleco_network_r, jaleco_network_w); - protstate = protpos = 0; + state->protstate = state->protpos = 0; ROM[0x56578/4] = 0x08000004; ROM[0x5b3e8/4] = 0x08000004; @@ -5052,10 +5080,11 @@ static DRIVER_INIT( overrev ) static DRIVER_INIT( doa ) { + model2_state *state = machine->driver_data(); UINT32 *ROM = (UINT32 *)machine->region("maincpu")->base(); memory_install_readwrite32_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x01d80000, 0x01dfffff, 0, 0, model2_prot_r, model2_prot_w); - protstate = protpos = 0; + state->protstate = state->protpos = 0; ROM[0x630/4] = 0x08000004; ROM[0x808/4] = 0x08000004; diff --git a/src/mame/drivers/model3.c b/src/mame/drivers/model3.c index f744c1afde5..f26172e6e87 100644 --- a/src/mame/drivers/model3.c +++ b/src/mame/drivers/model3.c @@ -607,50 +607,47 @@ ALL VROM ROMs are 16M MASK #include "sound/scsp.h" #include "includes/model3.h" -static UINT8 irq_enable; -static UINT8 irq_state; -static UINT8 scsi_irq_state; - -int model3_step; -UINT32 *model3_vrom; - -static UINT64 *work_ram; -static int model3_crom_bank = 0; -static int model3_controls_bank; -static UINT32 real3d_device_id; static void real3d_dma_callback(running_machine *machine, UINT32 src, UINT32 dst, int length, int byteswap); -static UINT16 *model3_soundram; static void update_irq_state(running_machine *machine) { - if ((irq_enable & irq_state) || scsi_irq_state) + model3_state *state = machine->driver_data(); + if ((state->irq_enable & state->irq_state) || state->scsi_irq_state) { -// printf("IRQ set: state %x enable %x scsi %x\n", irq_state, irq_enable, scsi_irq_state); +// printf("IRQ set: state %x enable %x scsi %x\n", state->irq_state, state->irq_enable, state->scsi_irq_state); cputag_set_input_line(machine, "maincpu", PPC_IRQ, ASSERT_LINE); - scsi_irq_state = 0; + state->scsi_irq_state = 0; } else { -// printf("IRQ clear: state %x enable %x scsi %x\n", irq_state, irq_enable, scsi_irq_state); +// printf("IRQ clear: state %x enable %x scsi %x\n", state->irq_state, state->irq_enable, state->scsi_irq_state); cputag_set_input_line(machine, "maincpu", PPC_IRQ, CLEAR_LINE); } } -void model3_set_irq_line(running_machine *machine, UINT8 bit, int state) +void model3_set_irq_line(running_machine *machine, UINT8 bit, int line) { - if (state != CLEAR_LINE) - irq_state |= bit; + model3_state *state = machine->driver_data(); + if (line != CLEAR_LINE) + state->irq_state |= bit; else - irq_state &= ~bit; + state->irq_state &= ~bit; update_irq_state(machine); } -static UINT32 pci_device_get_reg(int device, int reg) +/*****************************************************************************/ +/* Motorola MPC105 PCI Bridge/Memory Controller */ + + +static UINT32 pci_device_get_reg(model3_state *state) { + int device = state->pci_device; + int reg = state->pci_reg; + switch(device) { case 11: /* ??? */ @@ -665,7 +662,7 @@ static UINT32 pci_device_get_reg(int device, int reg) case 13: /* Real3D Controller chip */ switch(reg) { - case 0: return real3d_device_id; /* PCI Vendor ID & Device ID */ + case 0: return state->real3d_device_id; /* PCI Vendor ID & Device ID */ default: logerror("pci_device_get_reg: Real3D controller, unknown reg %02X", reg); break; @@ -699,8 +696,11 @@ static UINT32 pci_device_get_reg(int device, int reg) return 0; } -static void pci_device_set_reg(int device, int reg, UINT32 value) +static void pci_device_set_reg(model3_state *state, UINT32 value) { + int device = state->pci_device; + int reg = state->pci_reg; + switch(device) { case 11: /* Unknown device for now !!! */ @@ -769,184 +769,186 @@ static void pci_device_set_reg(int device, int reg, UINT32 value) } } -/*****************************************************************************/ -/* Motorola MPC105 PCI Bridge/Memory Controller */ - -static UINT32 mpc105_regs[0x40]; -static UINT32 mpc105_addr; -static int pci_bus; -static int pci_device; -static int pci_function; -static int pci_reg; - static READ64_HANDLER( mpc105_addr_r ) { + model3_state *state = space->machine->driver_data(); if (ACCESSING_BITS_32_63) { - return (UINT64)mpc105_addr << 32; + return (UINT64)state->mpc105_addr << 32; } return 0; } static WRITE64_HANDLER( mpc105_addr_w ) { + model3_state *state = space->machine->driver_data(); if (ACCESSING_BITS_32_63) { UINT32 d = FLIPENDIAN_INT32((UINT32)(data >> 32)); - mpc105_addr = data >> 32; + state->mpc105_addr = data >> 32; - pci_bus = (d >> 16) & 0xff; - pci_device = (d >> 11) & 0x1f; - pci_function = (d >> 8) & 0x7; - pci_reg = (d >> 2) & 0x3f; + state->pci_bus = (d >> 16) & 0xff; + state->pci_device = (d >> 11) & 0x1f; + state->pci_function = (d >> 8) & 0x7; + state->pci_reg = (d >> 2) & 0x3f; } } static READ64_HANDLER( mpc105_data_r ) { - if(pci_device == 0) { - return ((UINT64)(FLIPENDIAN_INT32(mpc105_regs[(pci_reg/2)+1])) << 32) | - ((UINT64)(FLIPENDIAN_INT32(mpc105_regs[(pci_reg/2)+0]))); + model3_state *state = space->machine->driver_data(); + if(state->pci_device == 0) { + return ((UINT64)(FLIPENDIAN_INT32(state->mpc105_regs[(state->pci_reg/2)+1])) << 32) | + ((UINT64)(FLIPENDIAN_INT32(state->mpc105_regs[(state->pci_reg/2)+0]))); } - return FLIPENDIAN_INT32(pci_device_get_reg(pci_device, pci_reg)); + return FLIPENDIAN_INT32(pci_device_get_reg(state)); } static WRITE64_HANDLER( mpc105_data_w ) { - if(pci_device == 0) { - mpc105_regs[(pci_reg/2)+1] = FLIPENDIAN_INT32((UINT32)(data >> 32)); - mpc105_regs[(pci_reg/2)+0] = FLIPENDIAN_INT32((UINT32)(data)); + model3_state *state = space->machine->driver_data(); + if(state->pci_device == 0) { + state->mpc105_regs[(state->pci_reg/2)+1] = FLIPENDIAN_INT32((UINT32)(data >> 32)); + state->mpc105_regs[(state->pci_reg/2)+0] = FLIPENDIAN_INT32((UINT32)(data)); return; } if (ACCESSING_BITS_0_31) { - pci_device_set_reg(pci_device, pci_reg, FLIPENDIAN_INT32((UINT32)data)); + pci_device_set_reg(state, FLIPENDIAN_INT32((UINT32)data)); } } static READ64_HANDLER( mpc105_reg_r ) { - return ((UINT64)(mpc105_regs[(offset*2)+0]) << 32) | - (UINT64)(mpc105_regs[(offset*2)+1]); + model3_state *state = space->machine->driver_data(); + return ((UINT64)(state->mpc105_regs[(offset*2)+0]) << 32) | + (UINT64)(state->mpc105_regs[(offset*2)+1]); } static WRITE64_HANDLER( mpc105_reg_w ) { - mpc105_regs[(offset*2)+0] = (UINT32)(data >> 32); - mpc105_regs[(offset*2)+1] = (UINT32)data; + model3_state *state = space->machine->driver_data(); + state->mpc105_regs[(offset*2)+0] = (UINT32)(data >> 32); + state->mpc105_regs[(offset*2)+1] = (UINT32)data; } -static void mpc105_init(void) +static void mpc105_init(running_machine *machine) { + model3_state *state = machine->driver_data(); /* set reset values */ - memset(mpc105_regs, 0, sizeof(mpc105_regs)); - mpc105_regs[0x00/4] = 0x00011057; /* Vendor ID & Device ID */ - mpc105_regs[0x04/4] = 0x00800006; /* PCI Command & PCI Status */ - mpc105_regs[0x08/4] = 0x00060000; /* Class code */ - mpc105_regs[0xa8/4] = 0x0010ff00; /* Processor interface configuration 1 */ - mpc105_regs[0xac/4] = 0x060c000c; /* Processor interface configuration 2 */ - mpc105_regs[0xb8/4] = 0x04000000; - mpc105_regs[0xf0/4] = 0x0000ff02; /* Memory control configuration 1 */ - mpc105_regs[0xf4/4] = 0x00030000; /* Memory control configuration 2 */ - mpc105_regs[0xfc/4] = 0x00000010; /* Memory control configuration 4 */ + memset(state->mpc105_regs, 0, sizeof(state->mpc105_regs)); + state->mpc105_regs[0x00/4] = 0x00011057; /* Vendor ID & Device ID */ + state->mpc105_regs[0x04/4] = 0x00800006; /* PCI Command & PCI Status */ + state->mpc105_regs[0x08/4] = 0x00060000; /* Class code */ + state->mpc105_regs[0xa8/4] = 0x0010ff00; /* Processor interface configuration 1 */ + state->mpc105_regs[0xac/4] = 0x060c000c; /* Processor interface configuration 2 */ + state->mpc105_regs[0xb8/4] = 0x04000000; + state->mpc105_regs[0xf0/4] = 0x0000ff02; /* Memory control configuration 1 */ + state->mpc105_regs[0xf4/4] = 0x00030000; /* Memory control configuration 2 */ + state->mpc105_regs[0xfc/4] = 0x00000010; /* Memory control configuration 4 */ } /*****************************************************************************/ /* Motorola MPC106 PCI Bridge/Memory Controller */ -static UINT32 mpc106_regs[0x40]; -static UINT32 mpc106_addr; static READ64_HANDLER( mpc106_addr_r ) { + model3_state *state = space->machine->driver_data(); if (ACCESSING_BITS_32_63) { - return (UINT64)mpc106_addr << 32; + return (UINT64)state->mpc106_addr << 32; } return 0; } static WRITE64_HANDLER( mpc106_addr_w ) { + model3_state *state = space->machine->driver_data(); if (ACCESSING_BITS_32_63) { UINT32 d = FLIPENDIAN_INT32((UINT32)(data >> 32)); if (((d >> 8) & 0xffffff) == 0x800000) { - mpc106_addr = d & 0xff; + state->mpc106_addr = d & 0xff; } else { - mpc106_addr = data >> 32; + state->mpc106_addr = data >> 32; - pci_bus = (d >> 16) & 0xff; - pci_device = (d >> 11) & 0x1f; - pci_function = (d >> 8) & 0x7; - pci_reg = (d >> 2) & 0x3f; + state->pci_bus = (d >> 16) & 0xff; + state->pci_device = (d >> 11) & 0x1f; + state->pci_function = (d >> 8) & 0x7; + state->pci_reg = (d >> 2) & 0x3f; } } } static READ64_HANDLER( mpc106_data_r ) { - if(pci_device == 0) { - return ((UINT64)(FLIPENDIAN_INT32(mpc106_regs[(pci_reg/2)+1])) << 32) | - ((UINT64)(FLIPENDIAN_INT32(mpc106_regs[(pci_reg/2)+0]))); + model3_state *state = space->machine->driver_data(); + if(state->pci_device == 0) { + return ((UINT64)(FLIPENDIAN_INT32(state->mpc106_regs[(state->pci_reg/2)+1])) << 32) | + ((UINT64)(FLIPENDIAN_INT32(state->mpc106_regs[(state->pci_reg/2)+0]))); } if (ACCESSING_BITS_32_63) { - return (UINT64)(FLIPENDIAN_INT32(pci_device_get_reg(pci_device, pci_reg))) << 32; + return (UINT64)(FLIPENDIAN_INT32(pci_device_get_reg(state))) << 32; } else { - return (UINT64)(FLIPENDIAN_INT32(pci_device_get_reg(pci_device, pci_reg))); + return (UINT64)(FLIPENDIAN_INT32(pci_device_get_reg(state))); } } static WRITE64_HANDLER( mpc106_data_w ) { - if(pci_device == 0) { - mpc106_regs[(pci_reg/2)+1] = FLIPENDIAN_INT32((UINT32)(data >> 32)); - mpc106_regs[(pci_reg/2)+0] = FLIPENDIAN_INT32((UINT32)(data)); + model3_state *state = space->machine->driver_data(); + if(state->pci_device == 0) { + state->mpc106_regs[(state->pci_reg/2)+1] = FLIPENDIAN_INT32((UINT32)(data >> 32)); + state->mpc106_regs[(state->pci_reg/2)+0] = FLIPENDIAN_INT32((UINT32)(data)); return; } if (ACCESSING_BITS_0_31) { - pci_device_set_reg(pci_device, pci_reg, FLIPENDIAN_INT32((UINT32)data)); + pci_device_set_reg(state, FLIPENDIAN_INT32((UINT32)data)); } } static READ64_HANDLER( mpc106_reg_r ) { - return ((UINT64)(mpc106_regs[(offset*2)+0]) << 32) | - (UINT64)(mpc106_regs[(offset*2)+1]); + model3_state *state = space->machine->driver_data(); + return ((UINT64)(state->mpc106_regs[(offset*2)+0]) << 32) | + (UINT64)(state->mpc106_regs[(offset*2)+1]); } static WRITE64_HANDLER( mpc106_reg_w ) { - mpc106_regs[(offset*2)+0] = (UINT32)(data >> 32); - mpc106_regs[(offset*2)+1] = (UINT32)data; + model3_state *state = space->machine->driver_data(); + state->mpc106_regs[(offset*2)+0] = (UINT32)(data >> 32); + state->mpc106_regs[(offset*2)+1] = (UINT32)data; } -static void mpc106_init(void) +static void mpc106_init(running_machine *machine) { + model3_state *state = machine->driver_data(); /* set reset values */ - memset(mpc106_regs, 0, sizeof(mpc106_regs)); - mpc106_regs[0x00/4] = 0x00021057; /* Vendor ID & Device ID */ - mpc106_regs[0x04/4] = 0x00800006; /* PCI Command & PCI Status */ - mpc106_regs[0x08/4] = 0x00060000; /* Class code */ - mpc106_regs[0x0c/4] = 0x00000800; /* Cache line size */ - mpc106_regs[0x70/4] = 0x00cd0000; /* Output driver control */ - mpc106_regs[0xa8/4] = 0x0010ff00; /* Processor interface configuration 1 */ - mpc106_regs[0xac/4] = 0x060c000c; /* Processor interface configuration 2 */ - mpc106_regs[0xb8/4] = 0x04000000; - mpc106_regs[0xc0/4] = 0x00000100; /* Error enabling 1 */ - mpc106_regs[0xe0/4] = 0x00420fff; /* Emulation support configuration 1 */ - mpc106_regs[0xe8/4] = 0x00200000; /* Emulation support configuration 2 */ - mpc106_regs[0xf0/4] = 0x0000ff02; /* Memory control configuration 1 */ - mpc106_regs[0xf4/4] = 0x00030000; /* Memory control configuration 2 */ - mpc106_regs[0xfc/4] = 0x00000010; /* Memory control configuration 4 */ + memset(state->mpc106_regs, 0, sizeof(state->mpc106_regs)); + state->mpc106_regs[0x00/4] = 0x00021057; /* Vendor ID & Device ID */ + state->mpc106_regs[0x04/4] = 0x00800006; /* PCI Command & PCI Status */ + state->mpc106_regs[0x08/4] = 0x00060000; /* Class code */ + state->mpc106_regs[0x0c/4] = 0x00000800; /* Cache line size */ + state->mpc106_regs[0x70/4] = 0x00cd0000; /* Output driver control */ + state->mpc106_regs[0xa8/4] = 0x0010ff00; /* Processor interface configuration 1 */ + state->mpc106_regs[0xac/4] = 0x060c000c; /* Processor interface configuration 2 */ + state->mpc106_regs[0xb8/4] = 0x04000000; + state->mpc106_regs[0xc0/4] = 0x00000100; /* Error enabling 1 */ + state->mpc106_regs[0xe0/4] = 0x00420fff; /* Emulation support configuration 1 */ + state->mpc106_regs[0xe8/4] = 0x00200000; /* Emulation support configuration 2 */ + state->mpc106_regs[0xf0/4] = 0x0000ff02; /* Memory control configuration 1 */ + state->mpc106_regs[0xf4/4] = 0x00030000; /* Memory control configuration 2 */ + state->mpc106_regs[0xfc/4] = 0x00000010; /* Memory control configuration 4 */ } /*****************************************************************************/ @@ -1022,29 +1024,25 @@ static UINT32 scsi_fetch(running_machine *machine, UINT32 dsp) static void scsi_irq_callback(running_machine *machine, int state) { - scsi_irq_state = state; + model3_state *drvstate = machine->driver_data(); + drvstate->scsi_irq_state = state; update_irq_state(machine); } /*****************************************************************************/ /* Real3D DMA */ -static UINT32 dma_data; -static UINT32 dma_status; -static UINT32 dma_source; -static UINT32 dma_dest; -static UINT32 dma_endian; -static UINT32 dma_irq; static READ64_HANDLER( real3d_dma_r ) { + model3_state *state = space->machine->driver_data(); switch(offset) { case 1: - return (dma_irq << 24) | (dma_endian << 8); + return (state->dma_irq << 24) | (state->dma_endian << 8); case 2: if(ACCESSING_BITS_0_31) { - return dma_data; + return state->dma_data; } break; } @@ -1054,15 +1052,16 @@ static READ64_HANDLER( real3d_dma_r ) static WRITE64_HANDLER( real3d_dma_w ) { + model3_state *state = space->machine->driver_data(); switch(offset) { case 0: if(ACCESSING_BITS_32_63) { /* DMA source address */ - dma_source = FLIPENDIAN_INT32((UINT32)(data >> 32)); + state->dma_source = FLIPENDIAN_INT32((UINT32)(data >> 32)); return; } if(ACCESSING_BITS_0_31) { /* DMA destination address */ - dma_dest = FLIPENDIAN_INT32((UINT32)(data)); + state->dma_dest = FLIPENDIAN_INT32((UINT32)(data)); return; } break; @@ -1070,29 +1069,29 @@ static WRITE64_HANDLER( real3d_dma_w ) if(ACCESSING_BITS_32_63) /* DMA length */ { int length = FLIPENDIAN_INT32((UINT32)(data >> 32)) * 4; - if (dma_endian & 0x80) + if (state->dma_endian & 0x80) { - real3d_dma_callback(space->machine, dma_source, dma_dest, length, 0); + real3d_dma_callback(space->machine, state->dma_source, state->dma_dest, length, 0); } else { - real3d_dma_callback(space->machine, dma_source, dma_dest, length, 1); + real3d_dma_callback(space->machine, state->dma_source, state->dma_dest, length, 1); } - dma_irq |= 0x01; + state->dma_irq |= 0x01; scsi_irq_callback(space->machine, 1); return; } else if(ACCESSING_BITS_16_23) { if(data & 0x10000) { - dma_irq &= ~0x1; + state->dma_irq &= ~0x1; scsi_irq_callback(space->machine, 0); } return; } else if(ACCESSING_BITS_8_15) { - dma_endian = (data >> 8) & 0xff; + state->dma_endian = (data >> 8) & 0xff; return; } break; @@ -1100,16 +1099,16 @@ static WRITE64_HANDLER( real3d_dma_w ) if(ACCESSING_BITS_32_63) { /* DMA command */ UINT32 cmd = FLIPENDIAN_INT32((UINT32)(data >> 32)); if(cmd & 0x20000000) { - dma_data = FLIPENDIAN_INT32(real3d_device_id); /* (PCI Vendor & Device ID) */ + state->dma_data = FLIPENDIAN_INT32(state->real3d_device_id); /* (PCI Vendor & Device ID) */ } else if(cmd & 0x80000000) { - dma_status ^= 0xffffffff; - dma_data = dma_status; + state->dma_status ^= 0xffffffff; + state->dma_data = state->dma_status; } return; } if(ACCESSING_BITS_0_31) { /* ??? */ - dma_data = 0xffffffff; + state->dma_data = 0xffffffff; return; } return; @@ -1187,11 +1186,12 @@ static void model3_exit(running_machine &machine) static void configure_fast_ram(running_machine *machine) { + model3_state *state = machine->driver_data(); /* set conservative DRC options */ ppcdrc_set_options(machine->device("maincpu"), PPCDRC_COMPATIBLE_OPTIONS - PPCDRC_ACCURATE_SINGLES); /* configure fast RAM regions for DRC */ - ppcdrc_add_fastram(machine->device("maincpu"), 0x00000000, 0x007fffff, FALSE, work_ram); + ppcdrc_add_fastram(machine->device("maincpu"), 0x00000000, 0x007fffff, FALSE, state->work_ram); } static MACHINE_START(model3_10) @@ -1217,44 +1217,45 @@ static MACHINE_START(model3_21) static void model3_init(running_machine *machine, int step) { - model3_step = step; + model3_state *state = machine->driver_data(); + state->step = step; memory_set_bankptr(machine, "bank1", machine->region( "user1" )->base() + 0x800000 ); /* banked CROM */ memory_set_bankptr(machine, "bank4", machine->region("samples")->base() + 0x200000); memory_set_bankptr(machine, "bank5", machine->region("samples")->base() + 0x600000); // copy the 68k vector table into RAM - memcpy(model3_soundram, machine->region("audiocpu")->base()+0x80000, 16); + memcpy(state->soundram, machine->region("audiocpu")->base()+0x80000, 16); machine->device("audiocpu")->reset(); - model3_machine_init(step); // step 1.5 - model3_tap_reset(); + model3_machine_init(machine, step); // step 1.5 + model3_tap_reset(machine); if(step < 0x20) { if( mame_stricmp(machine->gamedrv->name, "vs215") == 0 || mame_stricmp(machine->gamedrv->name, "vs29815") == 0 || mame_stricmp(machine->gamedrv->name, "bass") == 0 ) { - mpc106_init(); + mpc106_init(machine); } else { - mpc105_init(); + mpc105_init(machine); } - real3d_device_id = 0x16c311db; /* PCI Vendor ID (11db = SEGA), Device ID (16c3 = 315-5827) */ + state->real3d_device_id = 0x16c311db; /* PCI Vendor ID (11db = SEGA), Device ID (16c3 = 315-5827) */ } else { - mpc106_init(); + mpc106_init(machine); // some step 2+ games need the older PCI ID (obvious symptom: // vbl is enabled briefly then disabled so the game hangs) if (mame_stricmp(machine->gamedrv->name, "magtruck") == 0 || mame_stricmp(machine->gamedrv->name, "von254g") == 0) { - real3d_device_id = 0x16c311db; /* PCI Vendor ID (11db = SEGA), Device ID (16c3 = 315-5827) */ + state->real3d_device_id = 0x16c311db; /* PCI Vendor ID (11db = SEGA), Device ID (16c3 = 315-5827) */ } else { - real3d_device_id = 0x178611db; /* PCI Vendor ID (11db = SEGA), Device ID (1786 = 315-6022) */ + state->real3d_device_id = 0x178611db; /* PCI Vendor ID (11db = SEGA), Device ID (1786 = 315-6022) */ } } } @@ -1264,25 +1265,20 @@ static MACHINE_RESET(model3_15) { model3_init(machine, 0x15); } static MACHINE_RESET(model3_20) { model3_init(machine, 0x20); } static MACHINE_RESET(model3_21) { model3_init(machine, 0x21); } -static UINT64 controls_2; -static UINT64 controls_3; -static UINT8 model3_serial_fifo1; -static UINT8 model3_serial_fifo2; -static int lightgun_reg_sel; -static int adc_channel; static READ64_HANDLER( model3_ctrl_r ) { + model3_state *state = space->machine->driver_data(); switch( offset ) { case 0: if (ACCESSING_BITS_56_63) { - return (UINT64)model3_controls_bank << 56; + return (UINT64)state->controls_bank << 56; } else if (ACCESSING_BITS_24_31) { - if(model3_controls_bank & 0x1) + if(state->controls_bank & 0x1) { return (input_port_read(space->machine, "IN1")) << 24; } @@ -1316,14 +1312,14 @@ static READ64_HANDLER( model3_ctrl_r ) case 5: if (ACCESSING_BITS_24_31) /* Serial comm RX FIFO 1 */ { - return (UINT64)model3_serial_fifo1 << 24; + return (UINT64)state->serial_fifo1 << 24; } break; case 6: if (ACCESSING_BITS_56_63) /* Serial comm RX FIFO 2 */ { - return (UINT64)model3_serial_fifo2 << 56; + return (UINT64)state->serial_fifo2 << 56; } else if (ACCESSING_BITS_24_31) /* Serial comm full/empty flags */ { @@ -1335,9 +1331,9 @@ static READ64_HANDLER( model3_ctrl_r ) if (ACCESSING_BITS_24_31) /* ADC Data read */ { static const char *const adcnames[] = { "AN0", "AN1", "AN2", "AN3", "AN4", "AN5", "AN6", "AN7" }; - UINT8 adc_data = input_port_read_safe(space->machine, adcnames[adc_channel], 0); - adc_channel++; - adc_channel &= 0x7; + UINT8 adc_data = input_port_read_safe(space->machine, adcnames[state->adc_channel], 0); + state->adc_channel++; + state->adc_channel &= 0x7; return (UINT64)adc_data << 24; } break; @@ -1349,6 +1345,7 @@ static READ64_HANDLER( model3_ctrl_r ) static WRITE64_HANDLER( model3_ctrl_w ) { + model3_state *state = space->machine->driver_data(); switch(offset) { case 0: @@ -1359,16 +1356,16 @@ static WRITE64_HANDLER( model3_ctrl_w ) eeprom_write_bit(device, (reg & 0x20) ? 1 : 0); eeprom_set_clock_line(device, (reg & 0x80) ? ASSERT_LINE : CLEAR_LINE); eeprom_set_cs_line(device, (reg & 0x40) ? CLEAR_LINE : ASSERT_LINE); - model3_controls_bank = reg & 0xff; + state->controls_bank = reg & 0xff; } return; case 2: - COMBINE_DATA(&controls_2); + COMBINE_DATA(&state->controls_2); return; case 3: - COMBINE_DATA(&controls_3); + COMBINE_DATA(&state->controls_3); return; case 4: @@ -1381,40 +1378,40 @@ static WRITE64_HANDLER( model3_ctrl_w ) switch(data >> 24) { case 0x00: - lightgun_reg_sel = model3_serial_fifo2; + state->lightgun_reg_sel = state->serial_fifo2; break; case 0x87: - model3_serial_fifo1 = 0; - switch(lightgun_reg_sel) /* read lightrun register */ + state->serial_fifo1 = 0; + switch(state->lightgun_reg_sel) /* read lightrun register */ { case 0: /* player 1 gun X-position, lower 8-bits */ - model3_serial_fifo2 = input_port_read(space->machine, "LIGHT0_Y") & 0xff; + state->serial_fifo2 = input_port_read(space->machine, "LIGHT0_Y") & 0xff; break; case 1: /* player 1 gun X-position, upper 2-bits */ - model3_serial_fifo2 = (input_port_read(space->machine, "LIGHT0_Y") >> 8) & 0x3; + state->serial_fifo2 = (input_port_read(space->machine, "LIGHT0_Y") >> 8) & 0x3; break; case 2: /* player 1 gun Y-position, lower 8-bits */ - model3_serial_fifo2 = input_port_read(space->machine, "LIGHT0_X") & 0xff; + state->serial_fifo2 = input_port_read(space->machine, "LIGHT0_X") & 0xff; break; case 3: /* player 1 gun Y-position, upper 2-bits */ - model3_serial_fifo2 = (input_port_read(space->machine, "LIGHT0_X") >> 8) & 0x3; + state->serial_fifo2 = (input_port_read(space->machine, "LIGHT0_X") >> 8) & 0x3; break; case 4: /* player 2 gun X-position, lower 8-bits */ - model3_serial_fifo2 = input_port_read(space->machine, "LIGHT1_Y") & 0xff; + state->serial_fifo2 = input_port_read(space->machine, "LIGHT1_Y") & 0xff; break; case 5: /* player 2 gun X-position, upper 2-bits */ - model3_serial_fifo2 = (input_port_read(space->machine, "LIGHT1_Y") >> 8) & 0x3; + state->serial_fifo2 = (input_port_read(space->machine, "LIGHT1_Y") >> 8) & 0x3; break; case 6: /* player 2 gun Y-position, lower 8-bits */ - model3_serial_fifo2 = input_port_read(space->machine, "LIGHT1_X") & 0xff; + state->serial_fifo2 = input_port_read(space->machine, "LIGHT1_X") & 0xff; break; case 7: /* player 2 gun Y-position, upper 2-bits */ - model3_serial_fifo2 = (input_port_read(space->machine, "LIGHT1_X") >> 8) & 0x3; + state->serial_fifo2 = (input_port_read(space->machine, "LIGHT1_X") >> 8) & 0x3; break; case 8: /* gun offscreen (bit set = gun offscreen, bit clear = gun on screen) */ - model3_serial_fifo2 = 0; /* bit 0 = player 1, bit 1 = player 2 */ + state->serial_fifo2 = 0; /* bit 0 = player 1, bit 1 = player 2 */ if(input_port_read(space->machine, "OFFSCREEN") & 0x1) { - model3_serial_fifo2 |= 0x01; + state->serial_fifo2 |= 0x01; } break; } @@ -1429,7 +1426,7 @@ static WRITE64_HANDLER( model3_ctrl_w ) case 5: if (ACCESSING_BITS_56_63) /* Serial comm TX FIFO 2 */ { - model3_serial_fifo2 = data >> 56; + state->serial_fifo2 = data >> 56; return; } break; @@ -1437,7 +1434,7 @@ static WRITE64_HANDLER( model3_ctrl_w ) case 7: if (ACCESSING_BITS_24_31) /* ADC Channel selection */ { - adc_channel = (data >> 24) & 0xf; + state->adc_channel = (data >> 24) & 0xf; } return; } @@ -1447,6 +1444,7 @@ static WRITE64_HANDLER( model3_ctrl_w ) static READ64_HANDLER( model3_sys_r ) { + model3_state *state = space->machine->driver_data(); // printf("model3_sys_r: mask %llx @ %x (PC %x)\n", mem_mask, offset, cpu_get_pc(space->cpu)); switch (offset) @@ -1454,26 +1452,26 @@ static READ64_HANDLER( model3_sys_r ) case 0x08/8: if (ACCESSING_BITS_56_63) { - return ((UINT64)model3_crom_bank << 56); + return ((UINT64)state->crom_bank << 56); } break; case 0x10/8: if (ACCESSING_BITS_56_63) { - UINT64 res = model3_tap_read(); + UINT64 res = model3_tap_read(space->machine); return res<<61; } else if (ACCESSING_BITS_24_31) { - return (irq_enable<<24); + return (state->irq_enable<<24); } else logerror("m3_sys: Unk sys_r @ 0x10: mask = %x\n", (UINT32)mem_mask); break; case 0x18/8: -// printf("read irq_state %x (PC %x)\n", irq_state, cpu_get_pc(space->cpu)); - return (UINT64)irq_state<<56 | 0xff000000; +// printf("read state->irq_state %x (PC %x)\n", state->irq_state, cpu_get_pc(space->cpu)); + return (UINT64)state->irq_state<<56 | 0xff000000; break; } @@ -1483,6 +1481,7 @@ static READ64_HANDLER( model3_sys_r ) static WRITE64_HANDLER( model3_sys_w ) { + model3_state *state = space->machine->driver_data(); // printf("model3_sys_w: %llx to %x mask %llx\n", data, offset, mem_mask); switch (offset) @@ -1490,14 +1489,14 @@ static WRITE64_HANDLER( model3_sys_w ) case 0x10/8: if (ACCESSING_BITS_24_31) { - irq_enable = (data>>24)&0xff; + state->irq_enable = (data>>24)&0xff; } else logerror("m3_sys: unknown mask on IRQen write\n"); break; case 0x18/8: if ((mem_mask & 0xff000000) == 0xff000000) // int ACK with bits in REVERSE ORDER from the other registers (Seeeee-gaaaa!) { // may also be a secondary enable based on behavior of e.g. magtruck VBL handler -// UINT32 old_irq = irq_state; +// UINT32 old_irq = state->irq_state; UINT8 ack = (data>>24)&0xff, realack; int i; @@ -1519,7 +1518,7 @@ static WRITE64_HANDLER( model3_sys_w ) // printf("%x to ack (realack %x)\n", ack, realack); - irq_state &= realack; + state->irq_state &= realack; break; } } @@ -1531,7 +1530,7 @@ static WRITE64_HANDLER( model3_sys_w ) case 0x08/8: if (ACCESSING_BITS_56_63) { - model3_crom_bank = data >> 56; + state->crom_bank = data >> 56; data >>= 56; data = (~data) & 0x7; @@ -1541,7 +1540,7 @@ static WRITE64_HANDLER( model3_sys_w ) if (ACCESSING_BITS_24_31) { data >>= 24; - model3_tap_write( + model3_tap_write(space->machine, (data >> 6) & 1,// TCK (data >> 2) & 1,// TMS (data >> 5) & 1,// TDI @@ -1574,19 +1573,19 @@ static WRITE64_HANDLER( model3_rtc_w ) } } -static UINT64 real3d_status = 0; static READ64_HANDLER(real3d_status_r) { - real3d_status ^= U64(0xffffffffffffffff); + model3_state *state = space->machine->driver_data(); + state->real3d_status ^= U64(0xffffffffffffffff); if (offset == 0) { /* pretty sure this is VBLANK */ - real3d_status &= ~U64(0x0000000200000000); + state->real3d_status &= ~U64(0x0000000200000000); if (space->machine->primary_screen->vblank()) - real3d_status |= U64(0x0000000200000000); - return real3d_status; + state->real3d_status |= U64(0x0000000200000000); + return state->real3d_status; } - return real3d_status; + return state->real3d_status; } /* SCSP interface */ @@ -1614,20 +1613,20 @@ static WRITE64_HANDLER(model3_sound_w) -static UINT64 network_ram[0x10000]; static READ64_HANDLER(network_r) { + model3_state *state = space->machine->driver_data(); mame_printf_debug("network_r: %02X at %08X\n", offset, cpu_get_pc(space->cpu)); - return network_ram[offset]; + return state->network_ram[offset]; } static WRITE64_HANDLER(network_w) { - COMBINE_DATA(network_ram + offset); + model3_state *state = space->machine->driver_data(); + COMBINE_DATA(state->network_ram + offset); mame_printf_debug("network_w: %02X, %08X%08X at %08X\n", offset, (UINT32)(data >> 32), (UINT32)(data), cpu_get_pc(space->cpu)); } -static int prot_data_ptr = 0; static const UINT16 vs299_prot_data[] = { @@ -1701,6 +1700,7 @@ static const UINT16 eca_prot_data[] = static READ64_HANDLER(model3_security_r) { + model3_state *state = space->machine->driver_data(); switch(offset) { case 0x00/8: return 0; /* status */ @@ -1709,44 +1709,44 @@ static READ64_HANDLER(model3_security_r) if (mame_stricmp(space->machine->gamedrv->name, "vs299") == 0 || mame_stricmp(space->machine->gamedrv->name, "vs2v991") == 0) { - return (UINT64)vs299_prot_data[prot_data_ptr++] << 48; + return (UINT64)vs299_prot_data[state->prot_data_ptr++] << 48; } else if (mame_stricmp(space->machine->gamedrv->name, "swtrilgy") == 0 || mame_stricmp(space->machine->gamedrv->name, "swtrilgya") == 0) { - UINT64 data = (UINT64)swt_prot_data[prot_data_ptr++] << 16; - if (prot_data_ptr > 0x38) + UINT64 data = (UINT64)swt_prot_data[state->prot_data_ptr++] << 16; + if (state->prot_data_ptr > 0x38) { - prot_data_ptr = 0; + state->prot_data_ptr = 0; } return data; } else if (mame_stricmp(space->machine->gamedrv->name, "fvipers2") == 0) { - UINT64 data = (UINT64)fvipers2_prot_data[prot_data_ptr++] << 16; - if (prot_data_ptr >= 0x41) + UINT64 data = (UINT64)fvipers2_prot_data[state->prot_data_ptr++] << 16; + if (state->prot_data_ptr >= 0x41) { - prot_data_ptr = 0; + state->prot_data_ptr = 0; } return data; } else if (mame_stricmp(space->machine->gamedrv->name, "spikeout") == 0 || mame_stricmp(space->machine->gamedrv->name, "spikeofe") == 0) { - UINT64 data = (UINT64)spikeout_prot_data[prot_data_ptr++] << 16; - if (prot_data_ptr >= 0x55) + UINT64 data = (UINT64)spikeout_prot_data[state->prot_data_ptr++] << 16; + if (state->prot_data_ptr >= 0x55) { - prot_data_ptr = 0; + state->prot_data_ptr = 0; } return data; } else if (mame_stricmp(space->machine->gamedrv->name, "eca") == 0 || mame_stricmp(space->machine->gamedrv->name, "ecax") == 0) { - UINT64 data = (UINT64)eca_prot_data[prot_data_ptr++] << 16; - if (prot_data_ptr >= 0x31) + UINT64 data = (UINT64)eca_prot_data[state->prot_data_ptr++] << 16; + if (state->prot_data_ptr >= 0x31) { - prot_data_ptr = 0; + state->prot_data_ptr = 0; } return data; } @@ -1771,7 +1771,7 @@ static WRITE64_HANDLER(daytona2_rombank_w) } static ADDRESS_MAP_START( model3_mem, ADDRESS_SPACE_PROGRAM, 64) - AM_RANGE(0x00000000, 0x007fffff) AM_RAM AM_BASE(&work_ram) /* work RAM */ + AM_RANGE(0x00000000, 0x007fffff) AM_RAM AM_BASE_MEMBER(model3_state, work_ram) /* work RAM */ AM_RANGE(0x84000000, 0x8400003f) AM_READ( real3d_status_r ) AM_RANGE(0x88000000, 0x88000007) AM_WRITE( real3d_cmd_w ) @@ -1788,7 +1788,7 @@ static ADDRESS_MAP_START( model3_mem, ADDRESS_SPACE_PROGRAM, 64) AM_RANGE(0xf1000000, 0xf10f7fff) AM_READWRITE( model3_char_r, model3_char_w ) /* character RAM */ AM_RANGE(0xf10f8000, 0xf10fffff) AM_READWRITE( model3_tile_r, model3_tile_w ) /* tilemaps */ - AM_RANGE(0xf1100000, 0xf111ffff) AM_READWRITE( model3_palette_r, model3_palette_w ) AM_BASE(&paletteram64) /* palette */ + AM_RANGE(0xf1100000, 0xf111ffff) AM_READWRITE( model3_palette_r, model3_palette_w ) AM_BASE_MEMBER(model3_state, paletteram64) /* palette */ AM_RANGE(0xf1180000, 0xf11800ff) AM_READWRITE( model3_vid_reg_r, model3_vid_reg_w ) AM_RANGE(0xff800000, 0xffffffff) AM_ROM AM_REGION("user1", 0) @@ -4891,7 +4891,7 @@ static WRITE16_HANDLER( model3snd_ctrl ) } static ADDRESS_MAP_START( model3_snd, ADDRESS_SPACE_PROGRAM, 16 ) - AM_RANGE(0x000000, 0x07ffff) AM_RAM AM_REGION("scsp1", 0) AM_BASE(&model3_soundram) + AM_RANGE(0x000000, 0x07ffff) AM_RAM AM_REGION("scsp1", 0) AM_BASE_MEMBER(model3_state, soundram) AM_RANGE(0x100000, 0x100fff) AM_DEVREADWRITE("scsp1", scsp_r, scsp_w) AM_RANGE(0x200000, 0x27ffff) AM_RAM AM_REGION("scsp2", 0) AM_RANGE(0x300000, 0x300fff) AM_DEVREADWRITE("scsp2", scsp_r, scsp_w) @@ -4902,13 +4902,13 @@ static ADDRESS_MAP_START( model3_snd, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0xe00000, 0xffffff) AM_ROMBANK("bank5") ADDRESS_MAP_END -static int scsp_last_line = 0; static void scsp_irq(device_t *device, int irq) { + model3_state *state = device->machine->driver_data(); if (irq > 0) { - scsp_last_line = irq; + state->scsp_last_line = irq; cputag_set_input_line(device->machine, "audiocpu", irq, ASSERT_LINE); } else @@ -4938,17 +4938,17 @@ static const scsp_interface scsp2_interface = 0x02: Video (VBLANK start?) 0x01: Video (unused?) */ -static int model3_vblank = 0; static INTERRUPT_GEN(model3_interrupt) { - if (model3_vblank == 0) { + model3_state *state = device->machine->driver_data(); + if (state->vblank == 0) { model3_set_irq_line(device->machine, 0x02, ASSERT_LINE); } else { model3_set_irq_line(device->machine, 0x0d, ASSERT_LINE); } - model3_vblank++; - model3_vblank &= 1; + state->vblank++; + state->vblank &= 1; } static const powerpc_config model3_10 = @@ -4969,7 +4969,7 @@ static const powerpc_config model3_2x = 66000000 /* Multiplier 2.5, Bus = 66MHz, Core = 166MHz */ }; -static MACHINE_CONFIG_START( model3_10, driver_device ) +static MACHINE_CONFIG_START( model3_10, model3_state ) MCFG_CPU_ADD("maincpu", PPC603E, 66000000) MCFG_CPU_CONFIG(model3_10) MCFG_CPU_PROGRAM_MAP(model3_mem) @@ -5011,7 +5011,7 @@ static MACHINE_CONFIG_START( model3_10, driver_device ) MCFG_SOUND_ROUTE(0, "rspeaker", 2.0) MACHINE_CONFIG_END -static MACHINE_CONFIG_START( model3_15, driver_device ) +static MACHINE_CONFIG_START( model3_15, model3_state ) MCFG_CPU_ADD("maincpu", PPC603E, 100000000) MCFG_CPU_CONFIG(model3_15) MCFG_CPU_PROGRAM_MAP(model3_mem) @@ -5051,7 +5051,7 @@ static MACHINE_CONFIG_START( model3_15, driver_device ) MCFG_SOUND_ROUTE(0, "rspeaker", 2.0) MACHINE_CONFIG_END -static MACHINE_CONFIG_START( model3_20, driver_device ) +static MACHINE_CONFIG_START( model3_20, model3_state ) MCFG_CPU_ADD("maincpu", PPC603R, 166000000) MCFG_CPU_CONFIG(model3_2x) MCFG_CPU_PROGRAM_MAP(model3_mem) @@ -5091,7 +5091,7 @@ static MACHINE_CONFIG_START( model3_20, driver_device ) MCFG_SOUND_ROUTE(0, "rspeaker", 2.0) MACHINE_CONFIG_END -static MACHINE_CONFIG_START( model3_21, driver_device ) +static MACHINE_CONFIG_START( model3_21, model3_state ) MCFG_CPU_ADD("maincpu", PPC603R, 166000000) MCFG_CPU_CONFIG(model3_2x) MCFG_CPU_PROGRAM_MAP(model3_mem) @@ -5134,6 +5134,7 @@ MACHINE_CONFIG_END static void interleave_vroms(running_machine *machine) { + model3_state *state = machine->driver_data(); int start; int i,j,x; UINT16 *vrom1 = (UINT16*)machine->region("user3")->base(); @@ -5141,8 +5142,8 @@ static void interleave_vroms(running_machine *machine) int vrom_length = machine->region("user3")->bytes(); UINT16 *vrom; - model3_vrom = auto_alloc_array(machine, UINT32, 0x4000000/4); - vrom = (UINT16 *)model3_vrom; + state->vrom = auto_alloc_array(machine, UINT32, 0x4000000/4); + vrom = (UINT16 *)state->vrom; if( vrom_length <= 0x1000000 ) { start = 0x1000000; @@ -5397,9 +5398,11 @@ static DRIVER_INIT( vs299 ) static DRIVER_INIT( harley ) { + model3_state *state = machine->driver_data(); UINT32 *rom = (UINT32*)machine->region("user1")->base(); DRIVER_INIT_CALL(model3_20); + state->network_ram = auto_alloc_array_clear(machine, UINT64, 0x10000); memory_install_readwrite64_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xc0000000, 0xc00fffff, 0, 0, network_r, network_w ); rom[(0x50e8d4^4)/4] = 0x60000000; diff --git a/src/mame/drivers/mystwarr.c b/src/mame/drivers/mystwarr.c index ab489808c07..91a1c920099 100644 --- a/src/mame/drivers/mystwarr.c +++ b/src/mame/drivers/mystwarr.c @@ -33,9 +33,7 @@ #include "includes/konamipt.h" #include "includes/mystwarr.h" -static UINT16 *gx_workram; -static UINT8 mw_irq_control; static const eeprom_interface eeprom_intf = { @@ -108,7 +106,8 @@ static WRITE16_HANDLER( mmeeprom_w ) static INTERRUPT_GEN(mystwarr_interrupt) { - if (!(mw_irq_control & 0x01)) return; + mystwarr_state *state = device->machine->driver_data(); + if (!(state->mw_irq_control & 0x01)) return; switch (cpu_getiloops(device)) { @@ -146,7 +145,8 @@ static INTERRUPT_GEN(metamrph_interrupt) static INTERRUPT_GEN(mchamp_interrupt) { - if (!(mw_irq_control & 0x02)) return; + mystwarr_state *state = device->machine->driver_data(); + if (!(state->mw_irq_control & 0x02)) return; switch (cpu_getiloops(device)) { @@ -215,11 +215,12 @@ static READ16_HANDLER( sound_status_msb_r ) static WRITE16_HANDLER( irq_ack_w ) { + mystwarr_state *state = space->machine->driver_data(); K056832_b_word_w(space, offset, data, mem_mask); if (offset == 3 && ACCESSING_BITS_0_7) { - mw_irq_control = data&0xff; + state->mw_irq_control = data&0xff; // if ((data &0xf0) != 0xd0) logerror("Unknown write to IRQ reg: %x\n", data); @@ -258,7 +259,7 @@ static WRITE16_HANDLER( K053247_scattered_word_w ) /* Mystic Warriors */ static ADDRESS_MAP_START( mystwarr_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x000000, 0x1fffff) AM_ROM // main program - AM_RANGE(0x200000, 0x20ffff) AM_RAM AM_BASE(&gx_workram) + AM_RANGE(0x200000, 0x20ffff) AM_RAM AM_BASE_MEMBER(mystwarr_state, gx_workram) AM_RANGE(0x400000, 0x40ffff) AM_READWRITE(K053247_scattered_word_r,K053247_scattered_word_w) AM_BASE_GENERIC(spriteram) AM_RANGE(0x480000, 0x4800ff) AM_WRITE(K055555_word_w) AM_RANGE(0x482000, 0x48200f) AM_READ(K055673_rom_word_r) @@ -296,7 +297,7 @@ ADDRESS_MAP_END /* Metamorphic Force */ static ADDRESS_MAP_START( metamrph_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x000000, 0x1fffff) AM_ROM // main program - AM_RANGE(0x200000, 0x20ffff) AM_RAM AM_BASE(&gx_workram) + AM_RANGE(0x200000, 0x20ffff) AM_RAM AM_BASE_MEMBER(mystwarr_state, gx_workram) AM_RANGE(0x210000, 0x210fff) AM_READWRITE(K053247_word_r,K053247_word_w) AM_RANGE(0x211000, 0x21ffff) AM_RAM AM_RANGE(0x240000, 0x240007) AM_WRITE(K053246_word_w) @@ -339,7 +340,7 @@ ADDRESS_MAP_END /* Violent Storm */ static ADDRESS_MAP_START( viostorm_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x000000, 0x1fffff) AM_ROM // main program - AM_RANGE(0x200000, 0x20ffff) AM_RAM AM_BASE(&gx_workram) + AM_RANGE(0x200000, 0x20ffff) AM_RAM AM_BASE_MEMBER(mystwarr_state, gx_workram) AM_RANGE(0x210000, 0x210fff) AM_READWRITE(K053247_word_r,K053247_word_w) AM_RANGE(0x211000, 0x21ffff) AM_RAM AM_RANGE(0x240000, 0x240007) AM_WRITE(K053246_word_w) @@ -408,14 +409,16 @@ static WRITE16_HANDLER( K053247_martchmp_word_w ) static READ16_HANDLER( mccontrol_r ) { - return mw_irq_control<<8; + mystwarr_state *state = space->machine->driver_data(); + return state->mw_irq_control<<8; } static WRITE16_HANDLER( mccontrol_w ) { + mystwarr_state *state = space->machine->driver_data(); if (ACCESSING_BITS_8_15) { - mw_irq_control = data>>8; + state->mw_irq_control = data>>8; // bit 0 = watchdog // bit 1 = IRQ enable // bit 2 = OBJCHA @@ -433,7 +436,7 @@ static WRITE16_HANDLER( mccontrol_w ) /* Martial Champion */ static ADDRESS_MAP_START( martchmp_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x000000, 0x0fffff) AM_ROM // main program - AM_RANGE(0x100000, 0x10ffff) AM_RAM AM_BASE(&gx_workram) // work RAM + AM_RANGE(0x100000, 0x10ffff) AM_RAM AM_BASE_MEMBER(mystwarr_state, gx_workram) // work RAM AM_RANGE(0x300000, 0x3fffff) AM_ROM // data ROM AM_RANGE(0x400000, 0x4000ff) AM_WRITE(K055555_word_w) // PCU2 AM_RANGE(0x402000, 0x40200f) AM_READ(K055673_rom_word_r) // sprite ROM readback @@ -496,7 +499,7 @@ static ADDRESS_MAP_START( dadandrn_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x48c000, 0x48c01f) AM_WRITE(K054338_word_w) AM_RANGE(0x48e000, 0x48e001) AM_READ_PORT("IN0_P1") // bit 3 (0x8) is test switch AM_RANGE(0x48e020, 0x48e021) AM_READ(dddeeprom_r) - AM_RANGE(0x600000, 0x60ffff) AM_RAM AM_BASE(&gx_workram) + AM_RANGE(0x600000, 0x60ffff) AM_RAM AM_BASE_MEMBER(mystwarr_state, gx_workram) AM_RANGE(0x680000, 0x68003f) AM_READWRITE(K055550_word_r,K055550_word_w) AM_RANGE(0x6a0000, 0x6a0001) AM_WRITE(mmeeprom_w) AM_RANGE(0x6c0000, 0x6c0001) AM_WRITE(ddd_053936_enable_w) @@ -544,7 +547,7 @@ static ADDRESS_MAP_START( gaiapols_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x48c000, 0x48c01f) AM_WRITE(K054338_word_w) AM_RANGE(0x48e000, 0x48e001) AM_READ_PORT("IN0_P1") // bit 3 (0x8) is test switch AM_RANGE(0x48e020, 0x48e021) AM_READ(dddeeprom_r) - AM_RANGE(0x600000, 0x60ffff) AM_RAM AM_BASE(&gx_workram) + AM_RANGE(0x600000, 0x60ffff) AM_RAM AM_BASE_MEMBER(mystwarr_state, gx_workram) AM_RANGE(0x660000, 0x6600ff) AM_READWRITE(K054000_lsb_r,K054000_lsb_w) AM_RANGE(0x6a0000, 0x6a0001) AM_WRITE(mmeeprom_w) AM_RANGE(0x6c0000, 0x6c0001) AM_WRITE(ddd_053936_enable_w) @@ -566,16 +569,17 @@ ADDRESS_MAP_END /**********************************************************************************/ -static int cur_sound_region; static void reset_sound_region(running_machine *machine) { - memory_set_bankptr(machine, "bank2", machine->region("soundcpu")->base() + 0x10000 + cur_sound_region*0x4000); + mystwarr_state *state = machine->driver_data(); + memory_set_bankptr(machine, "bank2", machine->region("soundcpu")->base() + 0x10000 + state->cur_sound_region*0x4000); } static WRITE8_HANDLER( sound_bankswitch_w ) { - cur_sound_region = (data & 0xf); + mystwarr_state *state = space->machine->driver_data(); + state->cur_sound_region = (data & 0xf); reset_sound_region(space->machine); } @@ -857,14 +861,15 @@ static STATE_POSTLOAD( mystwarr_postload ) static MACHINE_START( mystwarr ) { + mystwarr_state *state = machine->driver_data(); /* set default bankswitch */ - cur_sound_region = 2; + state->cur_sound_region = 2; reset_sound_region(machine); - mw_irq_control = 0; + state->mw_irq_control = 0; - state_save_register_global(machine, mw_irq_control); - state_save_register_global(machine, cur_sound_region); + state_save_register_global(machine, state->mw_irq_control); + state_save_register_global(machine, state->cur_sound_region); machine->state().register_postload(mystwarr_postload, NULL); } @@ -939,7 +944,7 @@ static MACHINE_RESET(gaiapols) for (i=5; i<=7; i++) k054539_set_gain(k054539_1, i, 2.0); } -static MACHINE_CONFIG_START( mystwarr, driver_device ) +static MACHINE_CONFIG_START( mystwarr, mystwarr_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu", M68000, 16000000) /* 16 MHz (confirmed) */ diff --git a/src/mame/drivers/nwk-tr.c b/src/mame/drivers/nwk-tr.c index e3fad144b85..15325296604 100644 --- a/src/mame/drivers/nwk-tr.c +++ b/src/mame/drivers/nwk-tr.c @@ -225,9 +225,25 @@ Thrill Drive 713A13 - 713A14 - #include "video/voodoo.h" #include "video/konicdev.h" -static UINT8 led_reg0, led_reg1; -static UINT32 *work_ram; +class nwktr_state : public driver_device +{ +public: + nwktr_state(running_machine &machine, const driver_device_config_base &config) + : driver_device(machine, config) { } + + UINT8 led_reg0; + UINT8 led_reg1; + UINT32 *work_ram; + int fpga_uploaded; + int lanc2_ram_r; + int lanc2_ram_w; + UINT8 *lanc2_ram; + UINT32 *sharc_dataram; +}; + + + static WRITE32_HANDLER( paletteram32_w ) @@ -245,6 +261,7 @@ static void voodoo_vblank_0(device_t *device, int param) static VIDEO_UPDATE( nwktr ) { + nwktr_state *state = screen->machine->driver_data(); device_t *voodoo = screen->machine->device("voodoo"); device_t *k001604 = screen->machine->device("k001604"); @@ -254,8 +271,8 @@ static VIDEO_UPDATE( nwktr ) k001604_draw_front_layer(k001604, bitmap, cliprect); - draw_7segment_led(bitmap, 3, 3, led_reg0); - draw_7segment_led(bitmap, 9, 3, led_reg1); + draw_7segment_led(bitmap, 3, 3, state->led_reg0); + draw_7segment_led(bitmap, 9, 3, state->led_reg1); return 0; } @@ -296,16 +313,17 @@ static READ32_HANDLER( sysreg_r ) static WRITE32_HANDLER( sysreg_w ) { + nwktr_state *state = space->machine->driver_data(); device_t *adc12138 = space->machine->device("adc12138"); if( offset == 0 ) { if (ACCESSING_BITS_24_31) { - led_reg0 = (data >> 24) & 0xff; + state->led_reg0 = (data >> 24) & 0xff; } if (ACCESSING_BITS_16_23) { - led_reg1 = (data >> 16) & 0xff; + state->led_reg1 = (data >> 16) & 0xff; } return; } @@ -338,28 +356,26 @@ static WRITE32_HANDLER( sysreg_w ) } } -static int fpga_uploaded = 0; -static int lanc2_ram_r = 0; -static int lanc2_ram_w = 0; -static UINT8 *lanc2_ram; static void lanc2_init(running_machine *machine) { - fpga_uploaded = 0; - lanc2_ram_r = 0; - lanc2_ram_w = 0; - lanc2_ram = auto_alloc_array(machine, UINT8, 0x8000); + nwktr_state *state = machine->driver_data(); + state->fpga_uploaded = 0; + state->lanc2_ram_r = 0; + state->lanc2_ram_w = 0; + state->lanc2_ram = auto_alloc_array(machine, UINT8, 0x8000); } static READ32_HANDLER( lanc1_r ) { + nwktr_state *state = space->machine->driver_data(); switch (offset) { case 0x40/4: { UINT32 r = 0; - r |= (fpga_uploaded) ? (1 << 6) : 0; + r |= (state->fpga_uploaded) ? (1 << 6) : 0; r |= 1 << 5; return (r) << 24; @@ -380,14 +396,15 @@ static WRITE32_HANDLER( lanc1_w ) static READ32_HANDLER( lanc2_r ) { + nwktr_state *state = space->machine->driver_data(); UINT32 r = 0; if (offset == 0) { if (ACCESSING_BITS_0_7) { - r |= lanc2_ram[lanc2_ram_r & 0x7fff]; - lanc2_ram_r++; + r |= state->lanc2_ram[state->lanc2_ram_r & 0x7fff]; + state->lanc2_ram_r++; } else { @@ -410,6 +427,7 @@ static READ32_HANDLER( lanc2_r ) static WRITE32_HANDLER( lanc2_w ) { + nwktr_state *state = space->machine->driver_data(); if (offset == 0) { if (ACCESSING_BITS_24_31) @@ -425,14 +443,14 @@ static WRITE32_HANDLER( lanc2_w ) ((value << 5) & 0x40) | ((value << 7) & 0x80); - fpga_uploaded = 1; + state->fpga_uploaded = 1; //printf("lanc2_fpga_w: %02X at %08X\n", value, cpu_get_pc(space->cpu)); } else if (ACCESSING_BITS_0_7) { - lanc2_ram[lanc2_ram_w & 0x7fff] = data & 0xff; - lanc2_ram_w++; + state->lanc2_ram[state->lanc2_ram_w & 0x7fff] = data & 0xff; + state->lanc2_ram_w++; } else { @@ -443,15 +461,15 @@ static WRITE32_HANDLER( lanc2_w ) { if (mame_stricmp(space->machine->gamedrv->name, "thrilld") == 0) { - work_ram[(0x3ffed0/4) + 0] = 0x472a3731; - work_ram[(0x3ffed0/4) + 1] = 0x33202020; - work_ram[(0x3ffed0/4) + 2] = 0x2d2d2a2a; - work_ram[(0x3ffed0/4) + 3] = 0x2a207878; + state->work_ram[(0x3ffed0/4) + 0] = 0x472a3731; + state->work_ram[(0x3ffed0/4) + 1] = 0x33202020; + state->work_ram[(0x3ffed0/4) + 2] = 0x2d2d2a2a; + state->work_ram[(0x3ffed0/4) + 3] = 0x2a207878; - work_ram[(0x3fff40/4) + 0] = 0x47433731; - work_ram[(0x3fff40/4) + 1] = 0x33000000; - work_ram[(0x3fff40/4) + 2] = 0x19994a41; - work_ram[(0x3fff40/4) + 3] = 0x4100a9b1; + state->work_ram[(0x3fff40/4) + 0] = 0x47433731; + state->work_ram[(0x3fff40/4) + 1] = 0x33000000; + state->work_ram[(0x3fff40/4) + 2] = 0x19994a41; + state->work_ram[(0x3fff40/4) + 3] = 0x4100a9b1; } } @@ -462,15 +480,16 @@ static WRITE32_HANDLER( lanc2_w ) static MACHINE_START( nwktr ) { + nwktr_state *state = machine->driver_data(); /* set conservative DRC options */ ppcdrc_set_options(machine->device("maincpu"), PPCDRC_COMPATIBLE_OPTIONS); /* configure fast RAM regions for DRC */ - ppcdrc_add_fastram(machine->device("maincpu"), 0x00000000, 0x003fffff, FALSE, work_ram); + ppcdrc_add_fastram(machine->device("maincpu"), 0x00000000, 0x003fffff, FALSE, state->work_ram); } static ADDRESS_MAP_START( nwktr_map, ADDRESS_SPACE_PROGRAM, 32 ) - AM_RANGE(0x00000000, 0x003fffff) AM_RAM AM_BASE(&work_ram) /* Work RAM */ + AM_RANGE(0x00000000, 0x003fffff) AM_RAM AM_BASE_MEMBER(nwktr_state, work_ram) /* Work RAM */ AM_RANGE(0x74000000, 0x740000ff) AM_DEVREADWRITE("k001604", k001604_reg_r, k001604_reg_w) AM_RANGE(0x74010000, 0x74017fff) AM_RAM_WRITE(paletteram32_w) AM_BASE_GENERIC(paletteram) AM_RANGE(0x74020000, 0x7403ffff) AM_DEVREADWRITE("k001604", k001604_tile_r, k001604_tile_w) @@ -502,16 +521,17 @@ ADDRESS_MAP_END /*****************************************************************************/ -static UINT32 *sharc_dataram; static READ32_HANDLER( dsp_dataram_r ) { - return sharc_dataram[offset] & 0xffff; + nwktr_state *state = space->machine->driver_data(); + return state->sharc_dataram[offset] & 0xffff; } static WRITE32_HANDLER( dsp_dataram_w ) { - sharc_dataram[offset] = data; + nwktr_state *state = space->machine->driver_data(); + state->sharc_dataram[offset] = data; } static ADDRESS_MAP_START( sharc_map, ADDRESS_SPACE_DATA, 32 ) @@ -652,7 +672,7 @@ static MACHINE_RESET( nwktr ) cputag_set_input_line(machine, "dsp", INPUT_LINE_RESET, ASSERT_LINE); } -static MACHINE_CONFIG_START( nwktr, driver_device ) +static MACHINE_CONFIG_START( nwktr, nwktr_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu", PPC403GA, 64000000/2) /* PowerPC 403GA 32MHz */ @@ -715,11 +735,12 @@ MACHINE_CONFIG_END static DRIVER_INIT(nwktr) { + nwktr_state *state = machine->driver_data(); init_konami_cgboard(machine, 1, CGBOARD_TYPE_NWKTR); set_cgboard_texture_bank(machine, 0, "bank5", machine->region("user5")->base()); - sharc_dataram = auto_alloc_array(machine, UINT32, 0x100000/4); - led_reg0 = led_reg1 = 0x7f; + state->sharc_dataram = auto_alloc_array(machine, UINT32, 0x100000/4); + state->led_reg0 = state->led_reg1 = 0x7f; lanc2_init(machine); } diff --git a/src/mame/drivers/qdrmfgp.c b/src/mame/drivers/qdrmfgp.c index 1a49b68601c..c87e332bfcc 100644 --- a/src/mame/drivers/qdrmfgp.c +++ b/src/mame/drivers/qdrmfgp.c @@ -28,11 +28,6 @@ GP1 HDD data contents: #include "machine/nvram.h" #include "includes/qdrmfgp.h" -static UINT8 *sndram; -static UINT16 *workram; -static UINT16 control; -static INT32 qdrmfgp_pal; -static INT32 gp2_irq_control; /************************************* * @@ -42,9 +37,10 @@ static INT32 gp2_irq_control; static CUSTOM_INPUT( inputs_r ) { + qdrmfgp_state *state = field->port->machine->driver_data(); const char *tag1 = (const char *)param; const char *tag2 = tag1 + strlen(tag1) + 1; - return input_port_read(field->port->machine, (control & 0x0080) ? tag1 : tag2); + return input_port_read(field->port->machine, (state->control & 0x0080) ? tag1 : tag2); } static CUSTOM_INPUT( battery_sensor_r ) @@ -54,13 +50,10 @@ static CUSTOM_INPUT( battery_sensor_r ) } -int qdrmfgp_get_palette(void) -{ - return qdrmfgp_pal; -} - static WRITE16_HANDLER( gp_control_w ) { + qdrmfgp_state *state = space->machine->driver_data(); + /* bit 0 enable irq 1 (sound) */ /* bit 1 enable irq 2 (not used) */ /* bit 2 enable irq 3 (vblank) */ @@ -73,10 +66,10 @@ static WRITE16_HANDLER( gp_control_w ) /* bit 11 headphone volume: 1=up, 0=down */ /* bit 15 gfxrom bankswitch */ - COMBINE_DATA(&control); - qdrmfgp_pal = control & 0x70; + COMBINE_DATA(&state->control); + state->pal = state->control & 0x70; - if (control & 0x0100) + if (state->control & 0x0100) { qdrmfgp_state *state = space->machine->driver_data(); int vol = state->m_nvram[0x10] & 0xff; @@ -94,6 +87,8 @@ static WRITE16_HANDLER( gp_control_w ) static WRITE16_HANDLER( gp2_control_w ) { + qdrmfgp_state *state = space->machine->driver_data(); + /* bit 2 enable irq 3 (sound) */ /* bit 3 enable irq 4 (vblank) */ /* bit 4 enable irq 5 (hdd) */ @@ -104,10 +99,10 @@ static WRITE16_HANDLER( gp2_control_w ) /* bit 11 headphone volume: 1=up, 0=down */ /* bit 15 gfxrom bankswitch */ - COMBINE_DATA(&control); - qdrmfgp_pal = 0; + COMBINE_DATA(&state->control); + state->pal = 0; - if (control & 0x0100) + if (state->control & 0x0100) { qdrmfgp_state *state = space->machine->driver_data(); int vol = state->m_nvram[0x8] & 0xff; @@ -126,13 +121,14 @@ static WRITE16_HANDLER( gp2_control_w ) static READ16_HANDLER( v_rom_r ) { + qdrmfgp_state *state = space->machine->driver_data(); device_t *k056832 = space->machine->device("k056832"); UINT8 *mem8 = space->machine->region("gfx1")->base(); int bank = k056832_word_r(k056832, 0x34/2, 0xffff); offset += bank * 0x800 * 4; - if (control & 0x8000) + if (state->control & 0x8000) offset += 0x800 * 2; return (mem8[offset + 1] << 8) + mem8[offset]; @@ -184,19 +180,21 @@ static WRITE16_HANDLER( gp2_vram_mirror_w ) static READ16_HANDLER( sndram_r ) { + qdrmfgp_state *state = space->machine->driver_data(); if (ACCESSING_BITS_0_7) - return sndram[offset]; + return state->sndram[offset]; return 0; } static WRITE16_HANDLER( sndram_w ) { + qdrmfgp_state *state = space->machine->driver_data(); if (ACCESSING_BITS_0_7) { - sndram[offset] = data & 0xff; + state->sndram[offset] = data & 0xff; if (offset >= 0x40000) - sndram[offset+0xc00000-0x900000] = data & 0xff; + state->sndram[offset+0xc00000-0x900000] = data & 0xff; } } @@ -238,6 +236,7 @@ static WRITE16_DEVICE_HANDLER( ide_alt_w ) static READ16_HANDLER( gp2_ide_std_r ) { + qdrmfgp_state *state = space->machine->driver_data(); device_t *device = space->machine->device("ide"); if (offset & 0x01) { @@ -246,11 +245,11 @@ static READ16_HANDLER( gp2_ide_std_r ) switch (cpu_get_previouspc(space->cpu)) { case 0xdb4c: - if ((workram[0x5fa4/2] - cpu_get_reg(space->cpu, M68K_D0)) <= 0x10) - gp2_irq_control = 1; + if ((state->workram[0x5fa4/2] - cpu_get_reg(space->cpu, M68K_D0)) <= 0x10) + state->gp2_irq_control = 1; break; case 0xdec2: - gp2_irq_control = 1; + state->gp2_irq_control = 1; default: break; } @@ -270,16 +269,17 @@ static READ16_HANDLER( gp2_ide_std_r ) static INTERRUPT_GEN(qdrmfgp_interrupt) { + qdrmfgp_state *state = device->machine->driver_data(); switch (cpu_getiloops(device)) { case 0: - if (control & 0x0001) + if (state->control & 0x0001) cpu_set_input_line(device, 1, HOLD_LINE); break; case 1: /* trigger V-blank interrupt */ - if (control & 0x0004) + if (state->control & 0x0004) cpu_set_input_line(device, 3, HOLD_LINE); break; } @@ -287,7 +287,8 @@ static INTERRUPT_GEN(qdrmfgp_interrupt) static void ide_interrupt(device_t *device, int state) { - if (control & 0x0008) + qdrmfgp_state *drvstate = device->machine->driver_data(); + if (drvstate->control & 0x0008) { if (state != CLEAR_LINE) cputag_set_input_line(device->machine, "maincpu", 4, HOLD_LINE); @@ -300,25 +301,28 @@ static void ide_interrupt(device_t *device, int state) static TIMER_CALLBACK( gp2_timer_callback ) { - if (control & 0x0004) + qdrmfgp_state *state = machine->driver_data(); + if (state->control & 0x0004) cputag_set_input_line(machine, "maincpu", 3, HOLD_LINE); } static INTERRUPT_GEN(qdrmfgp2_interrupt) { + qdrmfgp_state *state = device->machine->driver_data(); /* trigger V-blank interrupt */ - if (control & 0x0008) + if (state->control & 0x0008) cpu_set_input_line(device, 4, HOLD_LINE); } static void gp2_ide_interrupt(device_t *device, int state) { - if (control & 0x0010) + qdrmfgp_state *drvstate = device->machine->driver_data(); + if (drvstate->control & 0x0010) { if (state != CLEAR_LINE) { - if (gp2_irq_control) - gp2_irq_control = 0; + if (drvstate->gp2_irq_control) + drvstate->gp2_irq_control = 0; else cputag_set_input_line(device->machine, "maincpu", 5, HOLD_LINE); } @@ -338,7 +342,7 @@ static void gp2_ide_interrupt(device_t *device, int state) static ADDRESS_MAP_START( qdrmfgp_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x000000, 0x0fffff) AM_ROM - AM_RANGE(0x100000, 0x10ffff) AM_RAM AM_BASE(&workram) /* work ram */ + AM_RANGE(0x100000, 0x10ffff) AM_RAM AM_BASE_MEMBER(qdrmfgp_state, workram) /* work ram */ AM_RANGE(0x180000, 0x183fff) AM_RAM AM_SHARE("nvram") /* backup ram */ AM_RANGE(0x280000, 0x280fff) AM_RAM_WRITE(paletteram16_xBBBBBGGGGGRRRRR_word_w) AM_BASE_GENERIC(paletteram) AM_RANGE(0x300000, 0x30003f) AM_DEVWRITE("k056832", k056832_word_w) /* video reg */ @@ -361,7 +365,7 @@ ADDRESS_MAP_END static ADDRESS_MAP_START( qdrmfgp2_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x000000, 0x0fffff) AM_ROM - AM_RANGE(0x100000, 0x110fff) AM_RAM AM_BASE(&workram) /* work ram */ + AM_RANGE(0x100000, 0x110fff) AM_RAM AM_BASE_MEMBER(qdrmfgp_state, workram) /* work ram */ AM_RANGE(0x180000, 0x183fff) AM_RAM AM_SHARE("nvram") /* backup ram */ AM_RANGE(0x280000, 0x280fff) AM_RAM_WRITE(paletteram16_xBBBBBGGGGGRRRRR_word_w) AM_BASE_GENERIC(paletteram) AM_RANGE(0x300000, 0x30003f) AM_DEVWRITE("k056832", k056832_word_w) /* video reg */ @@ -570,7 +574,8 @@ INPUT_PORTS_END static void sound_irq(device_t *device) { - if (control & 0x0001) + qdrmfgp_state *state = device->machine->driver_data(); + if (state->control & 0x0001) cputag_set_input_line(device->machine, "maincpu", 1, HOLD_LINE); } @@ -608,9 +613,10 @@ static const k056832_interface qdrmfgp2_k056832_intf = static MACHINE_START( qdrmfgp ) { - state_save_register_global(machine, control); - state_save_register_global(machine, qdrmfgp_pal); - state_save_register_global(machine, gp2_irq_control); + qdrmfgp_state *state = machine->driver_data(); + state_save_register_global(machine, state->control); + state_save_register_global(machine, state->pal); + state_save_register_global(machine, state->gp2_irq_control); } static MACHINE_START( qdrmfgp2 ) @@ -623,10 +629,11 @@ static MACHINE_START( qdrmfgp2 ) static MACHINE_RESET( qdrmfgp ) { - sndram = machine->region("konami")->base() + 0x100000; + qdrmfgp_state *state = machine->driver_data(); + state->sndram = machine->region("konami")->base() + 0x100000; /* reset the IDE controller */ - gp2_irq_control = 0; + state->gp2_irq_control = 0; devtag_reset(machine, "ide"); } diff --git a/src/mame/drivers/scobra.c b/src/mame/drivers/scobra.c index d542631edfb..6a4286f0a45 100644 --- a/src/mame/drivers/scobra.c +++ b/src/mame/drivers/scobra.c @@ -39,6 +39,17 @@ Notes/Tidbits: #include "includes/galaxold.h" #include "sound/ay8910.h" + +class scobra_state : public driver_device +{ +public: + scobra_state(running_machine &machine, const driver_device_config_base &config) + : driver_device(machine, config) { } + + UINT8 *soundram; +}; + + static const gfx_layout scobra_charlayout = { 8,8, @@ -302,22 +313,23 @@ static ADDRESS_MAP_START( anteatgb_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0xfe00, 0xfe03) AM_DEVREADWRITE("ppi8255_1", ppi8255_r, ppi8255_w) ADDRESS_MAP_END -static UINT8 *scobra_soundram; static READ8_HANDLER(scobra_soundram_r) { - return scobra_soundram[offset & 0x03ff]; + scobra_state *state = space->machine->driver_data(); + return state->soundram[offset & 0x03ff]; } static WRITE8_HANDLER(scobra_soundram_w) { - scobra_soundram[offset & 0x03ff] = data; + scobra_state *state = space->machine->driver_data(); + state->soundram[offset & 0x03ff] = data; } static ADDRESS_MAP_START( scobra_sound_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x0000, 0x2fff) AM_ROM AM_RANGE(0x8000, 0x8fff) AM_READWRITE(scobra_soundram_r, scobra_soundram_w) - AM_RANGE(0x8000, 0x83ff) AM_WRITENOP AM_BASE(&scobra_soundram) /* only here to initialize pointer */ + AM_RANGE(0x8000, 0x83ff) AM_WRITENOP AM_BASE_MEMBER(scobra_state, soundram) /* only here to initialize pointer */ AM_RANGE(0x9000, 0x9fff) AM_WRITE(scramble_filter_w) ADDRESS_MAP_END @@ -325,7 +337,7 @@ ADDRESS_MAP_END static ADDRESS_MAP_START( hustlerb_sound_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x0000, 0x2fff) AM_ROM AM_RANGE(0x6000, 0x6fff) AM_WRITE(frogger_filter_w) - AM_RANGE(0x8000, 0x8fff) AM_RAM_READ(scobra_soundram_r) AM_BASE(&scobra_soundram) /* only here to initialize pointer */ + AM_RANGE(0x8000, 0x8fff) AM_RAM_READ(scobra_soundram_r) AM_BASE_MEMBER(scobra_state, soundram) /* only here to initialize pointer */ ADDRESS_MAP_END @@ -850,7 +862,7 @@ static const ay8910_interface scobra_ay8910_interface_2 = }; -static MACHINE_CONFIG_START( type1, driver_device ) +static MACHINE_CONFIG_START( type1, scobra_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu", Z80, 18432000/6) /* 3.072 MHz */ @@ -975,7 +987,7 @@ static MACHINE_CONFIG_DERIVED( darkplnt, type2 ) MACHINE_CONFIG_END -static MACHINE_CONFIG_START( hustler, driver_device ) +static MACHINE_CONFIG_START( hustler, scobra_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu", Z80, 18432000/6) /* 3.072 MHz */ diff --git a/src/mame/drivers/segag80v.c b/src/mame/drivers/segag80v.c index df09fbf26c5..f4cf4664112 100644 --- a/src/mame/drivers/segag80v.c +++ b/src/mame/drivers/segag80v.c @@ -152,24 +152,6 @@ -/************************************* - * - * Global variables - * - *************************************/ - -static UINT8 *mainram; -static UINT8 has_usb; - -static UINT8 mult_data[2]; -static UINT16 mult_result; - -static UINT8 spinner_select; -static UINT8 spinner_sign; -static UINT8 spinner_count; - - - /************************************* * * Machine setup and config @@ -186,19 +168,21 @@ static INPUT_CHANGED( service_switch ) static MACHINE_START( g80v ) { + segag80v_state *state = machine->driver_data(); /* register for save states */ - state_save_register_global_array(machine, mult_data); - state_save_register_global(machine, mult_result); - state_save_register_global(machine, spinner_select); - state_save_register_global(machine, spinner_sign); - state_save_register_global(machine, spinner_count); + state_save_register_global_array(machine, state->mult_data); + state_save_register_global(machine, state->mult_result); + state_save_register_global(machine, state->spinner_select); + state_save_register_global(machine, state->spinner_sign); + state_save_register_global(machine, state->spinner_count); } static MACHINE_RESET( g80v ) { + segag80v_state *state = machine->driver_data(); /* if we have a Universal Sound Board, reset it here */ - if (has_usb) + if (state->has_usb) sega_usb_reset(machine, 0x10); } @@ -221,9 +205,11 @@ static offs_t decrypt_offset(address_space *space, offs_t offset) return (offset & 0xff00) | (*sega_decrypt)(pc, space->read_byte(pc + 1)); } -static WRITE8_HANDLER( mainram_w ) { mainram[decrypt_offset(space, offset)] = data; } +static WRITE8_HANDLER( mainram_w ) { + segag80v_state *state = space->machine->driver_data(); state->mainram[decrypt_offset(space, offset)] = data; } static WRITE8_HANDLER( usb_ram_w ) { sega_usb_ram_w(space, decrypt_offset(space, offset), data); } -static WRITE8_HANDLER( vectorram_w ) { segag80v_vectorram[decrypt_offset(space, offset)] = data; } +static WRITE8_HANDLER( vectorram_w ) { + segag80v_state *state = space->machine->driver_data(); state->vectorram[decrypt_offset(space, offset)] = data; } @@ -267,15 +253,17 @@ static READ8_HANDLER( mangled_ports_r ) static WRITE8_HANDLER( spinner_select_w ) { - spinner_select = data; + segag80v_state *state = space->machine->driver_data(); + state->spinner_select = data; } static READ8_HANDLER( spinner_input_r ) { + segag80v_state *state = space->machine->driver_data(); INT8 delta; - if (spinner_select & 1) + if (state->spinner_select & 1) return input_port_read(space->machine, "FC"); /* @@ -289,10 +277,10 @@ static READ8_HANDLER( spinner_input_r ) delta = input_port_read(space->machine, "SPINNER"); if (delta != 0) { - spinner_sign = (delta >> 7) & 1; - spinner_count += abs(delta); + state->spinner_sign = (delta >> 7) & 1; + state->spinner_count += abs(delta); } - return ~((spinner_count << 1) | spinner_sign); + return ~((state->spinner_count << 1) | state->spinner_sign); } @@ -311,13 +299,14 @@ static CUSTOM_INPUT( elim4_joint_coin_r ) static READ8_HANDLER( elim4_input_r ) { + segag80v_state *state = space->machine->driver_data(); UINT8 result = 0; /* bit 3 enables demux */ - if (spinner_select & 8) + if (state->spinner_select & 8) { /* Demux bit 0-2. Only 6 and 7 are connected */ - switch (spinner_select & 7) + switch (state->spinner_select & 7) { case 6: /* player 3 & 4 controls */ @@ -344,16 +333,18 @@ static READ8_HANDLER( elim4_input_r ) static WRITE8_HANDLER( multiply_w ) { - mult_data[offset] = data; + segag80v_state *state = space->machine->driver_data(); + state->mult_data[offset] = data; if (offset == 1) - mult_result = mult_data[0] * mult_data[1]; + state->mult_result = state->mult_data[0] * state->mult_data[1]; } static READ8_HANDLER( multiply_r ) { - UINT8 result = mult_result; - mult_result >>= 8; + segag80v_state *state = space->machine->driver_data(); + UINT8 result = state->mult_result; + state->mult_result >>= 8; return result; } @@ -392,8 +383,8 @@ static WRITE8_HANDLER( unknown_w ) static ADDRESS_MAP_START( main_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x0000, 0x07ff) AM_ROM /* CPU board ROM */ AM_RANGE(0x0800, 0xbfff) AM_ROM /* PROM board ROM area */ - AM_RANGE(0xc800, 0xcfff) AM_RAM_WRITE(mainram_w) AM_BASE(&mainram) - AM_RANGE(0xe000, 0xefff) AM_RAM_WRITE(vectorram_w) AM_BASE(&segag80v_vectorram) AM_SIZE(&segag80v_vectorram_size) + AM_RANGE(0xc800, 0xcfff) AM_RAM_WRITE(mainram_w) AM_BASE_MEMBER(segag80v_state, mainram) + AM_RANGE(0xe000, 0xefff) AM_RAM_WRITE(vectorram_w) AM_BASE_MEMBER(segag80v_state, vectorram) AM_SIZE_MEMBER(segag80v_state, vectorram_size) ADDRESS_MAP_END @@ -909,7 +900,7 @@ static const samples_interface zektor_samples_interface = * *************************************/ -static MACHINE_CONFIG_START( g80v_base, driver_device ) +static MACHINE_CONFIG_START( g80v_base, segag80v_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu", Z80, CPU_CLOCK/2) @@ -1310,13 +1301,14 @@ ROM_END static DRIVER_INIT( elim2 ) { + segag80v_state *state = machine->driver_data(); address_space *iospace = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_IO); /* configure security */ sega_security(70); /* configure sound */ - has_usb = FALSE; + state->has_usb = FALSE; memory_install_write8_handler(iospace, 0x3e, 0x3e, 0, 0, elim1_sh_w); memory_install_write8_handler(iospace, 0x3f, 0x3f, 0, 0, elim2_sh_w); } @@ -1324,13 +1316,14 @@ static DRIVER_INIT( elim2 ) static DRIVER_INIT( elim4 ) { + segag80v_state *state = machine->driver_data(); address_space *iospace = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_IO); /* configure security */ sega_security(76); /* configure sound */ - has_usb = FALSE; + state->has_usb = FALSE; memory_install_write8_handler(iospace, 0x3e, 0x3e, 0, 0, elim1_sh_w); memory_install_write8_handler(iospace, 0x3f, 0x3f, 0, 0, elim2_sh_w); @@ -1342,13 +1335,14 @@ static DRIVER_INIT( elim4 ) static DRIVER_INIT( spacfury ) { + segag80v_state *state = machine->driver_data(); address_space *iospace = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_IO); /* configure security */ sega_security(64); /* configure sound */ - has_usb = FALSE; + state->has_usb = FALSE; memory_install_write8_handler(iospace, 0x38, 0x38, 0, 0, sega_speech_data_w); memory_install_write8_handler(iospace, 0x3b, 0x3b, 0, 0, sega_speech_control_w); memory_install_write8_handler(iospace, 0x3e, 0x3e, 0, 0, spacfury1_sh_w); @@ -1358,6 +1352,7 @@ static DRIVER_INIT( spacfury ) static DRIVER_INIT( zektor ) { + segag80v_state *state = machine->driver_data(); address_space *iospace = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_IO); device_t *ay = machine->device("aysnd"); @@ -1365,7 +1360,7 @@ static DRIVER_INIT( zektor ) sega_security(82); /* configure sound */ - has_usb = FALSE; + state->has_usb = FALSE; memory_install_write8_handler(iospace, 0x38, 0x38, 0, 0, sega_speech_data_w); memory_install_write8_handler(iospace, 0x3b, 0x3b, 0, 0, sega_speech_control_w); memory_install_write8_device_handler(iospace, ay, 0x3c, 0x3d, 0, 0, ay8910_address_data_w); @@ -1380,6 +1375,7 @@ static DRIVER_INIT( zektor ) static DRIVER_INIT( tacscan ) { + segag80v_state *state = machine->driver_data(); address_space *pgmspace = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); address_space *iospace = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_IO); @@ -1387,7 +1383,7 @@ static DRIVER_INIT( tacscan ) sega_security(76); /* configure sound */ - has_usb = TRUE; + state->has_usb = TRUE; memory_install_readwrite8_handler(iospace, 0x3f, 0x3f, 0, 0, sega_usb_status_r, sega_usb_data_w); memory_install_readwrite8_handler(pgmspace, 0xd000, 0xdfff, 0, 0, sega_usb_ram_r, usb_ram_w); @@ -1399,6 +1395,7 @@ static DRIVER_INIT( tacscan ) static DRIVER_INIT( startrek ) { + segag80v_state *state = machine->driver_data(); address_space *pgmspace = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); address_space *iospace = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_IO); @@ -1406,7 +1403,7 @@ static DRIVER_INIT( startrek ) sega_security(64); /* configure sound */ - has_usb = TRUE; + state->has_usb = TRUE; memory_install_write8_handler(iospace, 0x38, 0x38, 0, 0, sega_speech_data_w); memory_install_write8_handler(iospace, 0x3b, 0x3b, 0, 0, sega_speech_control_w); diff --git a/src/mame/drivers/segas32.c b/src/mame/drivers/segas32.c index 7bdba2264e2..64853dc08b4 100644 --- a/src/mame/drivers/segas32.c +++ b/src/mame/drivers/segas32.c @@ -373,9 +373,6 @@ orunners: Interleaved with the dj and << >> buttons is the data the drives the * *************************************/ -UINT8 *ga2_dpram; -UINT16 *system32_workram; -UINT16 *system32_protram; @@ -385,31 +382,15 @@ UINT16 *system32_protram; * *************************************/ -static UINT8 *z80_shared_ram; /* V60 interrupt controller */ -static UINT8 v60_irq_control[0x10]; -static timer_device *v60_irq_timer[2]; /* sound interrupt controller */ -static UINT8 sound_irq_control[4]; -static UINT8 sound_irq_input; -static UINT8 sound_dummy_value; -static UINT16 sound_bank; /* I/O chips and custom I/O */ -static UINT8 misc_io_data[2][0x10]; -static read16_space_func custom_io_r[2]; -static write16_space_func custom_io_w[2]; -static UINT8 analog_bank; -static UINT8 analog_value[4]; -static UINT8 sonic_last[6]; /* callbacks to handle output */ -typedef void (*sys32_output_callback)(int which, UINT16 data); -static sys32_output_callback segas32_sw1_output, segas32_sw2_output, segas32_sw3_output; - static void (*system32_prot_vblank)(device_t *device); @@ -432,12 +413,13 @@ static void signal_sound_irq(running_machine *machine, int which); static MACHINE_RESET( system32 ) { + segas32_state *state = machine->driver_data(); /* initialize the interrupt controller */ - memset(v60_irq_control, 0xff, sizeof(v60_irq_control)); + memset(state->v60_irq_control, 0xff, sizeof(state->v60_irq_control)); /* allocate timers */ - v60_irq_timer[0] = machine->device("v60_irq0"); - v60_irq_timer[1] = machine->device("v60_irq1"); + state->v60_irq_timer[0] = machine->device("v60_irq0"); + state->v60_irq_timer[1] = machine->device("v60_irq1"); /* clear IRQ lines */ cputag_set_input_line(machine, "maincpu", 0, CLEAR_LINE); @@ -453,7 +435,8 @@ static MACHINE_RESET( system32 ) static void update_irq_state(running_machine *machine) { - UINT8 effirq = v60_irq_control[7] & ~v60_irq_control[6] & 0x1f; + segas32_state *state = machine->driver_data(); + UINT8 effirq = state->v60_irq_control[7] & ~state->v60_irq_control[6] & 0x1f; int vector; /* loop over interrupt vectors, finding the highest priority one with */ @@ -473,12 +456,13 @@ static void update_irq_state(running_machine *machine) static void signal_v60_irq(running_machine *machine, int which) { + segas32_state *state = machine->driver_data(); int i; /* see if this interrupt input is mapped to any vectors; if so, mark them */ for (i = 0; i < 5; i++) - if (v60_irq_control[i] == which) - v60_irq_control[7] |= 1 << i; + if (state->v60_irq_control[i] == which) + state->v60_irq_control[7] |= 1 << i; update_irq_state(machine); } @@ -491,6 +475,7 @@ static TIMER_DEVICE_CALLBACK( signal_v60_irq_callback ) static void int_control_w(address_space *space, int offset, UINT8 data) { + segas32_state *state = space->machine->driver_data(); int duration; // logerror("%06X:int_control_w(%X) = %02X\n", cpu_get_pc(space->cpu), offset, data); @@ -501,42 +486,42 @@ static void int_control_w(address_space *space, int offset, UINT8 data) case 2: case 3: case 4: /* vectors */ - v60_irq_control[offset] = data; + state->v60_irq_control[offset] = data; break; case 5: /* unknown */ - v60_irq_control[offset] = data; + state->v60_irq_control[offset] = data; break; case 6: /* mask */ - v60_irq_control[offset] = data; + state->v60_irq_control[offset] = data; update_irq_state(space->machine); break; case 7: /* acknowledge */ - v60_irq_control[offset] &= data; + state->v60_irq_control[offset] &= data; update_irq_state(space->machine); break; case 8: case 9: /* timer 0 count */ - v60_irq_control[offset] = data; - duration = v60_irq_control[8] + ((v60_irq_control[9] << 8) & 0xf00); + state->v60_irq_control[offset] = data; + duration = state->v60_irq_control[8] + ((state->v60_irq_control[9] << 8) & 0xf00); if (duration) { attotime period = attotime::from_hz(TIMER_0_CLOCK) * duration; - v60_irq_timer[0]->adjust(period, MAIN_IRQ_TIMER0); + state->v60_irq_timer[0]->adjust(period, MAIN_IRQ_TIMER0); } break; case 10: case 11: /* timer 1 count */ - v60_irq_control[offset] = data; - duration = v60_irq_control[10] + ((v60_irq_control[11] << 8) & 0xf00); + state->v60_irq_control[offset] = data; + duration = state->v60_irq_control[10] + ((state->v60_irq_control[11] << 8) & 0xf00); if (duration) { attotime period = attotime::from_hz(TIMER_1_CLOCK) * duration; - v60_irq_timer[1]->adjust(period, MAIN_IRQ_TIMER1); + state->v60_irq_timer[1]->adjust(period, MAIN_IRQ_TIMER1); } break; @@ -630,6 +615,7 @@ static INTERRUPT_GEN( start_of_vblank_int ) static UINT16 common_io_chip_r(address_space *space, int which, offs_t offset, UINT16 mem_mask) { + segas32_state *state = space->machine->driver_data(); static const char *const portnames[2][8] = { { "P1_A", "P2_A", "PORTC_A", "PORTD_A", "SERVICE12_A", "SERVICE34_A", "PORTG_A", "PORTH_A" }, @@ -649,8 +635,8 @@ static UINT16 common_io_chip_r(address_space *space, int which, offs_t offset, U case 0x0c/2: case 0x0e/2: /* if the port is configured as an output, return the last thing written */ - if (misc_io_data[which][0x1e/2] & (1 << offset)) - return misc_io_data[which][offset]; + if (state->misc_io_data[which][0x1e/2] & (1 << offset)) + return state->misc_io_data[which][offset]; /* otherwise, return an input port */ return input_port_read_safe(space->machine, portnames[which][offset], 0xffff); @@ -668,12 +654,12 @@ static UINT16 common_io_chip_r(address_space *space, int which, offs_t offset, U /* CNT register & mirror */ case 0x18/2: case 0x1c/2: - return misc_io_data[which][0x1c/2]; + return state->misc_io_data[which][0x1c/2]; /* port direction register & mirror */ case 0x1a/2: case 0x1e/2: - return misc_io_data[which][0x1e/2]; + return state->misc_io_data[which][0x1e/2]; } return 0xffff; } @@ -681,6 +667,7 @@ static UINT16 common_io_chip_r(address_space *space, int which, offs_t offset, U static void common_io_chip_w(address_space *space, int which, offs_t offset, UINT16 data, UINT16 mem_mask) { + segas32_state *state = space->machine->driver_data(); UINT8 old; /* only LSB matters */ @@ -689,8 +676,8 @@ static void common_io_chip_w(address_space *space, int which, offs_t offset, UIN /* generic implementation */ offset &= 0x1f/2; - old = misc_io_data[which][offset]; - misc_io_data[which][offset] = data; + old = state->misc_io_data[which][offset]; + state->misc_io_data[which][offset] = data; switch (offset) { @@ -701,14 +688,14 @@ static void common_io_chip_w(address_space *space, int which, offs_t offset, UIN case 0x08/2: case 0x0a/2: case 0x0c/2: - if (segas32_sw2_output) - segas32_sw2_output(which, data); + if (state->sw2_output) + state->sw2_output(which, data); break; /* miscellaneous output */ case 0x06/2: - if (segas32_sw1_output) - segas32_sw1_output(which, data); + if (state->sw1_output) + state->sw1_output(which, data); if (which == 0) { @@ -726,7 +713,7 @@ static void common_io_chip_w(address_space *space, int which, offs_t offset, UIN /* tile banking */ case 0x0e/2: if (which == 0) - system32_tilebank_external = data; + state->system32_tilebank_external = data; else { /* multi-32 EEPROM access */ @@ -739,7 +726,7 @@ static void common_io_chip_w(address_space *space, int which, offs_t offset, UIN /* CNT register */ case 0x1c/2: - system32_displayenable[which] = (data & 0x02); + state->system32_displayenable[which] = (data & 0x02); if (which == 0) cputag_set_input_line(space->machine, "soundcpu", INPUT_LINE_RESET, (data & 0x04) ? CLEAR_LINE : ASSERT_LINE); break; @@ -800,8 +787,9 @@ static WRITE32_HANDLER( io_chip_1_w ) static READ16_HANDLER( io_expansion_r ) { - if (custom_io_r[0]) - return (*custom_io_r[0])(space, offset, mem_mask); + segas32_state *state = space->machine->driver_data(); + if (state->custom_io_r[0]) + return (*state->custom_io_r[0])(space, offset, mem_mask); else logerror("%06X:io_expansion_r(%X)\n", cpu_get_pc(space->cpu), offset); return 0xffff; @@ -810,12 +798,13 @@ static READ16_HANDLER( io_expansion_r ) static WRITE16_HANDLER( io_expansion_w ) { + segas32_state *state = space->machine->driver_data(); /* only LSB matters */ if (!ACCESSING_BITS_0_7) return; - if (custom_io_w[0]) - (*custom_io_w[0])(space, offset, data, mem_mask); + if (state->custom_io_w[0]) + (*state->custom_io_w[0])(space, offset, data, mem_mask); else logerror("%06X:io_expansion_w(%X) = %02X\n", cpu_get_pc(space->cpu), offset, data & 0xff); } @@ -823,9 +812,10 @@ static WRITE16_HANDLER( io_expansion_w ) static READ32_HANDLER( io_expansion_0_r ) { - if (custom_io_r[0]) - return (*custom_io_r[0])(space, offset*2+0, mem_mask) | - ((*custom_io_r[0])(space, offset*2+1, mem_mask >> 16) << 16); + segas32_state *state = space->machine->driver_data(); + if (state->custom_io_r[0]) + return (*state->custom_io_r[0])(space, offset*2+0, mem_mask) | + ((*state->custom_io_r[0])(space, offset*2+1, mem_mask >> 16) << 16); else logerror("%06X:io_expansion_r(%X)\n", cpu_get_pc(space->cpu), offset); return 0xffffffff; @@ -834,25 +824,26 @@ static READ32_HANDLER( io_expansion_0_r ) static WRITE32_HANDLER( io_expansion_0_w ) { + segas32_state *state = space->machine->driver_data(); /* only LSB matters */ if (ACCESSING_BITS_0_7) { /* harddunk uses bits 4,5 for output lamps */ - if (segas32_sw3_output) - segas32_sw3_output(0, data & 0xff); + if (state->sw3_output) + state->sw3_output(0, data & 0xff); - if (custom_io_w[0]) - (*custom_io_w[0])(space, offset*2+0, data, mem_mask); + if (state->custom_io_w[0]) + (*state->custom_io_w[0])(space, offset*2+0, data, mem_mask); else logerror("%06X:io_expansion_w(%X) = %02X\n", cpu_get_pc(space->cpu), offset, data & 0xff); } if (ACCESSING_BITS_16_23) { - if (custom_io_w[0]) - (*custom_io_w[0])(space, offset*2+1, data >> 16, mem_mask >> 16); + if (state->custom_io_w[0]) + (*state->custom_io_w[0])(space, offset*2+1, data >> 16, mem_mask >> 16); else logerror("%06X:io_expansion_w(%X) = %02X\n", cpu_get_pc(space->cpu), offset, data & 0xff); } @@ -861,9 +852,10 @@ static WRITE32_HANDLER( io_expansion_0_w ) static READ32_HANDLER( io_expansion_1_r ) { - if (custom_io_r[1]) - return (*custom_io_r[1])(space, offset*2+0, mem_mask) | - ((*custom_io_r[1])(space, offset*2+1, mem_mask >> 16) << 16); + segas32_state *state = space->machine->driver_data(); + if (state->custom_io_r[1]) + return (*state->custom_io_r[1])(space, offset*2+0, mem_mask) | + ((*state->custom_io_r[1])(space, offset*2+1, mem_mask >> 16) << 16); else logerror("%06X:io_expansion_r(%X)\n", cpu_get_pc(space->cpu), offset); return 0xffffffff; @@ -872,18 +864,19 @@ static READ32_HANDLER( io_expansion_1_r ) static WRITE32_HANDLER( io_expansion_1_w ) { + segas32_state *state = space->machine->driver_data(); /* only LSB matters */ if (ACCESSING_BITS_0_7) { - if (custom_io_w[1]) - (*custom_io_w[1])(space, offset*2+0, data, mem_mask); + if (state->custom_io_w[1]) + (*state->custom_io_w[1])(space, offset*2+0, data, mem_mask); else logerror("%06X:io_expansion_w(%X) = %02X\n", cpu_get_pc(space->cpu), offset, data & 0xff); } if (ACCESSING_BITS_16_23) { - if (custom_io_w[1]) - (*custom_io_w[1])(space, offset*2+1, data >> 16, mem_mask >> 16); + if (state->custom_io_w[1]) + (*state->custom_io_w[1])(space, offset*2+1, data >> 16, mem_mask >> 16); else logerror("%06X:io_expansion_w(%X) = %02X\n", cpu_get_pc(space->cpu), offset, data & 0xff); } @@ -899,6 +892,7 @@ static WRITE32_HANDLER( io_expansion_1_w ) static READ16_HANDLER( analog_custom_io_r ) { + segas32_state *state = space->machine->driver_data(); UINT16 result; switch (offset) { @@ -906,8 +900,8 @@ static READ16_HANDLER( analog_custom_io_r ) case 0x12/2: case 0x14/2: case 0x16/2: - result = analog_value[offset & 3] | 0x7f; - analog_value[offset & 3] <<= 1; + result = state->analog_value[offset & 3] | 0x7f; + state->analog_value[offset & 3] <<= 1; return result; } logerror("%06X:unknown analog_custom_io_r(%X) & %04X\n", cpu_get_pc(space->cpu), offset*2, mem_mask); @@ -917,6 +911,7 @@ static READ16_HANDLER( analog_custom_io_r ) static WRITE16_HANDLER( analog_custom_io_w ) { + segas32_state *state = space->machine->driver_data(); static const char *const names[] = { "ANALOG1", "ANALOG2", "ANALOG3", "ANALOG4" }; switch (offset) { @@ -924,7 +919,7 @@ static WRITE16_HANDLER( analog_custom_io_w ) case 0x12/2: case 0x14/2: case 0x16/2: - analog_value[offset & 3] = input_port_read_safe(space->machine, names[offset & 3], 0); + state->analog_value[offset & 3] = input_port_read_safe(space->machine, names[offset & 3], 0); return; } logerror("%06X:unknown analog_custom_io_w(%X) = %04X & %04X\n", cpu_get_pc(space->cpu), offset*2, data, mem_mask); @@ -950,6 +945,7 @@ static READ16_HANDLER( extra_custom_io_r ) static WRITE16_HANDLER( orunners_custom_io_w ) { + segas32_state *state = space->machine->driver_data(); static const char *const names[] = { "ANALOG1", "ANALOG2", "ANALOG3", "ANALOG4", "ANALOG5", "ANALOG6", "ANALOG7", "ANALOG8" }; switch (offset) { @@ -957,11 +953,11 @@ static WRITE16_HANDLER( orunners_custom_io_w ) case 0x12/2: case 0x14/2: case 0x16/2: - analog_value[offset & 3] = input_port_read_safe(space->machine, names[analog_bank * 4 + (offset & 3)], 0); + state->analog_value[offset & 3] = input_port_read_safe(space->machine, names[state->analog_bank * 4 + (offset & 3)], 0); return; case 0x20/2: - analog_bank = data & 1; + state->analog_bank = data & 1; return; } logerror("%06X:unknown orunners_custom_io_w(%X) = %04X & %04X\n", cpu_get_pc(space->cpu), offset*2, data, mem_mask); @@ -970,6 +966,7 @@ static WRITE16_HANDLER( orunners_custom_io_w ) static READ16_HANDLER( sonic_custom_io_r ) { + segas32_state *state = space->machine->driver_data(); static const char *const names[] = { "TRACKX1", "TRACKY1", "TRACKX2", "TRACKY2", "TRACKX3", "TRACKY3" }; switch (offset) @@ -980,7 +977,7 @@ static READ16_HANDLER( sonic_custom_io_r ) case 0x0c/2: case 0x10/2: case 0x14/2: - return (UINT8)(input_port_read(space->machine, names[offset/2]) - sonic_last[offset/2]); + return (UINT8)(input_port_read(space->machine, names[offset/2]) - state->sonic_last[offset/2]); } logerror("%06X:unknown sonic_custom_io_r(%X) & %04X\n", cpu_get_pc(space->cpu), offset*2, mem_mask); @@ -990,6 +987,7 @@ static READ16_HANDLER( sonic_custom_io_r ) static WRITE16_HANDLER( sonic_custom_io_w ) { + segas32_state *state = space->machine->driver_data(); static const char *const names[] = { "TRACKX1", "TRACKY1", "TRACKX2", "TRACKY2", "TRACKX3", "TRACKY3" }; switch (offset) @@ -997,8 +995,8 @@ static WRITE16_HANDLER( sonic_custom_io_w ) case 0x00/2: case 0x08/2: case 0x10/2: - sonic_last[offset/2 + 0] = input_port_read(space->machine, names[offset/2 + 0]); - sonic_last[offset/2 + 1] = input_port_read(space->machine, names[offset/2 + 1]); + state->sonic_last[offset/2 + 0] = input_port_read(space->machine, names[offset/2 + 0]); + state->sonic_last[offset/2 + 1] = input_port_read(space->machine, names[offset/2 + 1]); return; } @@ -1043,36 +1041,40 @@ static READ32_HANDLER( random_number_32_r ) static READ16_HANDLER( shared_ram_16_r ) { - return z80_shared_ram[offset*2+0] | (z80_shared_ram[offset*2+1] << 8); + segas32_state *state = space->machine->driver_data(); + return state->z80_shared_ram[offset*2+0] | (state->z80_shared_ram[offset*2+1] << 8); } static WRITE16_HANDLER( shared_ram_16_w ) { + segas32_state *state = space->machine->driver_data(); if (ACCESSING_BITS_0_7) - z80_shared_ram[offset*2+0] = data; + state->z80_shared_ram[offset*2+0] = data; if (ACCESSING_BITS_8_15) - z80_shared_ram[offset*2+1] = data >> 8; + state->z80_shared_ram[offset*2+1] = data >> 8; } static READ32_HANDLER( shared_ram_32_r ) { - return z80_shared_ram[offset*4+0] | (z80_shared_ram[offset*4+1] << 8) | - (z80_shared_ram[offset*4+2] << 16) | (z80_shared_ram[offset*4+3] << 24); + segas32_state *state = space->machine->driver_data(); + return state->z80_shared_ram[offset*4+0] | (state->z80_shared_ram[offset*4+1] << 8) | + (state->z80_shared_ram[offset*4+2] << 16) | (state->z80_shared_ram[offset*4+3] << 24); } static WRITE32_HANDLER( shared_ram_32_w ) { + segas32_state *state = space->machine->driver_data(); if (ACCESSING_BITS_0_7) - z80_shared_ram[offset*4+0] = data; + state->z80_shared_ram[offset*4+0] = data; if (ACCESSING_BITS_8_15) - z80_shared_ram[offset*4+1] = data >> 8; + state->z80_shared_ram[offset*4+1] = data >> 8; if (ACCESSING_BITS_16_23) - z80_shared_ram[offset*4+2] = data >> 16; + state->z80_shared_ram[offset*4+2] = data >> 16; if (ACCESSING_BITS_24_31) - z80_shared_ram[offset*4+3] = data >> 24; + state->z80_shared_ram[offset*4+3] = data >> 24; } @@ -1085,7 +1087,8 @@ static WRITE32_HANDLER( shared_ram_32_w ) static void update_sound_irq_state(running_machine *machine) { - UINT8 effirq = sound_irq_input & ~sound_irq_control[3] & 0x07; + segas32_state *state = machine->driver_data(); + UINT8 effirq = state->sound_irq_input & ~state->sound_irq_control[3] & 0x07; int vector; /* loop over interrupt vectors, finding the highest priority one with */ @@ -1105,32 +1108,35 @@ static void update_sound_irq_state(running_machine *machine) static void signal_sound_irq(running_machine *machine, int which) { + segas32_state *state = machine->driver_data(); int i; /* see if this interrupt input is mapped to any vectors; if so, mark them */ for (i = 0; i < 3; i++) - if (sound_irq_control[i] == which) - sound_irq_input |= 1 << i; + if (state->sound_irq_control[i] == which) + state->sound_irq_input |= 1 << i; update_sound_irq_state(machine); } static void clear_sound_irq(running_machine *machine, int which) { + segas32_state *state = machine->driver_data(); int i; for (i = 0; i < 3; i++) - if (sound_irq_control[i] == which) - sound_irq_input &= ~(1 << i); + if (state->sound_irq_control[i] == which) + state->sound_irq_input &= ~(1 << i); update_sound_irq_state(machine); } static WRITE8_HANDLER( sound_int_control_lo_w ) { + segas32_state *state = space->machine->driver_data(); /* odd offsets are interrupt acks */ if (offset & 1) { - sound_irq_input &= data; + state->sound_irq_input &= data; update_sound_irq_state(space->machine); } @@ -1142,7 +1148,8 @@ static WRITE8_HANDLER( sound_int_control_lo_w ) static WRITE8_HANDLER( sound_int_control_hi_w ) { - sound_irq_control[offset] = data; + segas32_state *state = space->machine->driver_data(); + state->sound_irq_control[offset] = data; update_sound_irq_state(space->machine); } @@ -1165,15 +1172,17 @@ static void ym3438_irq_handler(device_t *device, int state) static WRITE8_HANDLER( sound_bank_lo_w ) { - sound_bank = (sound_bank & ~0x3f) | (data & 0x3f); - memory_set_bankptr(space->machine, "bank1", space->machine->region("soundcpu")->base() + 0x100000 + 0x2000 * sound_bank); + segas32_state *state = space->machine->driver_data(); + state->sound_bank = (state->sound_bank & ~0x3f) | (data & 0x3f); + memory_set_bankptr(space->machine, "bank1", space->machine->region("soundcpu")->base() + 0x100000 + 0x2000 * state->sound_bank); } static WRITE8_HANDLER( sound_bank_hi_w ) { - sound_bank = (sound_bank & 0x3f) | ((data & 0x04) << 4) | ((data & 0x03) << 7); - memory_set_bankptr(space->machine, "bank1", space->machine->region("soundcpu")->base() + 0x100000 + 0x2000 * sound_bank); + segas32_state *state = space->machine->driver_data(); + state->sound_bank = (state->sound_bank & 0x3f) | ((data & 0x04) << 4) | ((data & 0x03) << 7); + memory_set_bankptr(space->machine, "bank1", space->machine->region("soundcpu")->base() + 0x100000 + 0x2000 * state->sound_bank); } @@ -1198,13 +1207,15 @@ static WRITE8_DEVICE_HANDLER( scross_bank_w ) static READ8_HANDLER( sound_dummy_r ) { - return sound_dummy_value; + segas32_state *state = space->machine->driver_data(); + return state->sound_dummy_value; } static WRITE8_HANDLER( sound_dummy_w ) { - sound_dummy_value = data; + segas32_state *state = space->machine->driver_data(); + state->sound_dummy_value = data; } @@ -1218,11 +1229,11 @@ static WRITE8_HANDLER( sound_dummy_w ) static ADDRESS_MAP_START( system32_map, ADDRESS_SPACE_PROGRAM, 16 ) ADDRESS_MAP_UNMAP_HIGH AM_RANGE(0x000000, 0x1fffff) AM_ROM - AM_RANGE(0x200000, 0x20ffff) AM_MIRROR(0x0f0000) AM_RAM AM_BASE(&system32_workram) - AM_RANGE(0x300000, 0x31ffff) AM_MIRROR(0x0e0000) AM_READWRITE(system32_videoram_r, system32_videoram_w) AM_BASE(&system32_videoram) - AM_RANGE(0x400000, 0x41ffff) AM_MIRROR(0x0e0000) AM_READWRITE(system32_spriteram_r, system32_spriteram_w) AM_BASE(&system32_spriteram) + AM_RANGE(0x200000, 0x20ffff) AM_MIRROR(0x0f0000) AM_RAM AM_BASE_MEMBER(segas32_state, system32_workram) + AM_RANGE(0x300000, 0x31ffff) AM_MIRROR(0x0e0000) AM_READWRITE(system32_videoram_r, system32_videoram_w) AM_BASE_MEMBER(segas32_state, system32_videoram) + AM_RANGE(0x400000, 0x41ffff) AM_MIRROR(0x0e0000) AM_READWRITE(system32_spriteram_r, system32_spriteram_w) AM_BASE_MEMBER(segas32_state, system32_spriteram) AM_RANGE(0x500000, 0x50000f) AM_MIRROR(0x0ffff0) AM_READWRITE(system32_sprite_control_r, system32_sprite_control_w) - AM_RANGE(0x600000, 0x60ffff) AM_MIRROR(0x0e0000) AM_READWRITE(system32_paletteram_r, system32_paletteram_w) AM_BASE(&system32_paletteram[0]) + AM_RANGE(0x600000, 0x60ffff) AM_MIRROR(0x0e0000) AM_READWRITE(system32_paletteram_r, system32_paletteram_w) AM_BASE_MEMBER(segas32_state, system32_paletteram[0]) AM_RANGE(0x610000, 0x61007f) AM_MIRROR(0x0eff80) AM_READWRITE(system32_mixer_r, system32_mixer_w) AM_RANGE(0x700000, 0x701fff) AM_MIRROR(0x0fe000) AM_READWRITE(shared_ram_16_r, shared_ram_16_w) AM_RANGE(0xc00000, 0xc0001f) AM_MIRROR(0x0fff80) AM_READWRITE(io_chip_r, io_chip_w) @@ -1238,12 +1249,12 @@ static ADDRESS_MAP_START( multi32_map, ADDRESS_SPACE_PROGRAM, 32 ) ADDRESS_MAP_GLOBAL_MASK(0xffffff) AM_RANGE(0x000000, 0x1fffff) AM_ROM AM_RANGE(0x200000, 0x21ffff) AM_MIRROR(0x0e0000) AM_RAM - AM_RANGE(0x300000, 0x31ffff) AM_MIRROR(0x0e0000) AM_READWRITE(multi32_videoram_r, multi32_videoram_w) AM_BASE((UINT32 **)&system32_videoram) - AM_RANGE(0x400000, 0x41ffff) AM_MIRROR(0x0e0000) AM_READWRITE(multi32_spriteram_r, multi32_spriteram_w) AM_BASE((UINT32 **)&system32_spriteram) + AM_RANGE(0x300000, 0x31ffff) AM_MIRROR(0x0e0000) AM_READWRITE(multi32_videoram_r, multi32_videoram_w) AM_BASE_MEMBER(segas32_state, system32_videoram) + AM_RANGE(0x400000, 0x41ffff) AM_MIRROR(0x0e0000) AM_READWRITE(multi32_spriteram_r, multi32_spriteram_w) AM_BASE_MEMBER(segas32_state, system32_spriteram) AM_RANGE(0x500000, 0x50000f) AM_MIRROR(0x0ffff0) AM_READWRITE(multi32_sprite_control_r, multi32_sprite_control_w) - AM_RANGE(0x600000, 0x60ffff) AM_MIRROR(0x060000) AM_READWRITE(multi32_paletteram_0_r, multi32_paletteram_0_w) AM_BASE((UINT32 **)&system32_paletteram[0]) + AM_RANGE(0x600000, 0x60ffff) AM_MIRROR(0x060000) AM_READWRITE(multi32_paletteram_0_r, multi32_paletteram_0_w) AM_BASE_MEMBER(segas32_state, system32_paletteram[0]) AM_RANGE(0x610000, 0x61007f) AM_MIRROR(0x06ff80) AM_WRITE(multi32_mixer_0_w) - AM_RANGE(0x680000, 0x68ffff) AM_MIRROR(0x060000) AM_READWRITE(multi32_paletteram_1_r, multi32_paletteram_1_w) AM_BASE((UINT32 **)&system32_paletteram[1]) + AM_RANGE(0x680000, 0x68ffff) AM_MIRROR(0x060000) AM_READWRITE(multi32_paletteram_1_r, multi32_paletteram_1_w) AM_BASE_MEMBER(segas32_state, system32_paletteram[1]) AM_RANGE(0x690000, 0x69007f) AM_MIRROR(0x06ff80) AM_WRITE(multi32_mixer_1_w) AM_RANGE(0x700000, 0x701fff) AM_MIRROR(0x0fe000) AM_READWRITE(shared_ram_32_r, shared_ram_32_w) AM_RANGE(0xc00000, 0xc0001f) AM_MIRROR(0x07ff80) AM_READWRITE(io_chip_0_r, io_chip_0_w) @@ -1268,7 +1279,7 @@ static ADDRESS_MAP_START( system32_sound_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0xa000, 0xbfff) AM_ROMBANK("bank1") AM_RANGE(0xc000, 0xc00f) AM_MIRROR(0x0ff0) AM_DEVWRITE("rfsnd", rf5c68_w) AM_RANGE(0xd000, 0xdfff) AM_DEVREADWRITE("rfsnd", rf5c68_mem_r, rf5c68_mem_w) - AM_RANGE(0xe000, 0xffff) AM_RAM AM_BASE(&z80_shared_ram) + AM_RANGE(0xe000, 0xffff) AM_RAM AM_BASE_MEMBER(segas32_state, z80_shared_ram) ADDRESS_MAP_END static ADDRESS_MAP_START( system32_sound_portmap, ADDRESS_SPACE_IO, 8 ) @@ -1288,7 +1299,7 @@ static ADDRESS_MAP_START( multi32_sound_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x0000, 0x9fff) AM_ROM AM_REGION("soundcpu", 0x100000) AM_RANGE(0xa000, 0xbfff) AM_ROMBANK("bank1") AM_RANGE(0xc000, 0xdfff) AM_DEVREADWRITE("sega", multipcm_r, multipcm_w) - AM_RANGE(0xe000, 0xffff) AM_RAM AM_BASE(&z80_shared_ram) + AM_RANGE(0xe000, 0xffff) AM_RAM AM_BASE_MEMBER(segas32_state, z80_shared_ram) ADDRESS_MAP_END static ADDRESS_MAP_START( multi32_sound_portmap, ADDRESS_SPACE_IO, 8 ) @@ -1312,7 +1323,7 @@ ADDRESS_MAP_END static ADDRESS_MAP_START( ga2_v25_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x00000, 0x0ffff) AM_ROM AM_REGION("mcu", 0) - AM_RANGE(0x10000, 0x1ffff) AM_RAM AM_BASE(&ga2_dpram) + AM_RANGE(0x10000, 0x1ffff) AM_RAM AM_BASE_MEMBER(segas32_state, ga2_dpram) AM_RANGE(0xf0000, 0xfffff) AM_ROM AM_REGION("mcu", 0) ADDRESS_MAP_END @@ -2153,16 +2164,17 @@ static const ym3438_interface ym3438_config = // Both arescue and f1en appear to use an identical shared RAM system. -static UINT16* dual_pcb_comms; static WRITE16_HANDLER( dual_pcb_comms_w ) { - COMBINE_DATA(&dual_pcb_comms[offset]); + segas32_state *state = space->machine->driver_data(); + COMBINE_DATA(&state->dual_pcb_comms[offset]); } static READ16_HANDLER( dual_pcb_comms_r ) { - return dual_pcb_comms[offset]; + segas32_state *state = space->machine->driver_data(); + return state->dual_pcb_comms[offset]; } @@ -2183,7 +2195,7 @@ static READ16_HANDLER( dual_pcb_masterslave ) * *************************************/ -static MACHINE_CONFIG_START( system32, driver_device ) +static MACHINE_CONFIG_START( system32, segas32_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu", V60, MASTER_CLOCK/2) @@ -2243,7 +2255,7 @@ static MACHINE_CONFIG_DERIVED( system32_v25, system32 ) MACHINE_CONFIG_END -static MACHINE_CONFIG_START( multi32, driver_device ) +static MACHINE_CONFIG_START( multi32, segas32_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu", V70, MULTI32_CLOCK/2) @@ -3807,15 +3819,16 @@ ROM_END * *************************************/ -static void segas32_common_init(read16_space_func custom_r, write16_space_func custom_w) +static void segas32_common_init(running_machine *machine, read16_space_func custom_r, write16_space_func custom_w) { + segas32_state *state = machine->driver_data(); /* reset the custom handlers and other pointers */ - custom_io_r[0] = custom_r; - custom_io_w[0] = custom_w; + state->custom_io_r[0] = custom_r; + state->custom_io_w[0] = custom_w; system32_prot_vblank = NULL; - segas32_sw1_output = NULL; - segas32_sw2_output = NULL; - segas32_sw3_output = NULL; + state->sw1_output = NULL; + state->sw2_output = NULL; + state->sw3_output = NULL; } @@ -4003,8 +4016,9 @@ static void scross_sw2_output( int which, UINT16 data ) static DRIVER_INIT( alien3 ) { - segas32_common_init(analog_custom_io_r, analog_custom_io_w); - segas32_sw1_output = alien3_sw1_output; + segas32_state *state = machine->driver_data(); + segas32_common_init(machine, analog_custom_io_r, analog_custom_io_w); + state->sw1_output = alien3_sw1_output; } static READ16_HANDLER( arescue_handshake_r ) @@ -4019,23 +4033,24 @@ static READ16_HANDLER( arescue_slavebusy_r ) static DRIVER_INIT( arescue ) { - segas32_common_init(analog_custom_io_r, analog_custom_io_w); + segas32_state *state = machine->driver_data(); + segas32_common_init(machine, analog_custom_io_r, analog_custom_io_w); memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa00000, 0xa00007, 0, 0, arescue_dsp_r, arescue_dsp_w); - dual_pcb_comms = auto_alloc_array(machine, UINT16, 0x1000/2); + state->dual_pcb_comms = auto_alloc_array(machine, UINT16, 0x1000/2); memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x810000, 0x810fff, 0, 0, dual_pcb_comms_r, dual_pcb_comms_w); memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x818000, 0x818003, 0, 0, dual_pcb_masterslave); memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x810000, 0x810001, 0, 0, arescue_handshake_r); memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x81000e, 0x81000f, 0, 0, arescue_slavebusy_r); - segas32_sw1_output = arescue_sw1_output; + state->sw1_output = arescue_sw1_output; } static DRIVER_INIT( arabfgt ) { - segas32_common_init(extra_custom_io_r, NULL); + segas32_common_init(machine, extra_custom_io_r, NULL); /* install protection handlers */ memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa00100, 0xa0011f, 0, 0, arf_wakeup_protection_r); @@ -4045,10 +4060,11 @@ static DRIVER_INIT( arabfgt ) static DRIVER_INIT( brival ) { - segas32_common_init(extra_custom_io_r, NULL); + segas32_state *state = machine->driver_data(); + segas32_common_init(machine, extra_custom_io_r, NULL); /* install protection handlers */ - system32_protram = auto_alloc_array(machine, UINT16, 0x1000/2); + state->system32_protram = auto_alloc_array(machine, UINT16, 0x1000/2); memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x20ba00, 0x20ba07, 0, 0, brival_protection_r); memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa00000, 0xa00fff, 0, 0, brival_protection_w); } @@ -4056,7 +4072,7 @@ static DRIVER_INIT( brival ) static DRIVER_INIT( darkedge ) { - segas32_common_init(extra_custom_io_r, NULL); + segas32_common_init(machine, extra_custom_io_r, NULL); /* install protection handlers */ memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa00000, 0xa7ffff, 0, 0, darkedge_protection_r, darkedge_protection_w); @@ -4065,7 +4081,7 @@ static DRIVER_INIT( darkedge ) static DRIVER_INIT( dbzvrvs ) { - segas32_common_init(NULL, NULL); + segas32_common_init(machine, NULL, NULL); /* install protection handlers */ memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa00000, 0xa7ffff, 0, 0, dbzvrvs_protection_r, dbzvrvs_protection_w); @@ -4080,28 +4096,30 @@ static WRITE16_HANDLER( f1en_comms_echo_w ) static DRIVER_INIT( f1en ) { - segas32_common_init(analog_custom_io_r, analog_custom_io_w); + segas32_state *state = machine->driver_data(); + segas32_common_init(machine, analog_custom_io_r, analog_custom_io_w); - dual_pcb_comms = auto_alloc_array(machine, UINT16, 0x1000/2); + state->dual_pcb_comms = auto_alloc_array(machine, UINT16, 0x1000/2); memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x810000, 0x810fff, 0, 0, dual_pcb_comms_r, dual_pcb_comms_w); memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x818000, 0x818003, 0, 0, dual_pcb_masterslave); memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x810048, 0x810049, 0, 0, f1en_comms_echo_w); - segas32_sw1_output = radm_sw1_output; + state->sw1_output = radm_sw1_output; } static DRIVER_INIT( f1lap ) { - segas32_common_init(analog_custom_io_r, analog_custom_io_w); - segas32_sw1_output = f1lap_sw1_output; + segas32_state *state = machine->driver_data(); + segas32_common_init(machine, analog_custom_io_r, analog_custom_io_w); + state->sw1_output = f1lap_sw1_output; } static DRIVER_INIT( ga2 ) { - segas32_common_init(extra_custom_io_r, NULL); + segas32_common_init(machine, extra_custom_io_r, NULL); decrypt_ga2_protrom(machine); memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa00000, 0xa00fff, 0, 0, ga2_dpram_r, ga2_dpram_w); @@ -4110,77 +4128,83 @@ static DRIVER_INIT( ga2 ) static DRIVER_INIT( harddunk ) { - segas32_common_init(extra_custom_io_r, NULL); - segas32_sw1_output = harddunk_sw1_output; - segas32_sw2_output = harddunk_sw2_output; - segas32_sw3_output = harddunk_sw3_output; + segas32_state *state = machine->driver_data(); + segas32_common_init(machine, extra_custom_io_r, NULL); + state->sw1_output = harddunk_sw1_output; + state->sw2_output = harddunk_sw2_output; + state->sw3_output = harddunk_sw3_output; } static DRIVER_INIT( holo ) { - segas32_common_init(NULL, NULL); + segas32_common_init(machine, NULL, NULL); } static DRIVER_INIT( jpark ) { + segas32_state *state = machine->driver_data(); /* Temp. Patch until we emulate the 'Drive Board', thanks to Malice */ UINT16 *pROM = (UINT16 *)machine->region("maincpu")->base(); - segas32_common_init(analog_custom_io_r, analog_custom_io_w); + segas32_common_init(machine, analog_custom_io_r, analog_custom_io_w); pROM[0xC15A8/2] = 0xCD70; pROM[0xC15AA/2] = 0xD8CD; - segas32_sw1_output = jpark_sw1_output; + state->sw1_output = jpark_sw1_output; } static DRIVER_INIT( orunners ) { - segas32_common_init(analog_custom_io_r, orunners_custom_io_w); - segas32_sw1_output = orunners_sw1_output; - segas32_sw2_output = orunners_sw2_output; + segas32_state *state = machine->driver_data(); + segas32_common_init(machine, analog_custom_io_r, orunners_custom_io_w); + state->sw1_output = orunners_sw1_output; + state->sw2_output = orunners_sw2_output; } static DRIVER_INIT( radm ) { - segas32_common_init(analog_custom_io_r, analog_custom_io_w); - segas32_sw1_output = radm_sw1_output; - segas32_sw2_output = radm_sw2_output; + segas32_state *state = machine->driver_data(); + segas32_common_init(machine, analog_custom_io_r, analog_custom_io_w); + state->sw1_output = radm_sw1_output; + state->sw2_output = radm_sw2_output; } static DRIVER_INIT( radr ) { - segas32_common_init(analog_custom_io_r, analog_custom_io_w); - segas32_sw1_output = radm_sw1_output; - segas32_sw2_output = radr_sw2_output; + segas32_state *state = machine->driver_data(); + segas32_common_init(machine, analog_custom_io_r, analog_custom_io_w); + state->sw1_output = radm_sw1_output; + state->sw2_output = radr_sw2_output; } static DRIVER_INIT( scross ) { + segas32_state *state = machine->driver_data(); multipcm_device *multipcm = machine->device("sega"); - segas32_common_init(analog_custom_io_r, analog_custom_io_w); + segas32_common_init(machine, analog_custom_io_r, analog_custom_io_w); memory_install_write8_device_handler(cputag_get_address_space(machine, "soundcpu", ADDRESS_SPACE_PROGRAM), multipcm, 0xb0, 0xbf, 0, 0, scross_bank_w); - segas32_sw1_output = scross_sw1_output; - segas32_sw2_output = scross_sw2_output; + state->sw1_output = scross_sw1_output; + state->sw2_output = scross_sw2_output; } static DRIVER_INIT( slipstrm ) { - segas32_common_init(analog_custom_io_r, analog_custom_io_w); + segas32_common_init(machine, analog_custom_io_r, analog_custom_io_w); } static DRIVER_INIT( sonic ) { - segas32_common_init(sonic_custom_io_r, sonic_custom_io_w); + segas32_common_init(machine, sonic_custom_io_r, sonic_custom_io_w); /* install protection handlers */ memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x20E5C4, 0x20E5C5, 0, 0, sonic_level_load_protection); @@ -4189,34 +4213,35 @@ static DRIVER_INIT( sonic ) static DRIVER_INIT( sonicp ) { - segas32_common_init(sonic_custom_io_r, sonic_custom_io_w); + segas32_common_init(machine, sonic_custom_io_r, sonic_custom_io_w); } static DRIVER_INIT( spidman ) { - segas32_common_init(extra_custom_io_r, NULL); + segas32_common_init(machine, extra_custom_io_r, NULL); } static DRIVER_INIT( svf ) { - segas32_common_init(NULL, NULL); + segas32_common_init(machine, NULL, NULL); } static DRIVER_INIT( jleague ) { - segas32_common_init(NULL, NULL); + segas32_common_init(machine, NULL, NULL); memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x20F700, 0x20F705, 0, 0, jleague_protection_w); } static DRIVER_INIT( titlef ) { - segas32_common_init(NULL, NULL); - segas32_sw1_output = titlef_sw1_output; - segas32_sw2_output = titlef_sw2_output; + segas32_state *state = machine->driver_data(); + segas32_common_init(machine, NULL, NULL); + state->sw1_output = titlef_sw1_output; + state->sw2_output = titlef_sw2_output; } diff --git a/src/mame/drivers/suprloco.c b/src/mame/drivers/suprloco.c index 3782a2a7190..17996ec25b5 100644 --- a/src/mame/drivers/suprloco.c +++ b/src/mame/drivers/suprloco.c @@ -37,9 +37,9 @@ static ADDRESS_MAP_START( main_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0xe001, 0xe001) AM_READ_PORT("DSW2") AM_RANGE(0xe800, 0xe800) AM_WRITE(suprloco_soundport_w) AM_RANGE(0xe801, 0xe801) AM_READWRITE(suprloco_control_r, suprloco_control_w) - AM_RANGE(0xf000, 0xf6ff) AM_RAM_WRITE(suprloco_videoram_w) AM_BASE(&suprloco_videoram) + AM_RANGE(0xf000, 0xf6ff) AM_RAM_WRITE(suprloco_videoram_w) AM_BASE_MEMBER(suprloco_state, videoram) AM_RANGE(0xf700, 0xf7df) AM_RAM /* unused */ - AM_RANGE(0xf7e0, 0xf7ff) AM_RAM_WRITE(suprloco_scrollram_w) AM_BASE(&suprloco_scrollram) + AM_RANGE(0xf7e0, 0xf7ff) AM_RAM_WRITE(suprloco_scrollram_w) AM_BASE_MEMBER(suprloco_state, scrollram) AM_RANGE(0xf800, 0xffff) AM_RAM ADDRESS_MAP_END @@ -152,7 +152,7 @@ GFXDECODE_END -static MACHINE_CONFIG_START( suprloco, driver_device ) +static MACHINE_CONFIG_START( suprloco, suprloco_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu", Z80, 4000000) /* 4 MHz (?) */ diff --git a/src/mame/drivers/system1.c b/src/mame/drivers/system1.c index 7384f49e132..f9cca4b52d2 100644 --- a/src/mame/drivers/system1.c +++ b/src/mame/drivers/system1.c @@ -203,20 +203,6 @@ Notes: #define SOUND_CLOCK XTAL_8MHz -/* driver config */ -static void (*videomode_custom)(running_machine *machine, UINT8 data, UINT8 prevdata); -static UINT8 mute_xor; - -static UINT8 *system1_ram; -static UINT8 dakkochn_mux_data; -static UINT8 videomode_prev; -static UINT8 mcu_control; -static UINT8 *nob_mcu_status; -static UINT8 *nob_mcu_latch; -static UINT8 nob_maincpu_latch; - - - /************************************* * * Machine initialization @@ -355,6 +341,7 @@ static const UINT8 cc_ex[0x100] = { static MACHINE_START( system1 ) { + system1_state *state = machine->driver_data(); UINT32 numbanks = (machine->region("maincpu")->bytes() - 0x10000) / 0x4000; if (numbanks > 0) @@ -365,25 +352,27 @@ static MACHINE_START( system1 ) z80_set_cycle_tables(machine->device("maincpu"), cc_op, cc_cb, cc_ed, cc_xy, cc_xycb, cc_ex); - mute_xor = 0x00; + state->mute_xor = 0x00; - state_save_register_global(machine, dakkochn_mux_data); - state_save_register_global(machine, videomode_prev); - state_save_register_global(machine, mcu_control); - state_save_register_global(machine, nob_maincpu_latch); + state_save_register_global(machine, state->dakkochn_mux_data); + state_save_register_global(machine, state->videomode_prev); + state_save_register_global(machine, state->mcu_control); + state_save_register_global(machine, state->nob_maincpu_latch); } static MACHINE_START( system2 ) { + system1_state *state = machine->driver_data(); MACHINE_START_CALL(system1); - mute_xor = 0x01; + state->mute_xor = 0x01; } static MACHINE_RESET( system1 ) { - dakkochn_mux_data = 0; + system1_state *state = machine->driver_data(); + state->dakkochn_mux_data = 0; } @@ -410,6 +399,7 @@ static void bank0c_custom_w(running_machine *machine, UINT8 data, UINT8 prevdata static WRITE8_HANDLER( videomode_w ) { + system1_state *state = space->machine->driver_data(); device_t *i8751 = space->machine->device("mcu"); /* bit 6 is connected to the 8751 IRQ */ @@ -417,9 +407,9 @@ static WRITE8_HANDLER( videomode_w ) cpu_set_input_line(i8751, MCS51_INT1_LINE, (data & 0x40) ? CLEAR_LINE : ASSERT_LINE); /* handle any custom banking or other stuff */ - if (videomode_custom != NULL) - (*videomode_custom)(space->machine, data, videomode_prev); - videomode_prev = data; + if (state->videomode_custom != NULL) + (*state->videomode_custom)(space->machine, data, state->videomode_prev); + state->videomode_prev = data; /* bit 0 is for the coin counters */ coin_counter_w(space->machine, 0, data & 1); @@ -438,23 +428,26 @@ static WRITE8_HANDLER( videomode_w ) static CUSTOM_INPUT( dakkochn_mux_data_r ) { + system1_state *state = field->port->machine->driver_data(); static const char *const ports[] = { "KEY0", "KEY1", "KEY2", "KEY3", "KEY4", "KEY5", "KEY6" }; - return input_port_read(field->port->machine, ports[dakkochn_mux_data]); + return input_port_read(field->port->machine, ports[state->dakkochn_mux_data]); } static CUSTOM_INPUT( dakkochn_mux_status_r ) { + system1_state *state = field->port->machine->driver_data(); /* reads from here indicate which mux port is selected */ - return 1 << (dakkochn_mux_data); + return 1 << (state->dakkochn_mux_data); } static void dakkochn_custom_w(running_machine *machine, UINT8 data, UINT8 prevdata) { + system1_state *state = machine->driver_data(); /* bit 1 toggling on clocks the mux; we store the previous state in the high bit of dakkochn_mux_data */ if ((data & 0x02) && !(prevdata & 0x02)) - dakkochn_mux_data = (dakkochn_mux_data + 1) % 7; + state->dakkochn_mux_data = (state->dakkochn_mux_data + 1) % 7; /* remaining stuff acts like bank0c */ bank0c_custom_w(machine, data, prevdata); @@ -470,8 +463,9 @@ static void dakkochn_custom_w(running_machine *machine, UINT8 data, UINT8 prevda static WRITE8_DEVICE_HANDLER( sound_control_w ) { + system1_state *state = device->machine->driver_data(); /* bit 0 = MUTE (inverted sense on System 2) */ - device->machine->sound().system_mute((data ^ mute_xor) & 1); + device->machine->sound().system_mute((data ^ state->mute_xor) & 1); /* bit 6 = feedback from sound board that read occurrred */ @@ -534,6 +528,7 @@ static TIMER_DEVICE_CALLBACK( soundirq_gen ) static WRITE8_HANDLER( mcu_control_w ) { + system1_state *state = space->machine->driver_data(); /* Bit 7 -> connects to TD62003 pins 5 & 6 @ IC151 Bit 6 -> via PLS153, when high, asserts the BUSREQ signal, halting the Z80 @@ -544,7 +539,7 @@ static WRITE8_HANDLER( mcu_control_w ) Bit 1 -> n/c Bit 0 -> Directly connected to Z80 /INT line */ - mcu_control = data; + state->mcu_control = data; cputag_set_input_line(space->machine, "maincpu", INPUT_LINE_HALT, (data & 0x40) ? ASSERT_LINE : CLEAR_LINE); cputag_set_input_line(space->machine, "maincpu", 0, (data & 0x01) ? CLEAR_LINE : ASSERT_LINE); } @@ -552,7 +547,8 @@ static WRITE8_HANDLER( mcu_control_w ) static WRITE8_HANDLER( mcu_io_w ) { - switch ((mcu_control >> 3) & 3) + system1_state *state = space->machine->driver_data(); + switch ((state->mcu_control >> 3) & 3) { case 0: space->machine->device("maincpu")->space(AS_PROGRAM)->write_byte(offset, data); @@ -564,7 +560,7 @@ static WRITE8_HANDLER( mcu_io_w ) default: logerror("%03X: MCU movx write mode %02X offset %04X = %02X\n", - cpu_get_pc(space->cpu), mcu_control, offset, data); + cpu_get_pc(space->cpu), state->mcu_control, offset, data); break; } } @@ -572,7 +568,8 @@ static WRITE8_HANDLER( mcu_io_w ) static READ8_HANDLER( mcu_io_r ) { - switch ((mcu_control >> 3) & 3) + system1_state *state = space->machine->driver_data(); + switch ((state->mcu_control >> 3) & 3) { case 0: return space->machine->device("maincpu")->space(AS_PROGRAM)->read_byte(offset); @@ -585,7 +582,7 @@ static READ8_HANDLER( mcu_io_r ) default: logerror("%03X: MCU movx read mode %02X offset %04X\n", - cpu_get_pc(space->cpu), mcu_control, offset); + cpu_get_pc(space->cpu), state->mcu_control, offset); return 0xff; } } @@ -623,37 +620,40 @@ static TIMER_DEVICE_CALLBACK( mcu_t0_callback ) static WRITE8_HANDLER( nob_mcu_control_p2_w ) { + system1_state *state = space->machine->driver_data(); /* bit 0 triggers a read from MCU port 0 */ - if (((mcu_control ^ data) & 0x01) && !(data & 0x01)) - *nob_mcu_latch = nob_maincpu_latch; + if (((state->mcu_control ^ data) & 0x01) && !(data & 0x01)) + *state->nob_mcu_latch = state->nob_maincpu_latch; /* bit 1 triggers a write from MCU port 0 */ - if (((mcu_control ^ data) & 0x02) && !(data & 0x02)) - nob_maincpu_latch = *nob_mcu_latch; + if (((state->mcu_control ^ data) & 0x02) && !(data & 0x02)) + state->nob_maincpu_latch = *state->nob_mcu_latch; /* bit 2 is toggled once near the end of an IRQ */ - if (((mcu_control ^ data) & 0x04) && !(data & 0x04)) + if (((state->mcu_control ^ data) & 0x04) && !(data & 0x04)) cpu_set_input_line(space->cpu, MCS51_INT0_LINE, CLEAR_LINE); /* bit 3 is toggled once at the start of an IRQ, and again at the end */ - if (((mcu_control ^ data) & 0x08) && !(data & 0x08)) + if (((state->mcu_control ^ data) & 0x08) && !(data & 0x08)) { //logerror("MCU IRQ(8) toggle\n"); } - mcu_control = data; + state->mcu_control = data; } static READ8_HANDLER( nob_maincpu_latch_r ) { - return nob_maincpu_latch; + system1_state *state = space->machine->driver_data(); + return state->nob_maincpu_latch; } static WRITE8_HANDLER( nob_maincpu_latch_w ) { - nob_maincpu_latch = data; + system1_state *state = space->machine->driver_data(); + state->nob_maincpu_latch = data; cputag_set_input_line(space->machine, "mcu", MCS51_INT0_LINE, ASSERT_LINE); space->machine->scheduler().boost_interleave(attotime::zero, attotime::from_usec(100)); } @@ -661,7 +661,8 @@ static WRITE8_HANDLER( nob_maincpu_latch_w ) static READ8_HANDLER( nob_mcu_status_r ) { - return *nob_mcu_status; + system1_state *state = space->machine->driver_data(); + return *state->nob_mcu_status; } @@ -673,7 +674,6 @@ static READ8_HANDLER( nob_mcu_status_r ) *************************************/ // nobb - these ports are used for some kind of replacement protection system used by the bootleg -static int nobb_inport23_step; static READ8_HANDLER( nobb_inport1c_r ) { @@ -689,14 +689,16 @@ static READ8_HANDLER( nobb_inport22_r ) static READ8_HANDLER( nobb_inport23_r ) { -// logerror("IN $23 : pc = %04x - step = %02x\n",cpu_get_pc(space->cpu),nobb_inport23_step); - return(nobb_inport23_step); + system1_state *state = space->machine->driver_data(); +// logerror("IN $23 : pc = %04x - step = %02x\n",cpu_get_pc(space->cpu),state->nobb_inport23_step); + return(state->nobb_inport23_step); } static WRITE8_HANDLER( nobb_outport24_w ) { + system1_state *state = space->machine->driver_data(); // logerror("OUT $24 : pc = %04x - data = %02x\n",cpu_get_pc(space->cpu),data); - nobb_inport23_step = data; + state->nobb_inport23_step = data; } @@ -711,7 +713,7 @@ static WRITE8_HANDLER( nobb_outport24_w ) static ADDRESS_MAP_START( system1_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x0000, 0x7fff) AM_ROM AM_RANGE(0x8000, 0xbfff) AM_ROMBANK("bank1") - AM_RANGE(0xc000, 0xcfff) AM_RAM AM_BASE(&system1_ram) + AM_RANGE(0xc000, 0xcfff) AM_RAM AM_BASE_MEMBER(system1_state, ram) AM_RANGE(0xd000, 0xd7ff) AM_RAM AM_BASE_GENERIC(spriteram) AM_RANGE(0xd800, 0xdfff) AM_RAM_WRITE(system1_paletteram_w) AM_BASE_GENERIC(paletteram) AM_RANGE(0xe000, 0xefff) AM_READWRITE(system1_videoram_r, system1_videoram_w) @@ -732,7 +734,7 @@ static ADDRESS_MAP_START( nobo_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0xd000, 0xd7ff) AM_RAM AM_BASE_GENERIC(spriteram) AM_RANGE(0xd800, 0xdfff) AM_RAM_WRITE(system1_paletteram_w) AM_BASE_GENERIC(paletteram) AM_RANGE(0xe000, 0xefff) AM_READWRITE(system1_videoram_r, system1_videoram_w) - AM_RANGE(0xf000, 0xffff) AM_RAM AM_BASE(&system1_ram) + AM_RANGE(0xf000, 0xffff) AM_RAM AM_BASE_MEMBER(system1_state, ram) ADDRESS_MAP_END /* I/O map for systems with an 8255 PPI */ @@ -792,8 +794,8 @@ ADDRESS_MAP_END static ADDRESS_MAP_START( nob_mcu_io_map, ADDRESS_SPACE_IO, 8 ) ADDRESS_MAP_UNMAP_HIGH - AM_RANGE(MCS51_PORT_P0, MCS51_PORT_P0) AM_RAM AM_BASE(&nob_mcu_latch) - AM_RANGE(MCS51_PORT_P1, MCS51_PORT_P1) AM_WRITEONLY AM_BASE(&nob_mcu_status) + AM_RANGE(MCS51_PORT_P0, MCS51_PORT_P0) AM_RAM AM_BASE_MEMBER(system1_state, nob_mcu_latch) + AM_RANGE(MCS51_PORT_P1, MCS51_PORT_P1) AM_WRITEONLY AM_BASE_MEMBER(system1_state, nob_mcu_status) AM_RANGE(MCS51_PORT_P2, MCS51_PORT_P2) AM_WRITE(nob_mcu_control_p2_w) ADDRESS_MAP_END @@ -4490,9 +4492,22 @@ ROM_END * *************************************/ -static DRIVER_INIT( bank00 ) { videomode_custom = NULL; } -static DRIVER_INIT( bank44 ) { videomode_custom = bank44_custom_w; } -static DRIVER_INIT( bank0c ) { videomode_custom = bank0c_custom_w; } +static DRIVER_INIT( bank00 ) +{ + system1_state *state = machine->driver_data(); + state->videomode_custom = NULL; +} +static DRIVER_INIT( bank44 ) +{ + system1_state *state = machine->driver_data(); + state->videomode_custom = bank44_custom_w; +} + +static DRIVER_INIT( bank0c ) +{ + system1_state *state = machine->driver_data(); + state->videomode_custom = bank0c_custom_w; +} static DRIVER_INIT( regulus ) { DRIVER_INIT_CALL(bank00); regulus_decode(machine, "maincpu"); } static DRIVER_INIT( mrviking ) { DRIVER_INIT_CALL(bank00); mrviking_decode(machine, "maincpu"); } @@ -4524,8 +4539,8 @@ static DRIVER_INIT( wboysys2 ) { DRIVER_INIT_CALL(bank0c); sega_315_5177_decode( static DRIVER_INIT( dakkochn ) { - DRIVER_INIT_CALL(bank0c); - videomode_custom = dakkochn_custom_w; + system1_state *state = machine->driver_data(); + state->videomode_custom = dakkochn_custom_w; mc8123_decrypt_rom(machine, "maincpu", "key", "bank1", 4); diff --git a/src/mame/drivers/timetrv.c b/src/mame/drivers/timetrv.c index b08d04af8ed..c11824e468e 100644 --- a/src/mame/drivers/timetrv.c +++ b/src/mame/drivers/timetrv.c @@ -26,7 +26,18 @@ CPU is an Intel 80188 #include "emu.h" #include "cpu/i86/i86.h" -static UINT8 *led_vram_lo,*led_vram_hi; + +class timetrv_state : public driver_device +{ +public: + timetrv_state(running_machine &machine, const driver_device_config_base &config) + : driver_device(machine, config) { } + + UINT8 *led_vram_lo; + UINT8 *led_vram_hi; +}; + + static VIDEO_START( timetrv ) { @@ -35,7 +46,8 @@ static VIDEO_START( timetrv ) static VIDEO_UPDATE( timetrv ) { - popmessage("%s%s",led_vram_lo,led_vram_hi); + timetrv_state *state = screen->machine->driver_data(); + popmessage("%s%s",state->led_vram_lo,state->led_vram_hi); return 0; } @@ -75,8 +87,8 @@ static ADDRESS_MAP_START( timetrv_io, ADDRESS_SPACE_IO, 8 ) AM_RANGE(0x1080, 0x1082) AM_READ(in_r) //dsw AM_RANGE(0x1100, 0x1105) AM_WRITENOP //laserdisc write area AM_RANGE(0x1100, 0x1105) AM_READ(ld_r) //5 -> laserdisc read status - AM_RANGE(0x1180, 0x1187) AM_RAM AM_BASE(&led_vram_lo)//led string,part 1 - AM_RANGE(0x1200, 0x1207) AM_RAM AM_BASE(&led_vram_hi)//led string,part 2 + AM_RANGE(0x1180, 0x1187) AM_RAM AM_BASE_MEMBER(timetrv_state, led_vram_lo)//led string,part 1 + AM_RANGE(0x1200, 0x1207) AM_RAM AM_BASE_MEMBER(timetrv_state, led_vram_hi)//led string,part 2 AM_RANGE(0xff80, 0xffff) AM_RAM //am80188-em-like cpu internal regs? ADDRESS_MAP_END @@ -125,7 +137,7 @@ static INTERRUPT_GEN( ld_irq ) cpu_set_input_line_and_vector(device,0,HOLD_LINE,0x48/4); //ld irq } -static MACHINE_CONFIG_START( timetrv, driver_device ) +static MACHINE_CONFIG_START( timetrv, timetrv_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu",I80188,20000000) //??? diff --git a/src/mame/drivers/tp84.c b/src/mame/drivers/tp84.c index 753413c7426..54233f09f15 100644 --- a/src/mame/drivers/tp84.c +++ b/src/mame/drivers/tp84.c @@ -72,22 +72,23 @@ C004 76489 #4 trigger #include "includes/konamipt.h" #include "includes/tp84.h" -static cpu_device *audiocpu; static MACHINE_START( tp84 ) { - audiocpu = machine->device("audiocpu"); + tp84_state *state = machine->driver_data(); + state->audiocpu = machine->device("audiocpu"); } static READ8_HANDLER( tp84_sh_timer_r ) { + tp84_state *state = space->machine->driver_data(); /* main xtal 14.318MHz, divided by 4 to get the CPU clock, further */ /* divided by 2048 to get this timer */ /* (divide by (2048/2), and not 1024, because the CPU cycle counter is */ /* incremented every other state change of the clock) */ - return (audiocpu->total_cycles() / (2048/2)) & 0x0f; + return (state->audiocpu->total_cycles() / (2048/2)) & 0x0f; } @@ -127,43 +128,43 @@ static WRITE8_HANDLER( tp84_sh_irqtrigger_w ) static ADDRESS_MAP_START( tp84_cpu1_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x2000, 0x2000) AM_WRITE(watchdog_reset_w) - AM_RANGE(0x2800, 0x2800) AM_READ_PORT("SYSTEM") AM_WRITEONLY AM_BASE(&tp84_palette_bank) + AM_RANGE(0x2800, 0x2800) AM_READ_PORT("SYSTEM") AM_WRITEONLY AM_BASE_MEMBER(tp84_state, palette_bank) AM_RANGE(0x2820, 0x2820) AM_READ_PORT("P1") AM_RANGE(0x2840, 0x2840) AM_READ_PORT("P2") AM_RANGE(0x2860, 0x2860) AM_READ_PORT("DSW1") AM_RANGE(0x3000, 0x3000) AM_READ_PORT("DSW2") AM_WRITEONLY - AM_RANGE(0x3004, 0x3004) AM_WRITEONLY AM_BASE(&tp84_flipscreen_x) - AM_RANGE(0x3005, 0x3005) AM_WRITEONLY AM_BASE(&tp84_flipscreen_y) + AM_RANGE(0x3004, 0x3004) AM_WRITEONLY AM_BASE_MEMBER(tp84_state, flipscreen_x) + AM_RANGE(0x3005, 0x3005) AM_WRITEONLY AM_BASE_MEMBER(tp84_state, flipscreen_y) AM_RANGE(0x3800, 0x3800) AM_WRITE(tp84_sh_irqtrigger_w) AM_RANGE(0x3a00, 0x3a00) AM_WRITE(soundlatch_w) - AM_RANGE(0x3c00, 0x3c00) AM_WRITEONLY AM_BASE(&tp84_scroll_x) - AM_RANGE(0x3e00, 0x3e00) AM_WRITEONLY AM_BASE(&tp84_scroll_y) - AM_RANGE(0x4000, 0x43ff) AM_RAM AM_BASE(&tp84_bg_videoram) - AM_RANGE(0x4400, 0x47ff) AM_RAM AM_BASE(&tp84_fg_videoram) - AM_RANGE(0x4800, 0x4bff) AM_RAM AM_BASE(&tp84_bg_colorram) - AM_RANGE(0x4c00, 0x4fff) AM_RAM AM_BASE(&tp84_fg_colorram) + AM_RANGE(0x3c00, 0x3c00) AM_WRITEONLY AM_BASE_MEMBER(tp84_state, scroll_x) + AM_RANGE(0x3e00, 0x3e00) AM_WRITEONLY AM_BASE_MEMBER(tp84_state, scroll_y) + AM_RANGE(0x4000, 0x43ff) AM_RAM AM_BASE_MEMBER(tp84_state, bg_videoram) + AM_RANGE(0x4400, 0x47ff) AM_RAM AM_BASE_MEMBER(tp84_state, fg_videoram) + AM_RANGE(0x4800, 0x4bff) AM_RAM AM_BASE_MEMBER(tp84_state, bg_colorram) + AM_RANGE(0x4c00, 0x4fff) AM_RAM AM_BASE_MEMBER(tp84_state, fg_colorram) AM_RANGE(0x5000, 0x57ff) AM_RAM AM_SHARE("share1") AM_RANGE(0x8000, 0xffff) AM_ROM ADDRESS_MAP_END static ADDRESS_MAP_START( tp84b_cpu1_map, ADDRESS_SPACE_PROGRAM, 8 ) - AM_RANGE(0x0000, 0x03ff) AM_RAM AM_BASE(&tp84_bg_videoram) - AM_RANGE(0x0400, 0x07ff) AM_RAM AM_BASE(&tp84_fg_videoram) - AM_RANGE(0x0800, 0x0bff) AM_RAM AM_BASE(&tp84_bg_colorram) - AM_RANGE(0x0c00, 0x0fff) AM_RAM AM_BASE(&tp84_fg_colorram) + AM_RANGE(0x0000, 0x03ff) AM_RAM AM_BASE_MEMBER(tp84_state, bg_videoram) + AM_RANGE(0x0400, 0x07ff) AM_RAM AM_BASE_MEMBER(tp84_state, fg_videoram) + AM_RANGE(0x0800, 0x0bff) AM_RAM AM_BASE_MEMBER(tp84_state, bg_colorram) + AM_RANGE(0x0c00, 0x0fff) AM_RAM AM_BASE_MEMBER(tp84_state, fg_colorram) AM_RANGE(0x1000, 0x17ff) AM_RAM AM_SHARE("share1") AM_RANGE(0x1800, 0x1800) AM_WRITE(watchdog_reset_w) - AM_RANGE(0x1a00, 0x1a00) AM_READ_PORT("SYSTEM") AM_WRITEONLY AM_BASE(&tp84_palette_bank) + AM_RANGE(0x1a00, 0x1a00) AM_READ_PORT("SYSTEM") AM_WRITEONLY AM_BASE_MEMBER(tp84_state, palette_bank) AM_RANGE(0x1a20, 0x1a20) AM_READ_PORT("P1") AM_RANGE(0x1a40, 0x1a40) AM_READ_PORT("P2") AM_RANGE(0x1a60, 0x1a60) AM_READ_PORT("DSW1") AM_RANGE(0x1c00, 0x1c00) AM_READ_PORT("DSW2") AM_WRITENOP - AM_RANGE(0x1c04, 0x1c04) AM_WRITEONLY AM_BASE(&tp84_flipscreen_x) - AM_RANGE(0x1c05, 0x1c05) AM_WRITEONLY AM_BASE(&tp84_flipscreen_y) + AM_RANGE(0x1c04, 0x1c04) AM_WRITEONLY AM_BASE_MEMBER(tp84_state, flipscreen_x) + AM_RANGE(0x1c05, 0x1c05) AM_WRITEONLY AM_BASE_MEMBER(tp84_state, flipscreen_y) AM_RANGE(0x1e00, 0x1e00) AM_WRITE(tp84_sh_irqtrigger_w) AM_RANGE(0x1e80, 0x1e80) AM_WRITE(soundlatch_w) - AM_RANGE(0x1f00, 0x1f00) AM_WRITEONLY AM_BASE(&tp84_scroll_x) - AM_RANGE(0x1f80, 0x1f80) AM_WRITEONLY AM_BASE(&tp84_scroll_y) + AM_RANGE(0x1f00, 0x1f00) AM_WRITEONLY AM_BASE_MEMBER(tp84_state, scroll_x) + AM_RANGE(0x1f80, 0x1f80) AM_WRITEONLY AM_BASE_MEMBER(tp84_state, scroll_y) AM_RANGE(0x8000, 0xffff) AM_ROM ADDRESS_MAP_END @@ -173,7 +174,7 @@ static ADDRESS_MAP_START( cpu2_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x2000, 0x2000) AM_READ(tp84_scanline_r) /* beam position */ AM_RANGE(0x4000, 0x4000) AM_WRITE(interrupt_enable_w) AM_RANGE(0x6000, 0x679f) AM_RAM - AM_RANGE(0x67a0, 0x67ff) AM_RAM_WRITE(tp84_spriteram_w) AM_BASE(&tp84_spriteram) + AM_RANGE(0x67a0, 0x67ff) AM_RAM_WRITE(tp84_spriteram_w) AM_BASE_MEMBER(tp84_state, spriteram) AM_RANGE(0x8000, 0x87ff) AM_RAM AM_SHARE("share1") AM_RANGE(0xe000, 0xffff) AM_ROM ADDRESS_MAP_END @@ -274,7 +275,7 @@ GFXDECODE_END -static MACHINE_CONFIG_START( tp84, driver_device ) +static MACHINE_CONFIG_START( tp84, tp84_state ) /* basic machine hardware */ MCFG_CPU_ADD("cpu1",M6809, XTAL_18_432MHz/12) /* verified on pcb */ diff --git a/src/mame/drivers/twin16.c b/src/mame/drivers/twin16.c index d159559ef19..84b9c9fd4e6 100644 --- a/src/mame/drivers/twin16.c +++ b/src/mame/drivers/twin16.c @@ -53,26 +53,18 @@ Known Issues: #include "includes/twin16.h" #include "includes/konamipt.h" -UINT16 twin16_custom_video; -UINT16 *twin16_gfx_rom; -UINT16 *twin16_sprite_gfx_ram; -UINT16 *twin16_tile_gfx_ram; -UINT16 *twin16_text_ram; - -static UINT16 twin16_CPUA_register, twin16_CPUB_register; - -#define CPUA_IRQ_ENABLE (twin16_CPUA_register & 0x20) -#define CPUB_IRQ_ENABLE (twin16_CPUB_register & 0x02) - -static UINT16 twin16_sound_command; - -static int cuebrickj_nvram_bank; -static UINT16 cuebrickj_nvram[0x400*0x20]; // 32k paged in a 1k window -int twin16_spriteram_process_enable( void ) +#define CPUA_IRQ_ENABLE (state->CPUA_register & 0x20) +#define CPUB_IRQ_ENABLE (state->CPUB_register & 0x02) + + + + +int twin16_spriteram_process_enable( running_machine *machine ) { - return (twin16_CPUA_register & 0x40) == 0; + twin16_state *state = machine->driver_data(); + return (state->CPUA_register & 0x40) == 0; } /******************************************************************************************/ @@ -103,22 +95,26 @@ static READ16_HANDLER( extra_rom_r ) static READ16_HANDLER( twin16_gfx_rom1_r ) { - return twin16_gfx_rom[offset + ((twin16_CPUB_register&0x04)?0x40000:0)]; + twin16_state *state = space->machine->driver_data(); + return state->gfx_rom[offset + ((state->CPUB_register&0x04)?0x40000:0)]; } static READ16_HANDLER( twin16_gfx_rom2_r ) { - return twin16_gfx_rom[offset + 0x80000 + ((twin16_CPUB_register&0x04)?0x40000:0)]; + twin16_state *state = space->machine->driver_data(); + return state->gfx_rom[offset + 0x80000 + ((state->CPUB_register&0x04)?0x40000:0)]; } static WRITE16_HANDLER( sound_command_w ) { - COMBINE_DATA(&twin16_sound_command); - soundlatch_w( space, 0, twin16_sound_command&0xff ); + twin16_state *state = space->machine->driver_data(); + COMBINE_DATA(&state->sound_command); + soundlatch_w( space, 0, state->sound_command&0xff ); } static WRITE16_HANDLER( twin16_CPUA_register_w ) { + twin16_state *state = space->machine->driver_data(); /* 7 6 5 4 3 2 1 0 X sprite processing disable @@ -127,58 +123,60 @@ static WRITE16_HANDLER( twin16_CPUA_register_w ) X 0->1 trigger IRQ on sound CPU x x x coin counters */ - UINT16 old = twin16_CPUA_register; - COMBINE_DATA(&twin16_CPUA_register); - if (twin16_CPUA_register != old) + UINT16 old = state->CPUA_register; + COMBINE_DATA(&state->CPUA_register); + if (state->CPUA_register != old) { - if ((old & 0x08) == 0 && (twin16_CPUA_register & 0x08)) + if ((old & 0x08) == 0 && (state->CPUA_register & 0x08)) cputag_set_input_line_and_vector(space->machine, "audiocpu", 0, HOLD_LINE, 0xff); - if ((old & 0x40) && (twin16_CPUA_register & 0x40) == 0) + if ((old & 0x40) && (state->CPUA_register & 0x40) == 0) twin16_spriteram_process(space->machine); - if ((old & 0x10) == 0 && (twin16_CPUA_register & 0x10)) + if ((old & 0x10) == 0 && (state->CPUA_register & 0x10)) cputag_set_input_line(space->machine, "sub", M68K_IRQ_6, HOLD_LINE); - coin_counter_w(space->machine, 0, twin16_CPUA_register & 0x01); - coin_counter_w(space->machine, 1, twin16_CPUA_register & 0x02); - coin_counter_w(space->machine, 2, twin16_CPUA_register & 0x04); + coin_counter_w(space->machine, 0, state->CPUA_register & 0x01); + coin_counter_w(space->machine, 1, state->CPUA_register & 0x02); + coin_counter_w(space->machine, 2, state->CPUA_register & 0x04); } } static WRITE16_HANDLER( twin16_CPUB_register_w ) { + twin16_state *state = space->machine->driver_data(); /* 7 6 5 4 3 2 1 0 X gfx bank select X IRQ5 enable X 0->1 trigger IRQ6 on CPUA */ - UINT16 old = twin16_CPUB_register; - COMBINE_DATA(&twin16_CPUB_register); - if( twin16_CPUB_register!=old ) + UINT16 old = state->CPUB_register; + COMBINE_DATA(&state->CPUB_register); + if( state->CPUB_register!=old ) { - if ((old & 0x01) == 0 && (twin16_CPUB_register & 0x01)) + if ((old & 0x01) == 0 && (state->CPUB_register & 0x01)) cputag_set_input_line(space->machine, "maincpu", M68K_IRQ_6, HOLD_LINE); } } static WRITE16_HANDLER( fround_CPU_register_w ) { + twin16_state *state = space->machine->driver_data(); /* 7 6 5 4 3 2 1 0 X 0->1 trigger IRQ on sound CPU x x coin counters */ - UINT16 old = twin16_CPUA_register; - COMBINE_DATA(&twin16_CPUA_register); - if (twin16_CPUA_register != old) + UINT16 old = state->CPUA_register; + COMBINE_DATA(&state->CPUA_register); + if (state->CPUA_register != old) { - if ((old & 0x08) == 0 && (twin16_CPUA_register & 0x08)) + if ((old & 0x08) == 0 && (state->CPUA_register & 0x08)) cputag_set_input_line_and_vector(space->machine, "audiocpu", 0, HOLD_LINE, 0xff); - coin_counter_w(space->machine, 0, twin16_CPUA_register & 0x01); - coin_counter_w(space->machine, 1, twin16_CPUA_register & 0x02); + coin_counter_w(space->machine, 0, state->CPUA_register & 0x01); + coin_counter_w(space->machine, 1, state->CPUA_register & 0x02); } } @@ -215,17 +213,20 @@ static WRITE8_DEVICE_HANDLER( twin16_upd_start_w ) static READ16_HANDLER( cuebrickj_nvram_r ) { - return cuebrickj_nvram[offset + (cuebrickj_nvram_bank * 0x400 / 2)]; + twin16_state *state = space->machine->driver_data(); + return state->cuebrickj_nvram[offset + (state->cuebrickj_nvram_bank * 0x400 / 2)]; } static WRITE16_HANDLER( cuebrickj_nvram_w ) { - COMBINE_DATA(&cuebrickj_nvram[offset + (cuebrickj_nvram_bank * 0x400 / 2)]); + twin16_state *state = space->machine->driver_data(); + COMBINE_DATA(&state->cuebrickj_nvram[offset + (state->cuebrickj_nvram_bank * 0x400 / 2)]); } static WRITE16_HANDLER( cuebrickj_nvram_bank_w ) { - cuebrickj_nvram_bank = (data >> 8); + twin16_state *state = space->machine->driver_data(); + state->cuebrickj_nvram_bank = (data >> 8); } /* Memory Maps */ @@ -257,7 +258,7 @@ static ADDRESS_MAP_START( main_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x0b0400, 0x0b0401) AM_WRITE(cuebrickj_nvram_bank_w) AM_RANGE(0x0c0000, 0x0c000f) AM_WRITE(twin16_video_register_w) AM_RANGE(0x0c000e, 0x0c000f) AM_READ(twin16_sprite_status_r) - AM_RANGE(0x100000, 0x103fff) AM_RAM_WRITE(twin16_text_ram_w) AM_BASE(&twin16_text_ram) + AM_RANGE(0x100000, 0x103fff) AM_RAM_WRITE(twin16_text_ram_w) AM_BASE_MEMBER(twin16_state, text_ram) // AM_RANGE(0x104000, 0x105fff) AM_NOP // miaj AM_RANGE(0x120000, 0x123fff) AM_RAM AM_BASE_MEMBER(twin16_state, videoram) AM_RANGE(0x140000, 0x143fff) AM_RAM AM_SHARE("share1") AM_BASE_SIZE_GENERIC(spriteram) @@ -272,10 +273,10 @@ static ADDRESS_MAP_START( sub_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x0a0000, 0x0a0001) AM_WRITE(twin16_CPUB_register_w) AM_RANGE(0x400000, 0x403fff) AM_RAM AM_SHARE("share1") AM_RANGE(0x480000, 0x483fff) AM_READWRITE(videoram16_r, videoram16_w) - AM_RANGE(0x500000, 0x53ffff) AM_RAM AM_BASE(&twin16_tile_gfx_ram) + AM_RANGE(0x500000, 0x53ffff) AM_RAM AM_BASE_MEMBER(twin16_state, tile_gfx_ram) AM_RANGE(0x600000, 0x6fffff) AM_READ(twin16_gfx_rom1_r) AM_RANGE(0x700000, 0x77ffff) AM_READ(twin16_gfx_rom2_r) - AM_RANGE(0x780000, 0x79ffff) AM_RAM AM_BASE(&twin16_sprite_gfx_ram) + AM_RANGE(0x780000, 0x79ffff) AM_RAM AM_BASE_MEMBER(twin16_state, sprite_gfx_ram) ADDRESS_MAP_END static ADDRESS_MAP_START( fround_map, ADDRESS_SPACE_PROGRAM, 16 ) @@ -290,7 +291,7 @@ static ADDRESS_MAP_START( fround_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x0c0000, 0x0c000f) AM_WRITE(twin16_video_register_w) AM_RANGE(0x0c000e, 0x0c000f) AM_READ(twin16_sprite_status_r) AM_RANGE(0x0e0000, 0x0e0001) AM_WRITE(fround_gfx_bank_w) - AM_RANGE(0x100000, 0x103fff) AM_RAM_WRITE(twin16_text_ram_w) AM_BASE(&twin16_text_ram) + AM_RANGE(0x100000, 0x103fff) AM_RAM_WRITE(twin16_text_ram_w) AM_BASE_MEMBER(twin16_state, text_ram) AM_RANGE(0x120000, 0x123fff) AM_RAM AM_BASE_MEMBER(twin16_state, videoram) AM_RANGE(0x140000, 0x143fff) AM_RAM AM_BASE_SIZE_GENERIC(spriteram) AM_RANGE(0x500000, 0x6fffff) AM_READ(twin16_gfx_rom1_r) @@ -690,11 +691,13 @@ static const k007232_interface k007232_config = static INTERRUPT_GEN( CPUA_interrupt ) { + twin16_state *state = device->machine->driver_data(); if (CPUA_IRQ_ENABLE) cpu_set_input_line(device, 5, HOLD_LINE); } static INTERRUPT_GEN( CPUB_interrupt ) { + twin16_state *state = device->machine->driver_data(); if (CPUB_IRQ_ENABLE) cpu_set_input_line(device, 5, HOLD_LINE); } @@ -707,16 +710,17 @@ static MACHINE_RESET( twin16 ) static MACHINE_START( twin16 ) { - twin16_CPUA_register=0; - twin16_CPUB_register=0; + twin16_state *state = machine->driver_data(); + state->CPUA_register=0; + state->CPUB_register=0; /* register for savestates */ - state_save_register_global(machine, twin16_CPUA_register); - state_save_register_global(machine, twin16_CPUB_register); + state_save_register_global(machine, state->CPUA_register); + state_save_register_global(machine, state->CPUB_register); - state_save_register_global(machine, twin16_sound_command); - state_save_register_global(machine, cuebrickj_nvram_bank); - state_save_register_global_array(machine, cuebrickj_nvram); + state_save_register_global(machine, state->sound_command); + state_save_register_global(machine, state->cuebrickj_nvram_bank); + state_save_register_global_array(machine, state->cuebrickj_nvram); } static MACHINE_CONFIG_START( twin16, twin16_state ) @@ -1303,38 +1307,42 @@ ROM_END static void gfx_untangle( running_machine *machine ) { + twin16_state *state = machine->driver_data(); // sprite, tile data int i; UINT16 *temp = auto_alloc_array(machine, UINT16, 0x200000/2); - twin16_gfx_rom = (UINT16 *)machine->region("gfx2")->base(); - memcpy( temp, twin16_gfx_rom, 0x200000 ); + state->gfx_rom = (UINT16 *)machine->region("gfx2")->base(); + memcpy( temp, state->gfx_rom, 0x200000 ); for( i=0; i<0x080000; i++ ) { - twin16_gfx_rom[i*2+0] = temp[i+0x080000]; - twin16_gfx_rom[i*2+1] = temp[i]; + state->gfx_rom[i*2+0] = temp[i+0x080000]; + state->gfx_rom[i*2+1] = temp[i]; } auto_free( machine, temp ); } static DRIVER_INIT( twin16 ) { + twin16_state *state = machine->driver_data(); gfx_untangle(machine); - twin16_custom_video = 0; + state->custom_video = 0; } static DRIVER_INIT( fround ) { + twin16_state *state = machine->driver_data(); gfx_untangle(machine); - twin16_custom_video = 1; + state->custom_video = 1; } static DRIVER_INIT( cuebrickj ) { + twin16_state *state = machine->driver_data(); gfx_untangle(machine); - machine->device("nvram")->set_base(cuebrickj_nvram, 0x400*0x20); + machine->device("nvram")->set_base(state->cuebrickj_nvram, 0x400*0x20); } /* Game Drivers */ diff --git a/src/mame/drivers/ultrsprt.c b/src/mame/drivers/ultrsprt.c index 715aae21b45..6bafff7b6d8 100644 --- a/src/mame/drivers/ultrsprt.c +++ b/src/mame/drivers/ultrsprt.c @@ -17,14 +17,25 @@ TODO: #include "sound/k056800.h" -static UINT32 *vram; -static UINT32 *workram; +class ultrsprt_state : public driver_device +{ +public: + ultrsprt_state(running_machine &machine, const driver_device_config_base &config) + : driver_device(machine, config) { } + + UINT32 *vram; + UINT32 *workram; +}; + + + static VIDEO_UPDATE( ultrsprt ) { + ultrsprt_state *state = screen->machine->driver_data(); int i, j; - UINT8 *ram = (UINT8 *)vram; + UINT8 *ram = (UINT8 *)state->vram; for (j=0; j < 400; j++) { @@ -82,25 +93,26 @@ static WRITE32_HANDLER( int_ack_w ) static MACHINE_START( ultrsprt ) { + ultrsprt_state *state = machine->driver_data(); /* set conservative DRC options */ ppcdrc_set_options(machine->device("maincpu"), PPCDRC_COMPATIBLE_OPTIONS); /* configure fast RAM regions for DRC */ - ppcdrc_add_fastram(machine->device("maincpu"), 0x80000000, 0x8007ffff, FALSE, vram); - ppcdrc_add_fastram(machine->device("maincpu"), 0xff000000, 0xff01ffff, FALSE, workram); + ppcdrc_add_fastram(machine->device("maincpu"), 0x80000000, 0x8007ffff, FALSE, state->vram); + ppcdrc_add_fastram(machine->device("maincpu"), 0xff000000, 0xff01ffff, FALSE, state->workram); } static ADDRESS_MAP_START( ultrsprt_map, ADDRESS_SPACE_PROGRAM, 32 ) - AM_RANGE(0x00000000, 0x0007ffff) AM_RAM AM_BASE(&vram) + AM_RANGE(0x00000000, 0x0007ffff) AM_RAM AM_BASE_MEMBER(ultrsprt_state, vram) AM_RANGE(0x70000000, 0x70000003) AM_READWRITE(eeprom_r, eeprom_w) AM_RANGE(0x70000020, 0x70000023) AM_READ_PORT("P1") AM_RANGE(0x70000040, 0x70000043) AM_READ_PORT("P2") AM_RANGE(0x70000080, 0x70000087) AM_DEVWRITE("k056800", k056800_host_w) AM_RANGE(0x70000088, 0x7000008f) AM_DEVREAD("k056800", k056800_host_r) AM_RANGE(0x700000e0, 0x700000e3) AM_WRITE(int_ack_w) - AM_RANGE(0x7f000000, 0x7f01ffff) AM_RAM AM_BASE(&workram) + AM_RANGE(0x7f000000, 0x7f01ffff) AM_RAM AM_BASE_MEMBER(ultrsprt_state, workram) AM_RANGE(0x7f700000, 0x7f703fff) AM_RAM_WRITE(palette_w) AM_BASE_GENERIC(paletteram) AM_RANGE(0x7f800000, 0x7f9fffff) AM_MIRROR(0x00600000) AM_ROM AM_REGION("user1", 0) ADDRESS_MAP_END @@ -201,7 +213,7 @@ static const k056800_interface ultrsprt_k056800_interface = }; -static MACHINE_CONFIG_START( ultrsprt, driver_device ) +static MACHINE_CONFIG_START( ultrsprt, ultrsprt_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu", PPC403GA, 25000000) /* PowerPC 403GA 25MHz */ MCFG_CPU_PROGRAM_MAP(ultrsprt_map) diff --git a/src/mame/drivers/viper.c b/src/mame/drivers/viper.c index b0d1fa7708b..f4d1fb71ed0 100644 --- a/src/mame/drivers/viper.c +++ b/src/mame/drivers/viper.c @@ -45,6 +45,21 @@ DASM code snippets: #include "machine/timekpr.h" #include "video/voodoo.h" + +class viper_state : public driver_device +{ +public: + viper_state(running_machine &machine, const driver_device_config_base &config) + : driver_device(machine, config) { } + + UINT32 mpc8240_regs[256/4]; + UINT32 epic_iack; + int cf_card_ide; + int unk1_bit; + UINT32 voodoo3_pci_reg[0x100]; +}; + + //#define VIPER_DEBUG_LOG static VIDEO_UPDATE(viper) @@ -56,9 +71,9 @@ static VIDEO_UPDATE(viper) /*****************************************************************************/ -static UINT32 mpc8240_regs[256/4]; static UINT32 mpc8240_pci_r(device_t *busdevice, device_t *device, int function, int reg, UINT32 mem_mask) { + viper_state *state = device->machine->driver_data(); #ifdef VIPER_DEBUG_LOG printf("MPC8240: PCI read %d, %02X, %08X\n", function, reg, mem_mask); #endif @@ -67,16 +82,17 @@ static UINT32 mpc8240_pci_r(device_t *busdevice, device_t *device, int function, { } - return mpc8240_regs[reg/4]; + return state->mpc8240_regs[reg/4]; } static void mpc8240_pci_w(device_t *busdevice, device_t *device, int function, int reg, UINT32 data, UINT32 mem_mask) { + viper_state *state = device->machine->driver_data(); #ifdef VIPER_DEBUG_LOG printf("MPC8240: PCI write %d, %02X, %08X, %08X\n", function, reg, data, mem_mask); #endif - COMBINE_DATA(mpc8240_regs + (reg/4)); + COMBINE_DATA(state->mpc8240_regs + (reg/4)); } @@ -102,10 +118,10 @@ static WRITE64_DEVICE_HANDLER( pci_config_data_w ) -static UINT32 epic_iack; static READ32_HANDLER( epic_r ) { + viper_state *state = space->machine->driver_data(); int reg; reg = offset * 4; @@ -121,7 +137,7 @@ static READ32_HANDLER( epic_r ) switch (reg & 0xffff) { case 0x00a0: // IACK - return epic_iack; + return state->epic_iack; } break; @@ -133,6 +149,7 @@ static READ32_HANDLER( epic_r ) static WRITE32_HANDLER( epic_w ) { + viper_state *state = space->machine->driver_data(); int reg; reg = offset * 4; @@ -148,7 +165,7 @@ static WRITE32_HANDLER( epic_w ) switch (reg & 0xffff) { case 0x00b0: // EOI - epic_iack = 0xff; + state->epic_iack = 0xff; break; } break; @@ -166,7 +183,6 @@ static WRITE64_HANDLER(epic_64be_w) } -static int cf_card_ide = 0; static const UINT8 cf_card_tuples[] = { @@ -226,11 +242,12 @@ static WRITE64_DEVICE_HANDLER(cf_card_data_w) static READ64_DEVICE_HANDLER(cf_card_r) { + viper_state *state = device->machine->driver_data(); UINT64 r = 0; if (ACCESSING_BITS_16_31) { - if (cf_card_ide) + if (state->cf_card_ide) { switch (offset & 0xf) { @@ -289,6 +306,7 @@ static READ64_DEVICE_HANDLER(cf_card_r) static WRITE64_DEVICE_HANDLER(cf_card_w) { + viper_state *state = device->machine->driver_data(); #ifdef VIPER_DEBUG_LOG printf("%s:compact_flash_w: %08X%08X, %08X, %08X%08X\n", device->machine->describe_context(), (UINT32)(data>>32), (UINT32)(data), offset, (UINT32)(mem_mask >> 32), (UINT32)(mem_mask)); #endif @@ -341,7 +359,7 @@ static WRITE64_DEVICE_HANDLER(cf_card_w) { if ((data >> 16) & 0x80) { - cf_card_ide = 1; + state->cf_card_ide = 1; // soft reset // sector count register is set to 0x01 @@ -364,9 +382,10 @@ static WRITE64_DEVICE_HANDLER(cf_card_w) static WRITE64_HANDLER(unk2_w) { + viper_state *state = space->machine->driver_data(); if (ACCESSING_BITS_56_63) { - cf_card_ide = 0; + state->cf_card_ide = 0; } } @@ -397,15 +416,15 @@ static WRITE64_DEVICE_HANDLER(ata_w) } } -static int unk1_bit = 0; static READ64_HANDLER(unk1_r) { + viper_state *state = space->machine->driver_data(); UINT64 r = 0; //return 0;//U64(0x0000400000000000); if (ACCESSING_BITS_40_47) { - r |= (UINT64)(unk1_bit << 5) << 40; + r |= (UINT64)(state->unk1_bit << 5) << 40; } return r; @@ -413,23 +432,25 @@ static READ64_HANDLER(unk1_r) static WRITE64_HANDLER(unk1a_w) { + viper_state *state = space->machine->driver_data(); if (ACCESSING_BITS_56_63) { - unk1_bit = 1; + state->unk1_bit = 1; } } static WRITE64_HANDLER(unk1b_w) { + viper_state *state = space->machine->driver_data(); if (ACCESSING_BITS_56_63) { - unk1_bit = 0; + state->unk1_bit = 0; } } -static UINT32 voodoo3_pci_reg[0x100]; static UINT32 voodoo3_pci_r(device_t *busdevice, device_t *device, int function, int reg, UINT32 mem_mask) { + viper_state *state = device->machine->driver_data(); switch (reg) { case 0x00: // PCI Vendor ID (0x121a = 3dfx), Device ID (0x0005 = Voodoo 3) @@ -442,23 +463,23 @@ static UINT32 voodoo3_pci_r(device_t *busdevice, device_t *device, int function, } case 0x10: // memBaseAddr0 { - return voodoo3_pci_reg[0x10/4]; + return state->voodoo3_pci_reg[0x10/4]; } case 0x14: // memBaseAddr1 { - return voodoo3_pci_reg[0x14/4]; + return state->voodoo3_pci_reg[0x14/4]; } case 0x18: // memBaseAddr1 { - return voodoo3_pci_reg[0x18/4]; + return state->voodoo3_pci_reg[0x18/4]; } case 0x40: // fabId { - return voodoo3_pci_reg[0x40/4]; + return state->voodoo3_pci_reg[0x40/4]; } case 0x50: // cfgScratch { - return voodoo3_pci_reg[0x50/4]; + return state->voodoo3_pci_reg[0x50/4]; } default: @@ -469,24 +490,25 @@ static UINT32 voodoo3_pci_r(device_t *busdevice, device_t *device, int function, static void voodoo3_pci_w(device_t *busdevice, device_t *device, int function, int reg, UINT32 data, UINT32 mem_mask) { + viper_state *state = device->machine->driver_data(); // printf("voodoo3_pci_w: %08X, %08X\n", reg, data); switch (reg) { case 0x04: // Command register { - voodoo3_pci_reg[0x04/4] = data; + state->voodoo3_pci_reg[0x04/4] = data; break; } case 0x10: // memBaseAddr0 { if (data == 0xffffffff) { - voodoo3_pci_reg[0x10/4] = 0xfe000000; + state->voodoo3_pci_reg[0x10/4] = 0xfe000000; } else { - voodoo3_pci_reg[0x10/4] = data; + state->voodoo3_pci_reg[0x10/4] = data; } break; } @@ -494,11 +516,11 @@ static void voodoo3_pci_w(device_t *busdevice, device_t *device, int function, i { if (data == 0xffffffff) { - voodoo3_pci_reg[0x14/4] = 0xfe000008; + state->voodoo3_pci_reg[0x14/4] = 0xfe000008; } else { - voodoo3_pci_reg[0x14/4] = data; + state->voodoo3_pci_reg[0x14/4] = data; } break; } @@ -506,11 +528,11 @@ static void voodoo3_pci_w(device_t *busdevice, device_t *device, int function, i { if (data == 0xffffffff) { - voodoo3_pci_reg[0x18/4] = 0xffffff01; + state->voodoo3_pci_reg[0x18/4] = 0xffffff01; } else { - voodoo3_pci_reg[0x18/4] = data; + state->voodoo3_pci_reg[0x18/4] = data; } break; } @@ -520,12 +542,12 @@ static void voodoo3_pci_w(device_t *busdevice, device_t *device, int function, i } case 0x40: // fabId { - voodoo3_pci_reg[0x40/4] = data; + state->voodoo3_pci_reg[0x40/4] = data; break; } case 0x50: // cfgScratch { - voodoo3_pci_reg[0x50/4] = data; + state->voodoo3_pci_reg[0x50/4] = data; break; } @@ -614,7 +636,7 @@ static MACHINE_RESET(viper) devtag_reset(machine, "ide"); } -static MACHINE_CONFIG_START( viper, driver_device ) +static MACHINE_CONFIG_START( viper, viper_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu", MPC8240, 200000000) diff --git a/src/mame/drivers/wecleman.c b/src/mame/drivers/wecleman.c index 4c77a5bca42..7c73cfdd031 100644 --- a/src/mame/drivers/wecleman.c +++ b/src/mame/drivers/wecleman.c @@ -280,14 +280,6 @@ TODO: #include "wecleman.lh" #include "includes/wecleman.h" -/* Variables only used here: */ -static UINT16 *blitter_regs; -static int multiply_reg[2]; -static UINT16 *wecleman_protection_ram; -static int spr_color_offs; - -/* Variables that video has acces to: */ -int wecleman_selected_ip, wecleman_irqctrl; /*************************************************************************** Common Routines @@ -295,11 +287,12 @@ int wecleman_selected_ip, wecleman_irqctrl; static READ16_HANDLER( wecleman_protection_r ) { + wecleman_state *state = space->machine->driver_data(); int blend, data0, data1, r0, g0, b0, r1, g1, b1; - data0 = wecleman_protection_ram[0]; - blend = wecleman_protection_ram[2]; - data1 = wecleman_protection_ram[1]; + data0 = state->protection_ram[0]; + blend = state->protection_ram[2]; + data1 = state->protection_ram[1]; blend &= 0x3ff; // a precalculated table will take an astronomical 4096^2(colors) x 1024(steps) x 2(word) bytes @@ -321,10 +314,9 @@ static READ16_HANDLER( wecleman_protection_r ) static WRITE16_HANDLER( wecleman_protection_w ) { - static int state = 0; - - if (offset == 2) state = data & 0x2000; - if (!state) COMBINE_DATA(wecleman_protection_ram + offset); + wecleman_state *state = space->machine->driver_data(); + if (offset == 2) state->prot_state = data & 0x2000; + if (!state->prot_state) COMBINE_DATA(state->protection_ram + offset); } @@ -350,12 +342,13 @@ static WRITE16_HANDLER( wecleman_protection_w ) */ static WRITE16_HANDLER( irqctrl_w ) { + wecleman_state *state = space->machine->driver_data(); if (ACCESSING_BITS_0_7) { // logerror("CPU #0 - PC = %06X - $140005 <- %02X (old value: %02X)\n",cpu_get_pc(space->cpu), data&0xFF, old_data&0xFF); // Bit 0 : SUBINT - if ( (wecleman_irqctrl & 1) && (!(data & 1)) ) // 1->0 transition + if ( (state->irqctrl & 1) && (!(data & 1)) ) // 1->0 transition cputag_set_input_line(space->machine, "sub", 4, HOLD_LINE); // Bit 1 : NSUBRST @@ -369,7 +362,7 @@ static WRITE16_HANDLER( irqctrl_w ) // Bit 4 : SCR-HCNT // Bit 5 : SCR-VCNT // Bit 6 : TV-KILL - wecleman_irqctrl = data; // latch the value + state->irqctrl = data; // latch the value } } @@ -386,13 +379,15 @@ static WRITE16_HANDLER( irqctrl_w ) */ static WRITE16_HANDLER( selected_ip_w ) { - if (ACCESSING_BITS_0_7) wecleman_selected_ip = data & 0xff; // latch the value + wecleman_state *state = space->machine->driver_data(); + if (ACCESSING_BITS_0_7) state->selected_ip = data & 0xff; // latch the value } /* $140021.b - Return the previously selected input port's value */ static READ16_HANDLER( selected_ip_r ) { - switch ( (wecleman_selected_ip >> 5) & 3 ) + wecleman_state *state = space->machine->driver_data(); + switch ( (state->selected_ip >> 5) & 3 ) { // From WEC Le Mans Schems: case 0: return input_port_read(space->machine, "ACCEL"); // Accel - Schems: Accelevr case 1: return ~0; // ????? - Schems: Not Used @@ -439,32 +434,33 @@ static READ16_HANDLER( selected_ip_r ) */ static WRITE16_HANDLER( blitter_w ) { - COMBINE_DATA(&blitter_regs[offset]); + wecleman_state *state = space->machine->driver_data(); + COMBINE_DATA(&state->blitter_regs[offset]); /* do a blit if $80010.b has been written */ if ( (offset == 0x10/2) && (ACCESSING_BITS_8_15) ) { /* 80000.b = ?? usually 0 - other values: 02 ; 00 - ? logic function ? */ /* 80001.b = ?? usually 0 - other values: 3f ; 01 - ? height ? */ - int minterm = ( blitter_regs[0x0/2] & 0xFF00 ) >> 8; - int list_len = ( blitter_regs[0x0/2] & 0x00FF ) >> 0; + int minterm = ( state->blitter_regs[0x0/2] & 0xFF00 ) >> 8; + int list_len = ( state->blitter_regs[0x0/2] & 0x00FF ) >> 0; /* 80002.w = ?? always 0 - ? increment per horizontal line ? */ /* no proof at all, it's always 0 */ - //int srcdisp = blitter_regs[0x2/2] & 0xFF00; - //int destdisp = blitter_regs[0x2/2] & 0x00FF; + //int srcdisp = state->blitter_regs[0x2/2] & 0xFF00; + //int destdisp = state->blitter_regs[0x2/2] & 0x00FF; /* 80004.l = source data address */ - int src = ( blitter_regs[0x4/2] << 16 ) + blitter_regs[0x6/2]; + int src = ( state->blitter_regs[0x4/2] << 16 ) + state->blitter_regs[0x6/2]; /* 80008.l = list of blits address */ - int list = ( blitter_regs[0x8/2] << 16 ) + blitter_regs[0xA/2]; + int list = ( state->blitter_regs[0x8/2] << 16 ) + state->blitter_regs[0xA/2]; /* 8000C.l = destination address */ - int dest = ( blitter_regs[0xC/2] << 16 ) + blitter_regs[0xE/2]; + int dest = ( state->blitter_regs[0xC/2] << 16 ) + state->blitter_regs[0xE/2]; /* 80010.b = number of words to move */ - int size = ( blitter_regs[0x10/2] ) & 0x00FF; + int size = ( state->blitter_regs[0x10/2] ) & 0x00FF; /* Word aligned transfers only ?? */ src &= (~1); list &= (~1); dest &= (~1); @@ -497,7 +493,7 @@ static WRITE16_HANDLER( blitter_w ) space->write_word(destptr, space->read_word(i)); destptr = dest + 14; - i = space->read_word(list) + spr_color_offs; + i = space->read_word(list) + state->spr_color_offs; space->write_word(destptr, i); dest += 16; @@ -519,13 +515,13 @@ static WRITE16_HANDLER( wecleman_soundlatch_w ); static ADDRESS_MAP_START( wecleman_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x000000, 0x03ffff) AM_ROM // ROM (03c000-03ffff used as RAM sometimes!) - AM_RANGE(0x040494, 0x040495) AM_WRITE(wecleman_videostatus_w) AM_BASE(&wecleman_videostatus) // cloud blending control (HACK) + AM_RANGE(0x040494, 0x040495) AM_WRITE(wecleman_videostatus_w) AM_BASE_MEMBER(wecleman_state, videostatus) // cloud blending control (HACK) AM_RANGE(0x040000, 0x043fff) AM_RAM // RAM - AM_RANGE(0x060000, 0x060005) AM_WRITE(wecleman_protection_w) AM_BASE(&wecleman_protection_ram) + AM_RANGE(0x060000, 0x060005) AM_WRITE(wecleman_protection_w) AM_BASE_MEMBER(wecleman_state, protection_ram) AM_RANGE(0x060006, 0x060007) AM_READ(wecleman_protection_r) // MCU read - AM_RANGE(0x080000, 0x080011) AM_RAM_WRITE(blitter_w) AM_BASE(&blitter_regs) // Blitter - AM_RANGE(0x100000, 0x103fff) AM_RAM_WRITE(wecleman_pageram_w) AM_BASE(&wecleman_pageram) // Background Layers - AM_RANGE(0x108000, 0x108fff) AM_RAM_WRITE(wecleman_txtram_w) AM_BASE(&wecleman_txtram) // Text Layer + AM_RANGE(0x080000, 0x080011) AM_RAM_WRITE(blitter_w) AM_BASE_MEMBER(wecleman_state, blitter_regs) // Blitter + AM_RANGE(0x100000, 0x103fff) AM_RAM_WRITE(wecleman_pageram_w) AM_BASE_MEMBER(wecleman_state, pageram) // Background Layers + AM_RANGE(0x108000, 0x108fff) AM_RAM_WRITE(wecleman_txtram_w) AM_BASE_MEMBER(wecleman_state, txtram) // Text Layer AM_RANGE(0x110000, 0x110fff) AM_RAM_WRITE(wecleman_paletteram16_SSSSBBBBGGGGRRRR_word_w) AM_BASE_GENERIC(paletteram) AM_RANGE(0x124000, 0x127fff) AM_RAM AM_SHARE("share1") // Shared with main CPU AM_RANGE(0x130000, 0x130fff) AM_RAM AM_BASE_GENERIC(spriteram) // Sprites @@ -552,7 +548,7 @@ static WRITE16_HANDLER( hotchase_soundlatch_w ); static ADDRESS_MAP_START( hotchase_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x000000, 0x03ffff) AM_ROM AM_RANGE(0x040000, 0x063fff) AM_RAM // RAM (weird size!?) - AM_RANGE(0x080000, 0x080011) AM_RAM_WRITE(blitter_w) AM_BASE(&blitter_regs) // Blitter + AM_RANGE(0x080000, 0x080011) AM_RAM_WRITE(blitter_w) AM_BASE_MEMBER(wecleman_state, blitter_regs) // Blitter AM_RANGE(0x100000, 0x100fff) AM_DEVREADWRITE8("k051316_1", k051316_r, k051316_w, 0x00ff) // Background AM_RANGE(0x101000, 0x10101f) AM_DEVWRITE8("k051316_1", k051316_ctrl_w, 0x00ff) // Background Ctrl AM_RANGE(0x102000, 0x102fff) AM_DEVREADWRITE8("k051316_2", k051316_r, k051316_w, 0x00ff) // Foreground @@ -581,7 +577,7 @@ ADDRESS_MAP_END static ADDRESS_MAP_START( wecleman_sub_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x000000, 0x00ffff) AM_ROM // ROM - AM_RANGE(0x060000, 0x060fff) AM_RAM AM_BASE(&wecleman_roadram) AM_SIZE(&wecleman_roadram_size) // Road + AM_RANGE(0x060000, 0x060fff) AM_RAM AM_BASE_MEMBER(wecleman_state, roadram) AM_SIZE_MEMBER(wecleman_state, roadram_size) // Road AM_RANGE(0x070000, 0x073fff) AM_RAM AM_SHARE("share1") // RAM (Shared with main CPU) ADDRESS_MAP_END @@ -592,7 +588,7 @@ ADDRESS_MAP_END static ADDRESS_MAP_START( hotchase_sub_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x000000, 0x01ffff) AM_ROM // ROM - AM_RANGE(0x020000, 0x020fff) AM_RAM AM_BASE(&wecleman_roadram) AM_SIZE(&wecleman_roadram_size) // Road + AM_RANGE(0x020000, 0x020fff) AM_RAM AM_BASE_MEMBER(wecleman_state, roadram) AM_SIZE_MEMBER(wecleman_state, roadram_size) // Road AM_RANGE(0x040000, 0x043fff) AM_RAM AM_SHARE("share1") // Shared with main CPU AM_RANGE(0x060000, 0x060fff) AM_RAM // RAM ADDRESS_MAP_END @@ -615,12 +611,14 @@ WRITE16_HANDLER( wecleman_soundlatch_w ) /* Protection - an external multiplyer connected to the sound CPU */ static READ8_HANDLER( multiply_r ) { - return (multiply_reg[0] * multiply_reg[1]) & 0xFF; + wecleman_state *state = space->machine->driver_data(); + return (state->multiply_reg[0] * state->multiply_reg[1]) & 0xFF; } static WRITE8_HANDLER( multiply_w ) { - multiply_reg[offset] = data; + wecleman_state *state = space->machine->driver_data(); + state->multiply_reg[offset] = data; } /* K007232 registers reminder: @@ -1033,7 +1031,7 @@ static MACHINE_RESET( wecleman ) k007232_set_bank( machine->device("konami"), 0, 1 ); } -static MACHINE_CONFIG_START( wecleman, driver_device ) +static MACHINE_CONFIG_START( wecleman, wecleman_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu", M68000, 10000000) /* Schems show 10MHz */ @@ -1104,7 +1102,7 @@ static const k051316_interface hotchase_k051316_intf_1 = hotchase_zoom_callback_1 }; -static MACHINE_CONFIG_START( hotchase, driver_device ) +static MACHINE_CONFIG_START( hotchase, wecleman_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu", M68000, 10000000) /* 10 MHz - PCB is drawn in one set's readme */ @@ -1245,6 +1243,7 @@ static void bitswap(running_machine *machine,UINT8 *src,size_t len,int _14,int _ /* Unpack sprites data and do some patching */ static DRIVER_INIT( wecleman ) { + wecleman_state *state = machine->driver_data(); int i, len; UINT8 *RAM; // UINT16 *RAM1 = (UINT16 *) machine->region("maincpu")->base(); /* Main CPU patches */ @@ -1281,7 +1280,7 @@ static DRIVER_INIT( wecleman ) bitswap(machine, machine->region("gfx3")->base(), machine->region("gfx3")->bytes(), 20,19,18,17,16,15,14,7,12,4,2,5,6,13,8,9,11,3,10,1,0); - spr_color_offs = 0x40; + state->spr_color_offs = 0x40; } @@ -1388,6 +1387,7 @@ static void hotchase_sprite_decode( running_machine *machine, int num16_banks, i /* Unpack sprites data and do some patching */ static DRIVER_INIT( hotchase ) { + wecleman_state *state = machine->driver_data(); // UINT16 *RAM1 = (UINT16) machine->region("maincpu")->base(); /* Main CPU patches */ // RAM[0x1140/2] = 0x0015; RAM[0x195c/2] = 0x601A; // faster self test @@ -1405,7 +1405,7 @@ static DRIVER_INIT( hotchase ) RAM = machine->region("gfx3")->base(); memcpy(&RAM[0], &RAM[0x10000/2], 0x10000/2); - spr_color_offs = 0; + state->spr_color_offs = 0; } diff --git a/src/mame/drivers/zr107.c b/src/mame/drivers/zr107.c index f27ec8c97ec..3b857f84a2f 100644 --- a/src/mame/drivers/zr107.c +++ b/src/mame/drivers/zr107.c @@ -176,7 +176,22 @@ Check gticlub.c for details on the bottom board. #include "video/konicdev.h" #include "video/gticlub.h" -static UINT8 led_reg0, led_reg1; + +class zr107_state : public driver_device +{ +public: + zr107_state(running_machine &machine, const driver_device_config_base &config) + : driver_device(machine, config) { } + + UINT8 led_reg0; + UINT8 led_reg1; + int ccu_vcth; + int ccu_vctl; + UINT32 *workram; + UINT32 *sharc_dataram; +}; + + @@ -189,6 +204,7 @@ static VIDEO_START( jetwave ) static VIDEO_UPDATE( jetwave ) { + zr107_state *state = screen->machine->driver_data(); device_t *k001604 = screen->machine->device("k001604"); bitmap_fill(bitmap, cliprect, screen->machine->pens[0]); @@ -197,8 +213,8 @@ static VIDEO_UPDATE( jetwave ) k001604_draw_front_layer(k001604, bitmap, cliprect); - draw_7segment_led(bitmap, 3, 3, led_reg0); - draw_7segment_led(bitmap, 9, 3, led_reg1); + draw_7segment_led(bitmap, 3, 3, state->led_reg0); + draw_7segment_led(bitmap, 9, 3, state->led_reg1); sharc_set_flag_input(screen->machine->device("dsp"), 1, ASSERT_LINE); return 0; @@ -241,6 +257,7 @@ static VIDEO_START( zr107 ) static VIDEO_UPDATE( zr107 ) { + zr107_state *state = screen->machine->driver_data(); device_t *k056832 = screen->machine->device("k056832"); bitmap_fill(bitmap, cliprect, screen->machine->pens[0]); @@ -248,8 +265,8 @@ static VIDEO_UPDATE( zr107 ) K001005_draw(bitmap, cliprect); k056832_tilemap_draw(k056832, bitmap, cliprect, 0, 0, 0); - draw_7segment_led(bitmap, 3, 3, led_reg0); - draw_7segment_led(bitmap, 9, 3, led_reg1); + draw_7segment_led(bitmap, 3, 3, state->led_reg0); + draw_7segment_led(bitmap, 9, 3, state->led_reg1); sharc_set_flag_input(screen->machine->device("dsp"), 1, ASSERT_LINE); return 0; @@ -280,14 +297,15 @@ static READ8_HANDLER( sysreg_r ) static WRITE8_HANDLER( sysreg_w ) { + zr107_state *state = space->machine->driver_data(); switch (offset) { case 0: /* LED Register 0 */ - led_reg0 = data; + state->led_reg0 = data; break; case 1: /* LED Register 1 */ - led_reg1 = data; + state->led_reg1 = data; break; case 2: /* Parallel data register */ @@ -341,10 +359,9 @@ static WRITE8_HANDLER( sysreg_w ) } } -static int ccu_vcth = 0; -static int ccu_vctl = 0; static READ32_HANDLER( ccu_r ) { + zr107_state *state = space->machine->driver_data(); UINT32 r = 0; switch (offset) { @@ -353,14 +370,14 @@ static READ32_HANDLER( ccu_r ) // Midnight Run polls the vertical counter in vblank if (ACCESSING_BITS_24_31) { - ccu_vcth ^= 0xff; - r |= ccu_vcth << 24; + state->ccu_vcth ^= 0xff; + r |= state->ccu_vcth << 24; } if (ACCESSING_BITS_8_15) { - ccu_vctl++; - ccu_vctl &= 0x1ff; - r |= (ccu_vctl >> 2) << 8; + state->ccu_vctl++; + state->ccu_vctl &= 0x1ff; + r |= (state->ccu_vctl >> 2) << 8; } } } @@ -375,18 +392,18 @@ static WRITE32_HANDLER( ccu_w ) /******************************************************************/ -static UINT32 *workram; static MACHINE_START( zr107 ) { + zr107_state *state = machine->driver_data(); /* set conservative DRC options */ ppcdrc_set_options(machine->device("maincpu"), PPCDRC_COMPATIBLE_OPTIONS); /* configure fast RAM regions for DRC */ - ppcdrc_add_fastram(machine->device("maincpu"), 0x00000000, 0x000fffff, FALSE, workram); + ppcdrc_add_fastram(machine->device("maincpu"), 0x00000000, 0x000fffff, FALSE, state->workram); } static ADDRESS_MAP_START( zr107_map, ADDRESS_SPACE_PROGRAM, 32 ) - AM_RANGE(0x00000000, 0x000fffff) AM_RAM AM_BASE(&workram) /* Work RAM */ + AM_RANGE(0x00000000, 0x000fffff) AM_RAM AM_BASE_MEMBER(zr107_state, workram) /* Work RAM */ AM_RANGE(0x74000000, 0x74003fff) AM_DEVREADWRITE("k056832", k056832_ram_long_r, k056832_ram_long_w) AM_RANGE(0x74020000, 0x7402003f) AM_DEVREADWRITE("k056832", k056832_long_r, k056832_long_w) AM_RANGE(0x74060000, 0x7406003f) AM_READWRITE(ccu_r, ccu_w) @@ -474,16 +491,17 @@ static const k054539_interface k054539_config = /*****************************************************************************/ -static UINT32 *sharc_dataram; static READ32_HANDLER( dsp_dataram_r ) { - return sharc_dataram[offset] & 0xffff; + zr107_state *state = space->machine->driver_data(); + return state->sharc_dataram[offset] & 0xffff; } static WRITE32_HANDLER( dsp_dataram_w ) { - sharc_dataram[offset] = data; + zr107_state *state = space->machine->driver_data(); + state->sharc_dataram[offset] = data; } static ADDRESS_MAP_START( sharc_map, ADDRESS_SPACE_DATA, 32 ) @@ -717,7 +735,7 @@ static MACHINE_RESET( zr107 ) cputag_set_input_line(machine, "dsp", INPUT_LINE_RESET, ASSERT_LINE); } -static MACHINE_CONFIG_START( zr107, driver_device ) +static MACHINE_CONFIG_START( zr107, zr107_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu", PPC403GA, 64000000/2) /* PowerPC 403GA 32MHz */ @@ -778,7 +796,7 @@ static const k001604_interface jetwave_k001604_intf = 0 /* slrasslt hack */ }; -static MACHINE_CONFIG_START( jetwave, driver_device ) +static MACHINE_CONFIG_START( jetwave, zr107_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu", PPC403GA, 64000000/2) /* PowerPC 403GA 32MHz */ @@ -835,9 +853,10 @@ MACHINE_CONFIG_END static void init_zr107(running_machine *machine) { - sharc_dataram = auto_alloc_array(machine, UINT32, 0x100000/4); - led_reg0 = led_reg1 = 0x7f; - ccu_vcth = ccu_vctl = 0; + zr107_state *state = machine->driver_data(); + state->sharc_dataram = auto_alloc_array(machine, UINT32, 0x100000/4); + state->led_reg0 = state->led_reg1 = 0x7f; + state->ccu_vcth = state->ccu_vctl = 0; K001005_preprocess_texture_data(machine->region("gfx1")->base(), machine->region("gfx1")->bytes(), 0); } diff --git a/src/mame/includes/88games.h b/src/mame/includes/88games.h index 30625354121..d5193904698 100644 --- a/src/mame/includes/88games.h +++ b/src/mame/includes/88games.h @@ -15,6 +15,7 @@ public: UINT8 * banked_rom; // UINT8 * paletteram_1000; // this currently uses generic palette handling // UINT8 * nvram; // this currently uses generic nvram handling + UINT8 *paletteram_1000; /* video-related */ int k88games_priority; diff --git a/src/mame/includes/beezer.h b/src/mame/includes/beezer.h index 42adfedcb41..6eb7669c97f 100644 --- a/src/mame/includes/beezer.h +++ b/src/mame/includes/beezer.h @@ -1,3 +1,5 @@ +#include "machine/6522via.h" + class beezer_state : public driver_device { public: @@ -5,13 +7,16 @@ public: : driver_device(machine, config) { } UINT8 *videoram; + int pbus; + int banklatch; + int scanline; }; /*----------- defined in machine/beezer.c -----------*/ -//extern const via6522_interface b_via_0_interface; -//extern const via6522_interface b_via_1_interface; +extern const via6522_interface b_via_0_interface; +extern const via6522_interface b_via_1_interface; DRIVER_INIT( beezer ); WRITE8_HANDLER( beezer_bankswitch_w ); diff --git a/src/mame/includes/djmain.h b/src/mame/includes/djmain.h index c58c7e5192f..444b2d1bc2c 100644 --- a/src/mame/includes/djmain.h +++ b/src/mame/includes/djmain.h @@ -1,6 +1,24 @@ -/*----------- defined in video/djmain.c -----------*/ +class djmain_state : public driver_device +{ +public: + djmain_state(running_machine &machine, const driver_device_config_base &config) + : driver_device(machine, config) { } -extern UINT32 *djmain_obj_ram; + int sndram_bank; + UINT8 *sndram; + int turntable_select; + UINT8 turntable_last_pos[2]; + UINT16 turntable_pos[2]; + UINT8 pending_vb_int; + UINT16 v_ctrl; + UINT32 obj_regs[0xa0/4]; + const UINT8 *ide_user_password; + const UINT8 *ide_master_password; + UINT32 *obj_ram; +}; + + +/*----------- defined in video/djmain.c -----------*/ VIDEO_UPDATE( djmain ); VIDEO_START( djmain ); diff --git a/src/mame/includes/fastfred.h b/src/mame/includes/fastfred.h index 91e63080516..82083a9b5b3 100644 --- a/src/mame/includes/fastfred.h +++ b/src/mame/includes/fastfred.h @@ -5,16 +5,32 @@ ***************************************************************************/ +class fastfred_state : public driver_device +{ +public: + fastfred_state(running_machine &machine, const driver_device_config_base &config) + : driver_device(machine, config) { } + + UINT8 imago_sprites[0x800*3]; + UINT16 imago_sprites_address; + UINT8 imago_sprites_bank; + int hardware_type; + UINT8 *videoram; + UINT8 *spriteram; + size_t spriteram_size; + UINT8 *attributesram; + UINT8 *background_color; + UINT8 *imago_fg_videoram; + UINT16 charbank; + UINT8 colorbank; + tilemap_t *bg_tilemap; + tilemap_t *fg_tilemap; + tilemap_t *web_tilemap; +}; + + /*----------- defined in video/fastfred.c -----------*/ -extern int fastfred_hardware_type; - -extern UINT8 *fastfred_videoram; -extern UINT8 *fastfred_spriteram; -extern size_t fastfred_spriteram_size; -extern UINT8 *fastfred_attributesram; -extern UINT8 *fastfred_background_color; - PALETTE_INIT( fastfred ); VIDEO_START( fastfred ); WRITE8_HANDLER( fastfred_videoram_w ); @@ -27,7 +43,6 @@ WRITE8_HANDLER( fastfred_flip_screen_x_w ); WRITE8_HANDLER( fastfred_flip_screen_y_w ); VIDEO_UPDATE( fastfred ); -extern UINT8 *imago_fg_videoram; VIDEO_START( imago ); VIDEO_UPDATE( imago ); WRITE8_HANDLER( imago_fg_videoram_w ); diff --git a/src/mame/includes/hexion.h b/src/mame/includes/hexion.h index 6281bc9b491..215a701225d 100644 --- a/src/mame/includes/hexion.h +++ b/src/mame/includes/hexion.h @@ -1,3 +1,19 @@ +class hexion_state : public driver_device +{ +public: + hexion_state(running_machine &machine, const driver_device_config_base &config) + : driver_device(machine, config) { } + + UINT8 *vram[2]; + UINT8 *unkram; + int bankctrl; + int rambank; + int pmcbank; + int gfxrom_select; + tilemap_t *bg_tilemap[2]; +}; + + /*----------- defined in video/hexion.c -----------*/ VIDEO_START( hexion ); diff --git a/src/mame/includes/model1.h b/src/mame/includes/model1.h index b172c5ae44b..17e8f0baabb 100644 --- a/src/mame/includes/model1.h +++ b/src/mame/includes/model1.h @@ -1,7 +1,89 @@ +typedef void (*tgp_func)(running_machine *machine); + +enum {FIFO_SIZE = 256}; +enum {MAT_STACK_SIZE = 32}; + +class model1_state : public driver_device +{ +public: + model1_state(running_machine &machine, const driver_device_config_base &config) + : driver_device(machine, config) { } + + struct view *view; + struct point *pointdb, *pointpt; + struct quad_m1 *quaddb, *quadpt; + struct quad_m1 **quadind; + int sound_irq; + int to_68k[8]; + int fifo_wptr; + int fifo_rptr; + int last_irq; + UINT16 *mr; + UINT16 *mr2; + int dump; + UINT16 *display_list0; + UINT16 *display_list1; + UINT16 *color_xlat; + offs_t pushpc; + int fifoin_rpos; + int fifoin_wpos; + UINT32 fifoin_data[FIFO_SIZE]; + int swa; + int fifoin_cbcount; + tgp_func fifoin_cb; + INT32 fifoout_rpos; + INT32 fifoout_wpos; + UINT32 fifoout_data[FIFO_SIZE]; + UINT32 list_length; + float cmat[12]; + float mat_stack[MAT_STACK_SIZE][12]; + float mat_vector[21][12]; + INT32 mat_stack_pos; + float acc; + float tgp_vf_xmin; + float tgp_vf_xmax; + float tgp_vf_zmin; + float tgp_vf_zmax; + float tgp_vf_ygnd; + float tgp_vf_yflr; + float tgp_vf_yjmp; + float tgp_vr_circx; + float tgp_vr_circy; + float tgp_vr_circrad; + float tgp_vr_cbox[12]; + int tgp_vr_select; + UINT16 ram_adr; + UINT16 ram_latch[2]; + UINT16 ram_scanadr; + UINT32 *ram_data; + float tgp_vr_base[4]; + int puuu; + int ccount; + UINT32 copro_r; + UINT32 copro_w; + int copro_fifoout_rpos; + int copro_fifoout_wpos; + UINT32 copro_fifoout_data[FIFO_SIZE]; + int copro_fifoout_num; + int copro_fifoin_rpos; + int copro_fifoin_wpos; + UINT32 copro_fifoin_data[FIFO_SIZE]; + int copro_fifoin_num; + UINT32 vr_r; + UINT32 vr_w; + UINT16 listctl[2]; + UINT16 *glist; + int render_done; + UINT16 *tgp_ram; + UINT16 *paletteram16; + UINT32 *poly_rom; + UINT32 *poly_ram; +}; + + /*----------- defined in machine/model1.c -----------*/ extern const mb86233_cpu_core model1_vr_tgp_config; -extern int model1_dump; READ16_HANDLER( model1_tgp_copro_r ); WRITE16_HANDLER( model1_tgp_copro_w ); @@ -27,9 +109,6 @@ void model1_tgp_reset(running_machine *machine, int swa); /*----------- defined in video/model1.c -----------*/ -extern UINT16 *model1_display_list0, *model1_display_list1; -extern UINT16 *model1_color_xlat; - VIDEO_START(model1); VIDEO_UPDATE(model1); VIDEO_EOF(model1); diff --git a/src/mame/includes/model2.h b/src/mame/includes/model2.h index f11d753aa84..09f5cef4ef2 100644 --- a/src/mame/includes/model2.h +++ b/src/mame/includes/model2.h @@ -1,13 +1,71 @@ -/*----------- defined in drivers/model2.c -----------*/ +#include "video/poly.h" -extern UINT32 geo_read_start_address; -extern UINT32 geo_write_start_address; -extern UINT32 *model2_bufferram; -extern UINT32 *model2_colorxlat; -extern UINT32 *model2_textureram0; -extern UINT32 *model2_textureram1; -extern UINT32 *model2_lumaram; -extern UINT32 *model2_paletteram32; + +typedef struct _raster_state raster_state; +typedef struct _geo_state geo_state; + + +class model2_state : public driver_device +{ +public: + model2_state(running_machine &machine, const driver_device_config_base &config) + : driver_device(machine, config) { } + + UINT32 *workram; + UINT32 intreq; + UINT32 intena; + UINT32 coproctl; + UINT32 coprocnt; + UINT32 geoctl; + UINT32 geocnt; + UINT16 *soundram; + UINT32 timervals[4]; + UINT32 timerorig[4]; + int timerrun[4]; + timer_device *timers[4]; + int ctrlmode; + int analog_channel; + UINT32 *tgp_program; + int dsp_type; + int copro_fifoin_rpos; + int copro_fifoin_wpos; + UINT32 *copro_fifoin_data; + int copro_fifoin_num; + int copro_fifoout_rpos; + int copro_fifoout_wpos; + UINT32 *copro_fifoout_data; + int copro_fifoout_num; + UINT16 cmd_data; + UINT8 driveio_comm_data; + int iop_write_num; + UINT32 iop_data; + int geo_iop_write_num; + UINT32 geo_iop_data; + int to_68k; + int protstate; + int protpos; + UINT8 protram[256]; + int prot_a; + int maxxstate; + UINT32 netram[0x8000/4]; + int zflagi; + int zflag; + int sysres; + int scsp_last_line; + int jnet_time_out; + UINT32 geo_read_start_address; + UINT32 geo_write_start_address; + UINT32 *bufferram; + UINT32 *colorxlat; + UINT32 *textureram0; + UINT32 *textureram1; + UINT32 *lumaram; + UINT32 *paletteram32; + poly_manager *poly; + raster_state *raster; + geo_state *geo; + bitmap_t *sys24_bitmap; +}; /*----------- defined in video/model2.c -----------*/ @@ -15,4 +73,4 @@ extern UINT32 *model2_paletteram32; VIDEO_START(model2); VIDEO_UPDATE(model2); -void model2_3d_set_zclip( UINT8 clip ); +void model2_3d_set_zclip( running_machine *machine, UINT8 clip ); diff --git a/src/mame/includes/model3.h b/src/mame/includes/model3.h index 484fcc12d7a..e75a6b0ba82 100644 --- a/src/mame/includes/model3.h +++ b/src/mame/includes/model3.h @@ -1,25 +1,123 @@ -/*----------- defined in drivers/model3.c -----------*/ +#include "video/poly.h" -extern UINT32 *model3_vrom; -extern int model3_step; +typedef float MATRIX[4][4]; +typedef float VECTOR[4]; +typedef float VECTOR3[3]; + +typedef struct { + float x,y,z,d; +} PLANE; + +typedef struct _cached_texture cached_texture; + +class model3_state : public driver_device +{ +public: + model3_state(running_machine &machine, const driver_device_config_base &config) + : driver_device(machine, config) { } + + UINT8 irq_enable; + UINT8 irq_state; + UINT8 scsi_irq_state; + UINT64 *work_ram; + int crom_bank; + int controls_bank; + UINT32 real3d_device_id; + UINT16 *soundram; + UINT32 mpc105_regs[0x40]; + UINT32 mpc105_addr; + int pci_bus; + int pci_device; + int pci_function; + int pci_reg; + UINT32 mpc106_regs[0x40]; + UINT32 mpc106_addr; + UINT32 dma_data; + UINT32 dma_status; + UINT32 dma_source; + UINT32 dma_dest; + UINT32 dma_endian; + UINT32 dma_irq; + UINT64 controls_2; + UINT64 controls_3; + UINT8 serial_fifo1; + UINT8 serial_fifo2; + int lightgun_reg_sel; + int adc_channel; + UINT64 real3d_status; + UINT64 *network_ram; + int prot_data_ptr; + int scsp_last_line; + int vblank; + UINT32 *vrom; + int step; + UINT64 *paletteram64; + int m3_step; + INT32 tap_state; + UINT64 ir; + UINT8 id_data[32]; + INT32 id_size; + int tdo; + UINT8 layer_enable; + UINT32 layer_modulate_r; + UINT32 layer_modulate_g; + UINT32 layer_modulate_b; + UINT32 layer_modulate1; + UINT32 layer_modulate2; + UINT64 layer_scroll[2]; + UINT64 *m3_char_ram; + UINT64 *m3_tile_ram; + UINT32 *texture_fifo; + int texture_fifo_pos; + UINT16 *texture_ram[2]; + UINT32 *display_list_ram; + UINT32 *culling_ram; + UINT32 *polygon_ram; + UINT16 *pal_lookup; + int real3d_display_list; + bitmap_t *bitmap3d; + bitmap_t *zbuffer; + rectangle clip3d; + rectangle *screen_clip; + VECTOR3 parallel_light; + float parallel_light_intensity; + float ambient_light_intensity; + poly_manager *poly; + int list_depth; + int tick; + int debug_layer_disable; + UINT64 vid_reg0; + int matrix_stack_ptr; + MATRIX *matrix_stack; + MATRIX coordinate_system; + float viewport_focal_length; + int viewport_region_x; + int viewport_region_y; + int viewport_region_width; + int viewport_region_height; + PLANE clip_plane[5]; + UINT32 matrix_base_address; + cached_texture *texcache[2][1024/32][2048/32]; +}; + + +/*----------- defined in drivers/model3.c -----------*/ void model3_set_irq_line(running_machine *machine, UINT8 bit, int state); /*----------- defined in machine/model3.c -----------*/ -extern void model3_machine_init(int step); -extern int model3_tap_read(void); -extern void model3_tap_write(int tck, int tms, int tdi, int trst); -extern void model3_tap_reset(void); +extern void model3_machine_init(running_machine *machine, int step); +extern int model3_tap_read(running_machine *machine); +extern void model3_tap_write(running_machine *machine, int tck, int tms, int tdi, int trst); +extern void model3_tap_reset(running_machine *machine); extern READ32_HANDLER(rtc72421_r); extern WRITE32_HANDLER(rtc72421_w); /*----------- defined in video/model3.c -----------*/ -extern UINT64 *paletteram64; - READ64_HANDLER(model3_char_r); WRITE64_HANDLER(model3_char_w); READ64_HANDLER(model3_tile_r); diff --git a/src/mame/includes/mystwarr.h b/src/mame/includes/mystwarr.h index 675a1344ab1..364fd131f9c 100644 --- a/src/mame/includes/mystwarr.h +++ b/src/mame/includes/mystwarr.h @@ -1,3 +1,26 @@ +class mystwarr_state : public driver_device +{ +public: + mystwarr_state(running_machine &machine, const driver_device_config_base &config) + : driver_device(machine, config) { } + + UINT16 *gx_workram; + UINT8 mw_irq_control; + int cur_sound_region; + int layer_colorbase[6]; + int oinprion; + int cbparam; + int sprite_colorbase; + int sub1_colorbase; + int last_psac_colorbase; + int gametype; + int roz_enable; + int roz_rombank; + tilemap_t *ult_936_tilemap; + UINT16 clip; +}; + + /*----------- defined in video/mystwarr.c -----------*/ VIDEO_START( gaiapols ); diff --git a/src/mame/includes/qdrmfgp.h b/src/mame/includes/qdrmfgp.h index e0c7a3b4492..30dc1fcee96 100644 --- a/src/mame/includes/qdrmfgp.h +++ b/src/mame/includes/qdrmfgp.h @@ -6,13 +6,13 @@ public: m_nvram(*this, "nvram") { } required_shared_ptr m_nvram; + UINT8 *sndram; + UINT16 *workram; + UINT16 control; + INT32 gp2_irq_control; + INT32 pal; }; -/*----------- defined in drivers/qdrmfgp.c -----------*/ - -int qdrmfgp_get_palette(void); - - /*----------- defined in video/qdrmfgp.c -----------*/ VIDEO_START( qdrmfgp ); diff --git a/src/mame/includes/segag80v.h b/src/mame/includes/segag80v.h index 4c4d21cd4a4..848eecb19a2 100644 --- a/src/mame/includes/segag80v.h +++ b/src/mame/includes/segag80v.h @@ -5,6 +5,26 @@ *************************************************************************/ +class segag80v_state : public driver_device +{ +public: + segag80v_state(running_machine &machine, const driver_device_config_base &config) + : driver_device(machine, config) { } + + UINT8 *mainram; + UINT8 has_usb; + UINT8 mult_data[2]; + UINT16 mult_result; + UINT8 spinner_select; + UINT8 spinner_sign; + UINT8 spinner_count; + UINT8 *vectorram; + size_t vectorram_size; + int min_x; + int min_y; +}; + + /*----------- defined in audio/segag80v.c -----------*/ WRITE8_HANDLER( elim1_sh_w ); @@ -17,8 +37,5 @@ WRITE8_HANDLER( zektor2_sh_w ); /*----------- defined in video/segag80v.c -----------*/ -extern UINT8 *segag80v_vectorram; -extern size_t segag80v_vectorram_size; - VIDEO_START( segag80v ); VIDEO_UPDATE( segag80v ); diff --git a/src/mame/includes/segas32.h b/src/mame/includes/segas32.h index 6915170e66b..1056633b3e4 100644 --- a/src/mame/includes/segas32.h +++ b/src/mame/includes/segas32.h @@ -5,11 +5,57 @@ ***************************************************************************/ -/*----------- defined in drivers/segas32.c -----------*/ +typedef void (*sys32_output_callback)(int which, UINT16 data); +struct layer_info +{ + bitmap_t * bitmap; + UINT8 * transparent; +}; -extern UINT8 *ga2_dpram; -extern UINT16 *system32_workram; -extern UINT16 *system32_protram; + +class segas32_state : public driver_device +{ +public: + segas32_state(running_machine &machine, const driver_device_config_base &config) + : driver_device(machine, config) { } + + UINT8 *z80_shared_ram; + UINT8 v60_irq_control[0x10]; + timer_device *v60_irq_timer[2]; + UINT8 sound_irq_control[4]; + UINT8 sound_irq_input; + UINT8 sound_dummy_value; + UINT16 sound_bank; + UINT8 misc_io_data[2][0x10]; + read16_space_func custom_io_r[2]; + write16_space_func custom_io_w[2]; + UINT8 analog_bank; + UINT8 analog_value[4]; + UINT8 sonic_last[6]; + sys32_output_callback sw1_output; + sys32_output_callback sw2_output; + sys32_output_callback sw3_output; + UINT16* dual_pcb_comms; + UINT8 *ga2_dpram; + UINT16 *system32_workram; + UINT16 *system32_protram; + UINT16 *system32_videoram; + UINT16 *system32_spriteram; + UINT16 *system32_paletteram[2]; + UINT16 system32_displayenable[2]; + UINT16 system32_tilebank_external; + UINT16 arescue_dsp_io[6]; + UINT8 is_multi32; + struct cache_entry *cache_head; + struct layer_info layer_data[11]; + UINT16 mixer_control[2][0x40]; + UINT16 *solid_0000; + UINT16 *solid_ffff; + UINT8 sprite_render_count; + UINT8 sprite_control_latched[8]; + UINT8 sprite_control[8]; + UINT32 *spriteram_32bit; +}; /*----------- defined in machine/segas32.c -----------*/ @@ -42,12 +88,6 @@ WRITE16_HANDLER( arescue_dsp_w ); /*----------- defined in video/segas32.c -----------*/ -extern UINT16 *system32_videoram; -extern UINT16 *system32_spriteram; -extern UINT16 *system32_paletteram[2]; -extern UINT16 system32_displayenable[2]; -extern UINT16 system32_tilebank_external; - VIDEO_START(system32); VIDEO_START(multi32); VIDEO_UPDATE(system32); diff --git a/src/mame/includes/suprloco.h b/src/mame/includes/suprloco.h index 4f5ed423935..474a4c91c6a 100644 --- a/src/mame/includes/suprloco.h +++ b/src/mame/includes/suprloco.h @@ -1,7 +1,17 @@ -/*----------- defined in video/suprloco.c -----------*/ +class suprloco_state : public driver_device +{ +public: + suprloco_state(running_machine &machine, const driver_device_config_base &config) + : driver_device(machine, config) { } -extern UINT8 *suprloco_videoram; -extern UINT8 *suprloco_scrollram; + UINT8 *videoram; + UINT8 *scrollram; + tilemap_t *bg_tilemap; + int control; +}; + + +/*----------- defined in video/suprloco.c -----------*/ PALETTE_INIT( suprloco ); VIDEO_START( suprloco ); diff --git a/src/mame/includes/system1.h b/src/mame/includes/system1.h index 097d4cf6a16..e6c8b45561a 100644 --- a/src/mame/includes/system1.h +++ b/src/mame/includes/system1.h @@ -5,6 +5,25 @@ public: : driver_device(machine, config) { } UINT8 *videoram; + void (*videomode_custom)(running_machine *machine, UINT8 data, UINT8 prevdata); + UINT8 mute_xor; + UINT8 *ram; + UINT8 dakkochn_mux_data; + UINT8 videomode_prev; + UINT8 mcu_control; + UINT8 *nob_mcu_status; + UINT8 *nob_mcu_latch; + UINT8 nob_maincpu_latch; + int nobb_inport23_step; + UINT8 *mix_collide; + UINT8 mix_collide_summary; + UINT8 *sprite_collide; + UINT8 sprite_collide_summary; + bitmap_t *sprite_bitmap; + UINT8 video_mode; + UINT8 videoram_bank; + tilemap_t *tilemap_page[8]; + UINT8 tilemap_pages; }; diff --git a/src/mame/includes/tp84.h b/src/mame/includes/tp84.h index 477ec07a0bb..96c9e037f0a 100644 --- a/src/mame/includes/tp84.h +++ b/src/mame/includes/tp84.h @@ -1,15 +1,26 @@ -/*----------- defined in video/tp84.c -----------*/ +class tp84_state : public driver_device +{ +public: + tp84_state(running_machine &machine, const driver_device_config_base &config) + : driver_device(machine, config) { } -extern UINT8 *tp84_bg_videoram; -extern UINT8 *tp84_bg_colorram; -extern UINT8 *tp84_fg_videoram; -extern UINT8 *tp84_fg_colorram; -extern UINT8 *tp84_spriteram; -extern UINT8 *tp84_scroll_x; -extern UINT8 *tp84_scroll_y; -extern UINT8 *tp84_palette_bank; -extern UINT8 *tp84_flipscreen_x; -extern UINT8 *tp84_flipscreen_y; + cpu_device *audiocpu; + UINT8 *bg_videoram; + UINT8 *bg_colorram; + UINT8 *fg_videoram; + UINT8 *fg_colorram; + UINT8 *spriteram; + UINT8 *scroll_x; + UINT8 *scroll_y; + UINT8 *palette_bank; + UINT8 *flipscreen_x; + UINT8 *flipscreen_y; + tilemap_t *bg_tilemap; + tilemap_t *fg_tilemap; +}; + + +/*----------- defined in video/tp84.c -----------*/ WRITE8_HANDLER( tp84_spriteram_w ); READ8_HANDLER( tp84_scanline_r ); diff --git a/src/mame/includes/twin16.h b/src/mame/includes/twin16.h index b410dc1ea6d..3e2a8ece92f 100644 --- a/src/mame/includes/twin16.h +++ b/src/mame/includes/twin16.h @@ -5,17 +5,31 @@ public: : driver_device(machine, config) { } UINT16 *videoram; + UINT16 CPUA_register; + UINT16 CPUB_register; + UINT16 sound_command; + int cuebrickj_nvram_bank; + UINT16 cuebrickj_nvram[0x400*0x20]; + UINT16 custom_video; + UINT16 *gfx_rom; + UINT16 *text_ram; + UINT16 *sprite_gfx_ram; + UINT16 *tile_gfx_ram; + UINT16 sprite_buffer[0x800]; + emu_timer *sprite_timer; + int sprite_busy; + int need_process_spriteram; + UINT16 gfx_bank; + UINT16 scrollx[3]; + UINT16 scrolly[3]; + UINT16 video_register; + tilemap_t *text_tilemap; }; /*----------- defined in drivers/twin16.c -----------*/ -extern UINT16 twin16_custom_video; -extern UINT16 *twin16_gfx_rom; -extern UINT16 *twin16_text_ram; -extern UINT16 *twin16_sprite_gfx_ram; -extern UINT16 *twin16_tile_gfx_ram; -int twin16_spriteram_process_enable( void ); +int twin16_spriteram_process_enable( running_machine *machine ); /*----------- defined in video/twin16.c -----------*/ @@ -30,4 +44,4 @@ VIDEO_START( twin16 ); VIDEO_UPDATE( twin16 ); VIDEO_EOF( twin16 ); -void twin16_spriteram_process( running_machine* ); +void twin16_spriteram_process( running_machine *machine ); diff --git a/src/mame/includes/wecleman.h b/src/mame/includes/wecleman.h index 0c410e7cbd5..716adfb65bd 100644 --- a/src/mame/includes/wecleman.h +++ b/src/mame/includes/wecleman.h @@ -1,14 +1,46 @@ -/*----------- defined in drivers/wecleman.c -----------*/ +class wecleman_state : public driver_device +{ +public: + wecleman_state(running_machine &machine, const driver_device_config_base &config) + : driver_device(machine, config) { } -extern int wecleman_selected_ip, wecleman_irqctrl; + UINT16 *blitter_regs; + int multiply_reg[2]; + UINT16 *protection_ram; + int spr_color_offs; + int prot_state; + int selected_ip; + int irqctrl; + UINT16 *videostatus; + UINT16 *pageram; + UINT16 *txtram; + UINT16 *roadram; + size_t roadram_size; + int bgpage[4]; + int fgpage[4]; + const int *gfx_bank; + tilemap_t *bg_tilemap; + tilemap_t *fg_tilemap; + tilemap_t *txt_tilemap; + int *spr_idx_list; + int *spr_pri_list; + int *t32x32pm; + int gameid; + int spr_offsx; + int spr_offsy; + int spr_count; + UINT16 *rgb_half; + int cloud_blend; + int cloud_ds; + int cloud_visible; + pen_t black_pen; + struct sprite *sprite_list; + struct sprite **spr_ptr_list; +}; /*----------- defined in video/wecleman.c -----------*/ -extern UINT16 *wecleman_videostatus; -extern UINT16 *wecleman_pageram, *wecleman_txtram, *wecleman_roadram; -extern size_t wecleman_roadram_size; - WRITE16_HANDLER( hotchase_paletteram16_SBGRBBBBGGGGRRRR_word_w ); WRITE16_HANDLER( wecleman_paletteram16_SSSSBBBBGGGGRRRR_word_w ); WRITE16_HANDLER( wecleman_videostatus_w ); diff --git a/src/mame/machine/beezer.c b/src/mame/machine/beezer.c index 90f1a599218..2a8ae397f08 100644 --- a/src/mame/machine/beezer.c +++ b/src/mame/machine/beezer.c @@ -3,11 +3,6 @@ #include "machine/6522via.h" #include "includes/beezer.h" -extern const via6522_interface b_via_0_interface; -extern const via6522_interface b_via_1_interface; - -static int pbus; -static int banklatch; static READ8_DEVICE_HANDLER( b_via_0_pa_r ); static READ8_DEVICE_HANDLER( b_via_0_pb_r ); @@ -93,16 +88,19 @@ static READ_LINE_DEVICE_HANDLER( b_via_0_ca2_r ) static READ8_DEVICE_HANDLER( b_via_0_pa_r ) { - return (banklatch&0x38)<<2; // return X,Y,Z bits TODO: the Z bit connects somewhere else... where? + beezer_state *state = device->machine->driver_data(); + return (state->banklatch&0x38)<<2; // return X,Y,Z bits TODO: the Z bit connects somewhere else... where? } static READ8_DEVICE_HANDLER( b_via_0_pb_r ) { - return pbus; + beezer_state *state = device->machine->driver_data(); + return state->pbus; } static WRITE8_DEVICE_HANDLER( b_via_0_pa_w ) { + beezer_state *state = device->machine->driver_data(); if ((data & 0x08) == 0) cputag_set_input_line(device->machine, "audiocpu", INPUT_LINE_RESET, ASSERT_LINE); else @@ -113,16 +111,16 @@ static WRITE8_DEVICE_HANDLER( b_via_0_pa_w ) switch (data & 0x03) { case 0: - pbus = input_port_read(device->machine, "IN0"); + state->pbus = input_port_read(device->machine, "IN0"); break; case 1: - pbus = input_port_read(device->machine, "IN1") | (input_port_read(device->machine, "IN2") << 4); + state->pbus = input_port_read(device->machine, "IN1") | (input_port_read(device->machine, "IN2") << 4); break; case 2: - pbus = input_port_read(device->machine, "DSWB"); + state->pbus = input_port_read(device->machine, "DSWB"); break; case 3: - pbus = input_port_read(device->machine, "DSWA"); // Technically DSWA isn't populated on the board and is pulled to 0xFF with resistor pack, but there IS a DSWA port in the driver so we may as well use it. + state->pbus = input_port_read(device->machine, "DSWA"); // Technically DSWA isn't populated on the board and is pulled to 0xFF with resistor pack, but there IS a DSWA port in the driver so we may as well use it. break; } } @@ -130,12 +128,14 @@ static WRITE8_DEVICE_HANDLER( b_via_0_pa_w ) static WRITE8_DEVICE_HANDLER( b_via_0_pb_w ) { - pbus = data; + beezer_state *state = device->machine->driver_data(); + state->pbus = data; } static READ8_DEVICE_HANDLER( b_via_1_pa_r ) { - return pbus; + beezer_state *state = device->machine->driver_data(); + return state->pbus; } static READ8_DEVICE_HANDLER( b_via_1_pb_r ) @@ -145,7 +145,8 @@ static READ8_DEVICE_HANDLER( b_via_1_pb_r ) static WRITE8_DEVICE_HANDLER( b_via_1_pa_w ) { - pbus = data; + beezer_state *state = device->machine->driver_data(); + state->pbus = data; } static WRITE8_DEVICE_HANDLER( b_via_1_pb_w ) @@ -157,13 +158,15 @@ static WRITE8_DEVICE_HANDLER( b_via_1_pb_w ) DRIVER_INIT( beezer ) { - pbus = 0; - banklatch = 0; + beezer_state *state = machine->driver_data(); + state->pbus = 0; + state->banklatch = 0; } WRITE8_HANDLER( beezer_bankswitch_w ) { - banklatch = data&0x3f; // latched 'x,y,z' plus bank bits in ls174 @ 4H + beezer_state *state = space->machine->driver_data(); + state->banklatch = data&0x3f; // latched 'x,y,z' plus bank bits in ls174 @ 4H if ((data & 0x07) == 0) { via6522_device *via_0 = space->machine->device("via6522_0"); diff --git a/src/mame/machine/model1.c b/src/mame/machine/model1.c index 36b52057c13..781ef1c8ff9 100644 --- a/src/mame/machine/model1.c +++ b/src/mame/machine/model1.c @@ -9,110 +9,80 @@ #include "includes/model1.h" #define TGP_FUNCTION(name) void name(running_machine *machine) -typedef void (*tgp_func)(running_machine *machine); -enum {FIFO_SIZE = 256}; -enum {MAT_STACK_SIZE = 32}; - -int model1_dump; - -static offs_t pushpc; - -static int fifoin_rpos, fifoin_wpos; -static UINT32 fifoin_data[FIFO_SIZE]; -static int model1_swa; - -static int fifoin_cbcount; -static tgp_func fifoin_cb; - -static INT32 fifoout_rpos, fifoout_wpos; -static UINT32 fifoout_data[FIFO_SIZE]; - -static UINT32 list_length; - -static float cmat[12], mat_stack[MAT_STACK_SIZE][12], mat_vector[21][12]; -static INT32 mat_stack_pos; -static float acc; - -static float tgp_vf_xmin, tgp_vf_xmax, tgp_vf_zmin, tgp_vf_zmax, tgp_vf_ygnd, tgp_vf_yflr, tgp_vf_yjmp; -static float tgp_vr_circx, tgp_vr_circy, tgp_vr_circrad, tgp_vr_cbox[12]; -static int tgp_vr_select; -static UINT16 ram_adr, ram_latch[2], ram_scanadr; -static UINT32 *ram_data; -static float tgp_vr_base[4]; - static UINT32 fifoout_pop(address_space *space) { + model1_state *state = space->machine->driver_data(); UINT32 v; - if(fifoout_wpos == fifoout_rpos) { + if(state->fifoout_wpos == state->fifoout_rpos) { fatalerror("TGP FIFOOUT underflow (%x)", cpu_get_pc(space->cpu)); } - v = fifoout_data[fifoout_rpos++]; - if(fifoout_rpos == FIFO_SIZE) - fifoout_rpos = 0; + v = state->fifoout_data[state->fifoout_rpos++]; + if(state->fifoout_rpos == FIFO_SIZE) + state->fifoout_rpos = 0; return v; } -static int puuu = 0; -static void fifoout_push(UINT32 data) +static void fifoout_push(model1_state *state, UINT32 data) { - if(!puuu) + if(!state->puuu) logerror("TGP: Push %d\n", data); else - puuu = 0; - fifoout_data[fifoout_wpos++] = data; - if(fifoout_wpos == FIFO_SIZE) - fifoout_wpos = 0; - if(fifoout_wpos == fifoout_rpos) + state->puuu = 0; + state->fifoout_data[state->fifoout_wpos++] = data; + if(state->fifoout_wpos == FIFO_SIZE) + state->fifoout_wpos = 0; + if(state->fifoout_wpos == state->fifoout_rpos) logerror("TGP FIFOOUT overflow\n"); } -static void fifoout_push_f(float data) +static void fifoout_push_f(model1_state *state, float data) { - puuu = 1; + state->puuu = 1; logerror("TGP: Push %f\n", data); - fifoout_push(f2u(data)); + fifoout_push(state, f2u(data)); } -static UINT32 fifoin_pop(void) +static UINT32 fifoin_pop(model1_state *state) { UINT32 v; - if(fifoin_wpos == fifoin_rpos) + if(state->fifoin_wpos == state->fifoin_rpos) logerror("TGP FIFOIN underflow\n"); - v = fifoin_data[fifoin_rpos++]; - if(fifoin_rpos == FIFO_SIZE) - fifoin_rpos = 0; + v = state->fifoin_data[state->fifoin_rpos++]; + if(state->fifoin_rpos == FIFO_SIZE) + state->fifoin_rpos = 0; return v; } static void fifoin_push(address_space *space, UINT32 data) { + model1_state *state = space->machine->driver_data(); // logerror("TGP FIFOIN write %08x (%x)\n", data, cpu_get_pc(space->cpu)); - fifoin_data[fifoin_wpos++] = data; - if(fifoin_wpos == FIFO_SIZE) - fifoin_wpos = 0; - if(fifoin_wpos == fifoin_rpos) + state->fifoin_data[state->fifoin_wpos++] = data; + if(state->fifoin_wpos == FIFO_SIZE) + state->fifoin_wpos = 0; + if(state->fifoin_wpos == state->fifoin_rpos) logerror("TGP FIFOIN overflow\n"); - fifoin_cbcount--; - if(!fifoin_cbcount) - fifoin_cb(space->machine); + state->fifoin_cbcount--; + if(!state->fifoin_cbcount) + state->fifoin_cb(space->machine); } -static float fifoin_pop_f(void) +static float fifoin_pop_f(model1_state *state) { - return u2f(fifoin_pop()); + return u2f(fifoin_pop(state)); } static TGP_FUNCTION( function_get_vf ); static TGP_FUNCTION( function_get_swa ); -static void next_fn(void) +static void next_fn(model1_state *state) { - fifoin_cbcount = 1; - fifoin_cb = model1_swa ? function_get_swa : function_get_vf; + state->fifoin_cbcount = 1; + state->fifoin_cb = state->swa ? function_get_swa : function_get_vf; } static float tcos(INT16 a) @@ -139,160 +109,171 @@ static float tsin(INT16 a) return sin(a*(2*M_PI/65536.0)); } -static UINT16 ram_get_i(void) +static UINT16 ram_get_i(model1_state *state) { - return ram_data[ram_scanadr++]; + return state->ram_data[state->ram_scanadr++]; } -static float ram_get_f(void) +static float ram_get_f(model1_state *state) { - return u2f(ram_data[ram_scanadr++]); + return u2f(state->ram_data[state->ram_scanadr++]); } static TGP_FUNCTION( fadd ) { - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); float r = a+b; - logerror("TGP fadd %f+%f=%f (%x)\n", a, b, r, pushpc); - fifoout_push_f(r); - next_fn(); + logerror("TGP fadd %f+%f=%f (%x)\n", a, b, r, state->pushpc); + fifoout_push_f(state, r); + next_fn(state); } static TGP_FUNCTION( fsub ) { - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); float r = a-b; - model1_dump = 1; - logerror("TGP fsub %f-%f=%f (%x)\n", a, b, r, pushpc); - fifoout_push_f(r); - next_fn(); + state->dump = 1; + logerror("TGP fsub %f-%f=%f (%x)\n", a, b, r, state->pushpc); + fifoout_push_f(state, r); + next_fn(state); } static TGP_FUNCTION( fmul ) { - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); float r = a*b; - logerror("TGP fmul %f*%f=%f (%x)\n", a, b, r, pushpc); - fifoout_push_f(r); - next_fn(); + logerror("TGP fmul %f*%f=%f (%x)\n", a, b, r, state->pushpc); + fifoout_push_f(state, r); + next_fn(state); } static TGP_FUNCTION( fdiv ) { - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); // float r = !b ? 1e39 : a/b; float r = !b ? 0 : a * (1/b); - logerror("TGP fdiv %f/%f=%f (%x)\n", a, b, r, pushpc); - fifoout_push_f(r); - next_fn(); + logerror("TGP fdiv %f/%f=%f (%x)\n", a, b, r, state->pushpc); + fifoout_push_f(state, r); + next_fn(state); } static TGP_FUNCTION( matrix_push ) { - if(mat_stack_pos != MAT_STACK_SIZE) { - memcpy(mat_stack[mat_stack_pos], cmat, sizeof(cmat)); - mat_stack_pos++; + model1_state *state = machine->driver_data(); + if(state->mat_stack_pos != MAT_STACK_SIZE) { + memcpy(state->mat_stack[state->mat_stack_pos], state->cmat, sizeof(state->cmat)); + state->mat_stack_pos++; } - logerror("TGP matrix_push (depth=%d, pc=%x)\n", mat_stack_pos, pushpc); - next_fn(); + logerror("TGP matrix_push (depth=%d, pc=%x)\n", state->mat_stack_pos, state->pushpc); + next_fn(state); } static TGP_FUNCTION( matrix_pop ) { - if(mat_stack_pos) { - mat_stack_pos--; - memcpy(cmat, mat_stack[mat_stack_pos], sizeof(cmat)); + model1_state *state = machine->driver_data(); + if(state->mat_stack_pos) { + state->mat_stack_pos--; + memcpy(state->cmat, state->mat_stack[state->mat_stack_pos], sizeof(state->cmat)); } - logerror("TGP matrix_pop (depth=%d, pc=%x)\n", mat_stack_pos, pushpc); - next_fn(); + logerror("TGP matrix_pop (depth=%d, pc=%x)\n", state->mat_stack_pos, state->pushpc); + next_fn(state); } static TGP_FUNCTION( matrix_write ) { + model1_state *state = machine->driver_data(); int i; for(i=0; i<12; i++) - cmat[i] = fifoin_pop_f(); + state->cmat[i] = fifoin_pop_f(state); logerror("TGP matrix_write %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f) (%x)\n", - cmat[0], cmat[1], cmat[2], cmat[3], cmat[4], cmat[5], cmat[6], cmat[7], cmat[8], cmat[9], cmat[10], cmat[11], - pushpc); - next_fn(); + state->cmat[0], state->cmat[1], state->cmat[2], state->cmat[3], state->cmat[4], state->cmat[5], state->cmat[6], state->cmat[7], state->cmat[8], state->cmat[9], state->cmat[10], state->cmat[11], + state->pushpc); + next_fn(state); } static TGP_FUNCTION( clear_stack ) { - logerror("TGP clear_stack (%x)\n", pushpc); - mat_stack_pos = 0; - next_fn(); + model1_state *state = machine->driver_data(); + logerror("TGP clear_stack (%x)\n", state->pushpc); + state->mat_stack_pos = 0; + next_fn(state); } static TGP_FUNCTION( matrix_mul ) { + model1_state *state = machine->driver_data(); float m[12]; - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - float c = fifoin_pop_f(); - float d = fifoin_pop_f(); - float e = fifoin_pop_f(); - float f = fifoin_pop_f(); - float g = fifoin_pop_f(); - float h = fifoin_pop_f(); - float i = fifoin_pop_f(); - float j = fifoin_pop_f(); - float k = fifoin_pop_f(); - float l = fifoin_pop_f(); - logerror("TGP matrix_mul %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, pushpc); - m[0] = a*cmat[0] + b*cmat[3] + c*cmat[6]; - m[1] = a*cmat[1] + b*cmat[4] + c*cmat[7]; - m[2] = a*cmat[2] + b*cmat[5] + c*cmat[8]; - m[3] = d*cmat[0] + e*cmat[3] + f*cmat[6]; - m[4] = d*cmat[1] + e*cmat[4] + f*cmat[7]; - m[5] = d*cmat[2] + e*cmat[5] + f*cmat[8]; - m[6] = g*cmat[0] + h*cmat[3] + i*cmat[6]; - m[7] = g*cmat[1] + h*cmat[4] + i*cmat[7]; - m[8] = g*cmat[2] + h*cmat[5] + i*cmat[8]; - m[9] = j*cmat[0] + k*cmat[3] + l*cmat[6] + cmat[9]; - m[10] = j*cmat[1] + k*cmat[4] + l*cmat[7] + cmat[10]; - m[11] = j*cmat[2] + k*cmat[5] + l*cmat[8] + cmat[11]; + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + float c = fifoin_pop_f(state); + float d = fifoin_pop_f(state); + float e = fifoin_pop_f(state); + float f = fifoin_pop_f(state); + float g = fifoin_pop_f(state); + float h = fifoin_pop_f(state); + float i = fifoin_pop_f(state); + float j = fifoin_pop_f(state); + float k = fifoin_pop_f(state); + float l = fifoin_pop_f(state); + logerror("TGP matrix_mul %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, state->pushpc); + m[0] = a*state->cmat[0] + b*state->cmat[3] + c*state->cmat[6]; + m[1] = a*state->cmat[1] + b*state->cmat[4] + c*state->cmat[7]; + m[2] = a*state->cmat[2] + b*state->cmat[5] + c*state->cmat[8]; + m[3] = d*state->cmat[0] + e*state->cmat[3] + f*state->cmat[6]; + m[4] = d*state->cmat[1] + e*state->cmat[4] + f*state->cmat[7]; + m[5] = d*state->cmat[2] + e*state->cmat[5] + f*state->cmat[8]; + m[6] = g*state->cmat[0] + h*state->cmat[3] + i*state->cmat[6]; + m[7] = g*state->cmat[1] + h*state->cmat[4] + i*state->cmat[7]; + m[8] = g*state->cmat[2] + h*state->cmat[5] + i*state->cmat[8]; + m[9] = j*state->cmat[0] + k*state->cmat[3] + l*state->cmat[6] + state->cmat[9]; + m[10] = j*state->cmat[1] + k*state->cmat[4] + l*state->cmat[7] + state->cmat[10]; + m[11] = j*state->cmat[2] + k*state->cmat[5] + l*state->cmat[8] + state->cmat[11]; - memcpy(cmat, m, sizeof(m)); - next_fn(); + memcpy(state->cmat, m, sizeof(m)); + next_fn(state); } static TGP_FUNCTION( anglev ) { - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - logerror("TGP anglev %f, %f (%x)\n", a, b, pushpc); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + logerror("TGP anglev %f, %f (%x)\n", a, b, state->pushpc); if(!b) { if(a>=0) - fifoout_push(0); + fifoout_push(state, 0); else - fifoout_push((UINT32)-32768); + fifoout_push(state, (UINT32)-32768); } else if(!a) { if(b>=0) - fifoout_push(16384); + fifoout_push(state, 16384); else - fifoout_push((UINT32)-16384); + fifoout_push(state, (UINT32)-16384); } else - fifoout_push((INT16)(atan2(b, a)*32768/M_PI)); - next_fn(); + fifoout_push(state, (INT16)(atan2(b, a)*32768/M_PI)); + next_fn(state); } static TGP_FUNCTION( f11 ) { - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - float c = fifoin_pop_f(); - float d = fifoin_pop_f(); - float e = fifoin_pop_f(); - float f = fifoin_pop_f(); - float g = fifoin_pop_f(); - float h = fifoin_pop_f(); - float i = fifoin_pop_f(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + float c = fifoin_pop_f(state); + float d = fifoin_pop_f(state); + float e = fifoin_pop_f(state); + float f = fifoin_pop_f(state); + float g = fifoin_pop_f(state); + float h = fifoin_pop_f(state); + float i = fifoin_pop_f(state); (void)a; (void)b; (void)c; @@ -302,235 +283,250 @@ static TGP_FUNCTION( f11 ) (void)g; (void)h; (void)i; - logerror("TGP f11 %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, pushpc); - fifoout_push_f(0); - fifoout_push_f(0); - fifoout_push_f(0); - next_fn(); + logerror("TGP f11 %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, state->pushpc); + fifoout_push_f(state, 0); + fifoout_push_f(state, 0); + fifoout_push_f(state, 0); + next_fn(state); } static TGP_FUNCTION( normalize ) { - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - float c = fifoin_pop_f(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + float c = fifoin_pop_f(state); float n = (a*a+b*b+c*c) / sqrt(a*a+b*b+c*c); - logerror("TGP normalize %f, %f, %f (%x)\n", a, b, c, pushpc); - fifoout_push_f(a/n); - fifoout_push_f(b/n); - fifoout_push_f(c/n); - next_fn(); + logerror("TGP normalize %f, %f, %f (%x)\n", a, b, c, state->pushpc); + fifoout_push_f(state, a/n); + fifoout_push_f(state, b/n); + fifoout_push_f(state, c/n); + next_fn(state); } static TGP_FUNCTION( acc_seti ) { - INT32 a = fifoin_pop(); - model1_dump = 1; - logerror("TGP acc_seti %d (%x)\n", a, pushpc); - acc = a; - next_fn(); + model1_state *state = machine->driver_data(); + INT32 a = fifoin_pop(state); + state->dump = 1; + logerror("TGP acc_seti %d (%x)\n", a, state->pushpc); + state->acc = a; + next_fn(state); } static TGP_FUNCTION( track_select ) { - INT32 a = fifoin_pop(); - logerror("TGP track_select %d (%x)\n", a, pushpc); - tgp_vr_select = a; - next_fn(); + model1_state *state = machine->driver_data(); + INT32 a = fifoin_pop(state); + logerror("TGP track_select %d (%x)\n", a, state->pushpc); + state->tgp_vr_select = a; + next_fn(state); } static TGP_FUNCTION( f14 ) { - tgp_vr_base[0] = fifoin_pop_f(); - tgp_vr_base[1] = fifoin_pop_f(); - tgp_vr_base[2] = fifoin_pop_f(); - tgp_vr_base[3] = fifoin_pop_f(); + model1_state *state = machine->driver_data(); + state->tgp_vr_base[0] = fifoin_pop_f(state); + state->tgp_vr_base[1] = fifoin_pop_f(state); + state->tgp_vr_base[2] = fifoin_pop_f(state); + state->tgp_vr_base[3] = fifoin_pop_f(state); - next_fn(); + next_fn(state); } static TGP_FUNCTION( f15_swa ) { - logerror("TGP f15_swa (%x)\n", pushpc); + model1_state *state = machine->driver_data(); + logerror("TGP f15_swa (%x)\n", state->pushpc); - next_fn(); + next_fn(state); } static TGP_FUNCTION( anglep ) { - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - float c = fifoin_pop_f(); - float d = fifoin_pop_f(); - logerror("TGP anglep %f, %f, %f, %f (%x)\n", a, b, c, d, pushpc); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + float c = fifoin_pop_f(state); + float d = fifoin_pop_f(state); + logerror("TGP anglep %f, %f, %f, %f (%x)\n", a, b, c, d, state->pushpc); c = a - c; d = b - d; if(!d) { if(c>=0) - fifoout_push(0); + fifoout_push(state, 0); else - fifoout_push((UINT32)-32768); + fifoout_push(state, (UINT32)-32768); } else if(!c) { if(d>=0) - fifoout_push(16384); + fifoout_push(state, 16384); else - fifoout_push((UINT32)-16384); + fifoout_push(state, (UINT32)-16384); } else - fifoout_push((INT16)(atan2(d, c)*32768/M_PI)); - next_fn(); + fifoout_push(state, (INT16)(atan2(d, c)*32768/M_PI)); + next_fn(state); } static TGP_FUNCTION( matrix_ident ) { - logerror("TGP matrix_ident (%x)\n", pushpc); - memset(cmat, 0, sizeof(cmat)); - cmat[0] = 1.0; - cmat[4] = 1.0; - cmat[8] = 1.0; - next_fn(); + model1_state *state = machine->driver_data(); + logerror("TGP matrix_ident (%x)\n", state->pushpc); + memset(state->cmat, 0, sizeof(state->cmat)); + state->cmat[0] = 1.0; + state->cmat[4] = 1.0; + state->cmat[8] = 1.0; + next_fn(state); } static TGP_FUNCTION( matrix_read ) { + model1_state *state = machine->driver_data(); int i; logerror("TGP matrix_read (%f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f) (%x)\n", - cmat[0], cmat[1], cmat[2], cmat[3], cmat[4], cmat[5], cmat[6], cmat[7], cmat[8], cmat[9], cmat[10], cmat[11], pushpc); + state->cmat[0], state->cmat[1], state->cmat[2], state->cmat[3], state->cmat[4], state->cmat[5], state->cmat[6], state->cmat[7], state->cmat[8], state->cmat[9], state->cmat[10], state->cmat[11], state->pushpc); for(i=0; i<12; i++) - fifoout_push_f(cmat[i]); - next_fn(); + fifoout_push_f(state, state->cmat[i]); + next_fn(state); } static TGP_FUNCTION( matrix_trans ) { - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - float c = fifoin_pop_f(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + float c = fifoin_pop_f(state); - cmat[ 9] += cmat[0]*a+cmat[3]*b+cmat[6]*c; - cmat[10] += cmat[1]*a+cmat[4]*b+cmat[7]*c; - cmat[11] += cmat[2]*a+cmat[5]*b+cmat[8]*c; - next_fn(); + state->cmat[ 9] += state->cmat[0]*a+state->cmat[3]*b+state->cmat[6]*c; + state->cmat[10] += state->cmat[1]*a+state->cmat[4]*b+state->cmat[7]*c; + state->cmat[11] += state->cmat[2]*a+state->cmat[5]*b+state->cmat[8]*c; + next_fn(state); } static TGP_FUNCTION( matrix_scale ) { - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - float c = fifoin_pop_f(); - logerror("TGP matrix_scale %f, %f, %f (%x)\n", a, b, c, pushpc); - cmat[0] *= a; - cmat[1] *= a; - cmat[2] *= a; - cmat[3] *= b; - cmat[4] *= b; - cmat[5] *= b; - cmat[6] *= c; - cmat[7] *= c; - cmat[8] *= c; - next_fn(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + float c = fifoin_pop_f(state); + logerror("TGP matrix_scale %f, %f, %f (%x)\n", a, b, c, state->pushpc); + state->cmat[0] *= a; + state->cmat[1] *= a; + state->cmat[2] *= a; + state->cmat[3] *= b; + state->cmat[4] *= b; + state->cmat[5] *= b; + state->cmat[6] *= c; + state->cmat[7] *= c; + state->cmat[8] *= c; + next_fn(state); } static TGP_FUNCTION( matrix_rotx ) { - INT16 a = fifoin_pop(); + model1_state *state = machine->driver_data(); + INT16 a = fifoin_pop(state); float s = tsin(a); float c = tcos(a); float t1, t2; - logerror("TGP matrix_rotx %d (%x)\n", a, pushpc); - t1 = cmat[3]; - t2 = cmat[6]; - cmat[3] = c*t1-s*t2; - cmat[6] = s*t1+c*t2; - t1 = cmat[4]; - t2 = cmat[7]; - cmat[4] = c*t1-s*t2; - cmat[7] = s*t1+c*t2; - t1 = cmat[5]; - t2 = cmat[8]; - cmat[5] = c*t1-s*t2; - cmat[8] = s*t1+c*t2; - next_fn(); + logerror("TGP matrix_rotx %d (%x)\n", a, state->pushpc); + t1 = state->cmat[3]; + t2 = state->cmat[6]; + state->cmat[3] = c*t1-s*t2; + state->cmat[6] = s*t1+c*t2; + t1 = state->cmat[4]; + t2 = state->cmat[7]; + state->cmat[4] = c*t1-s*t2; + state->cmat[7] = s*t1+c*t2; + t1 = state->cmat[5]; + t2 = state->cmat[8]; + state->cmat[5] = c*t1-s*t2; + state->cmat[8] = s*t1+c*t2; + next_fn(state); } static TGP_FUNCTION( matrix_roty ) { - INT16 a = fifoin_pop(); + model1_state *state = machine->driver_data(); + INT16 a = fifoin_pop(state); float s = tsin(a); float c = tcos(a); float t1, t2; - logerror("TGP matrix_roty %d (%x)\n", a, pushpc); - t1 = cmat[6]; - t2 = cmat[0]; - cmat[6] = c*t1-s*t2; - cmat[0] = s*t1+c*t2; - t1 = cmat[7]; - t2 = cmat[1]; - cmat[7] = c*t1-s*t2; - cmat[1] = s*t1+c*t2; - t1 = cmat[8]; - t2 = cmat[2]; - cmat[8] = c*t1-s*t2; - cmat[2] = s*t1+c*t2; - next_fn(); + logerror("TGP matrix_roty %d (%x)\n", a, state->pushpc); + t1 = state->cmat[6]; + t2 = state->cmat[0]; + state->cmat[6] = c*t1-s*t2; + state->cmat[0] = s*t1+c*t2; + t1 = state->cmat[7]; + t2 = state->cmat[1]; + state->cmat[7] = c*t1-s*t2; + state->cmat[1] = s*t1+c*t2; + t1 = state->cmat[8]; + t2 = state->cmat[2]; + state->cmat[8] = c*t1-s*t2; + state->cmat[2] = s*t1+c*t2; + next_fn(state); } static TGP_FUNCTION( matrix_rotz ) { - INT16 a = fifoin_pop(); + model1_state *state = machine->driver_data(); + INT16 a = fifoin_pop(state); float s = tsin(a); float c = tcos(a); float t1, t2; - logerror("TGP matrix_rotz %d (%x)\n", a, pushpc); - t1 = cmat[0]; - t2 = cmat[3]; - cmat[0] = c*t1-s*t2; - cmat[3] = s*t1+c*t2; - t1 = cmat[1]; - t2 = cmat[4]; - cmat[1] = c*t1-s*t2; - cmat[4] = s*t1+c*t2; - t1 = cmat[2]; - t2 = cmat[5]; - cmat[2] = c*t1-s*t2; - cmat[5] = s*t1+c*t2; - next_fn(); + logerror("TGP matrix_rotz %d (%x)\n", a, state->pushpc); + t1 = state->cmat[0]; + t2 = state->cmat[3]; + state->cmat[0] = c*t1-s*t2; + state->cmat[3] = s*t1+c*t2; + t1 = state->cmat[1]; + t2 = state->cmat[4]; + state->cmat[1] = c*t1-s*t2; + state->cmat[4] = s*t1+c*t2; + t1 = state->cmat[2]; + t2 = state->cmat[5]; + state->cmat[2] = c*t1-s*t2; + state->cmat[5] = s*t1+c*t2; + next_fn(state); } static TGP_FUNCTION( track_read_quad ) { + model1_state *state = machine->driver_data(); const UINT32 *tgp_data = (const UINT32 *)machine->region("user2")->base(); - UINT32 a = fifoin_pop(); + UINT32 a = fifoin_pop(state); int offd; - logerror("TGP track_read_quad %d (%x)\n", a, pushpc); + logerror("TGP track_read_quad %d (%x)\n", a, state->pushpc); - offd = tgp_data[0x20+tgp_vr_select] + 16*a; - fifoout_push(tgp_data[offd]); - fifoout_push(tgp_data[offd+1]); - fifoout_push(tgp_data[offd+2]); - fifoout_push(tgp_data[offd+3]); - fifoout_push(tgp_data[offd+4]); - fifoout_push(tgp_data[offd+5]); - fifoout_push(tgp_data[offd+6]); - fifoout_push(tgp_data[offd+7]); - fifoout_push(tgp_data[offd+8]); - fifoout_push(tgp_data[offd+9]); - fifoout_push(tgp_data[offd+10]); - fifoout_push(tgp_data[offd+11]); - next_fn(); + offd = tgp_data[0x20+state->tgp_vr_select] + 16*a; + fifoout_push(state, tgp_data[offd]); + fifoout_push(state, tgp_data[offd+1]); + fifoout_push(state, tgp_data[offd+2]); + fifoout_push(state, tgp_data[offd+3]); + fifoout_push(state, tgp_data[offd+4]); + fifoout_push(state, tgp_data[offd+5]); + fifoout_push(state, tgp_data[offd+6]); + fifoout_push(state, tgp_data[offd+7]); + fifoout_push(state, tgp_data[offd+8]); + fifoout_push(state, tgp_data[offd+9]); + fifoout_push(state, tgp_data[offd+10]); + fifoout_push(state, tgp_data[offd+11]); + next_fn(state); } static TGP_FUNCTION( f24_swa ) { - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - float c = fifoin_pop_f(); - float d = fifoin_pop_f(); - float e = fifoin_pop_f(); - float f = fifoin_pop_f(); - UINT32 g = fifoin_pop(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + float c = fifoin_pop_f(state); + float d = fifoin_pop_f(state); + float e = fifoin_pop_f(state); + float f = fifoin_pop_f(state); + UINT32 g = fifoin_pop(state); (void)a; (void)b; (void)c; @@ -538,155 +534,170 @@ static TGP_FUNCTION( f24_swa ) (void)e; (void)f; (void)g; - logerror("TGP f24_swa %f, %f, %f, %f, %f, %f, %x (%x)\n", a, b, c, d, e, f, g, pushpc); - fifoout_push_f(0); - next_fn(); + logerror("TGP f24_swa %f, %f, %f, %f, %f, %f, %x (%x)\n", a, b, c, d, e, f, g, state->pushpc); + fifoout_push_f(state, 0); + next_fn(state); } static TGP_FUNCTION( transform_point ) { - float x = fifoin_pop_f(); - float y = fifoin_pop_f(); - float z = fifoin_pop_f(); - logerror("TGP transform_point %f, %f, %f (%x)\n", x, y, z, pushpc); + model1_state *state = machine->driver_data(); + float x = fifoin_pop_f(state); + float y = fifoin_pop_f(state); + float z = fifoin_pop_f(state); + logerror("TGP transform_point %f, %f, %f (%x)\n", x, y, z, state->pushpc); - fifoout_push_f(cmat[0]*x+cmat[3]*y+cmat[6]*z+cmat[9]); - fifoout_push_f(cmat[1]*x+cmat[4]*y+cmat[7]*z+cmat[10]); - fifoout_push_f(cmat[2]*x+cmat[5]*y+cmat[8]*z+cmat[11]); - next_fn(); + fifoout_push_f(state, state->cmat[0]*x+state->cmat[3]*y+state->cmat[6]*z+state->cmat[9]); + fifoout_push_f(state, state->cmat[1]*x+state->cmat[4]*y+state->cmat[7]*z+state->cmat[10]); + fifoout_push_f(state, state->cmat[2]*x+state->cmat[5]*y+state->cmat[8]*z+state->cmat[11]); + next_fn(state); } static TGP_FUNCTION( fcos_m1 ) { - INT16 a = fifoin_pop(); - logerror("TGP fcos %d (%x)\n", a, pushpc); - fifoout_push_f(tcos(a)); - next_fn(); + model1_state *state = machine->driver_data(); + INT16 a = fifoin_pop(state); + logerror("TGP fcos %d (%x)\n", a, state->pushpc); + fifoout_push_f(state, tcos(a)); + next_fn(state); } static TGP_FUNCTION( fsin_m1 ) { - INT16 a = fifoin_pop(); - logerror("TGP fsin %d (%x)\n", a, pushpc); - fifoout_push_f(tsin(a)); - next_fn(); + model1_state *state = machine->driver_data(); + INT16 a = fifoin_pop(state); + logerror("TGP fsin %d (%x)\n", a, state->pushpc); + fifoout_push_f(state, tsin(a)); + next_fn(state); } static TGP_FUNCTION( fcosm_m1 ) { - INT16 a = fifoin_pop(); - float b = fifoin_pop_f(); - logerror("TGP fcosm %d, %f (%x)\n", a, b, pushpc); - fifoout_push_f(b*tcos(a)); - next_fn(); + model1_state *state = machine->driver_data(); + INT16 a = fifoin_pop(state); + float b = fifoin_pop_f(state); + logerror("TGP fcosm %d, %f (%x)\n", a, b, state->pushpc); + fifoout_push_f(state, b*tcos(a)); + next_fn(state); } static TGP_FUNCTION( fsinm_m1 ) { - INT16 a = fifoin_pop(); - float b = fifoin_pop_f(); - model1_dump = 1; - logerror("TGP fsinm %d, %f (%x)\n", a, b, pushpc); - fifoout_push_f(b*tsin(a)); - next_fn(); + model1_state *state = machine->driver_data(); + INT16 a = fifoin_pop(state); + float b = fifoin_pop_f(state); + state->dump = 1; + logerror("TGP fsinm %d, %f (%x)\n", a, b, state->pushpc); + fifoout_push_f(state, b*tsin(a)); + next_fn(state); } static TGP_FUNCTION( distance3 ) { - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - float c = fifoin_pop_f(); - float d = fifoin_pop_f(); - float e = fifoin_pop_f(); - float f = fifoin_pop_f(); - logerror("TGP distance3 (%f, %f, %f), (%f, %f, %f) (%x)\n", a, b, c, d, e, f, pushpc); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + float c = fifoin_pop_f(state); + float d = fifoin_pop_f(state); + float e = fifoin_pop_f(state); + float f = fifoin_pop_f(state); + logerror("TGP distance3 (%f, %f, %f), (%f, %f, %f) (%x)\n", a, b, c, d, e, f, state->pushpc); a -= d; b -= e; c -= f; - fifoout_push_f((a*a+b*b+c*c)/sqrt(a*a+b*b+c*c)); - next_fn(); + fifoout_push_f(state, (a*a+b*b+c*c)/sqrt(a*a+b*b+c*c)); + next_fn(state); } static TGP_FUNCTION( ftoi ) { - float a = fifoin_pop_f(); - logerror("TGP ftoi %f (%x)\n", a, pushpc); - fifoout_push((int)a); - next_fn(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + logerror("TGP ftoi %f (%x)\n", a, state->pushpc); + fifoout_push(state, (int)a); + next_fn(state); } static TGP_FUNCTION( itof ) { - INT32 a = fifoin_pop(); - logerror("TGP itof %d (%x)\n", a, pushpc); - fifoout_push_f(a); - next_fn(); + model1_state *state = machine->driver_data(); + INT32 a = fifoin_pop(state); + logerror("TGP itof %d (%x)\n", a, state->pushpc); + fifoout_push_f(state, a); + next_fn(state); } static TGP_FUNCTION( acc_set ) { - float a = fifoin_pop_f(); - logerror("TGP acc_set %f (%x)\n", a, pushpc); - acc = a; - next_fn(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + logerror("TGP acc_set %f (%x)\n", a, state->pushpc); + state->acc = a; + next_fn(state); } static TGP_FUNCTION( acc_get ) { - logerror("TGP acc_get (%x)\n", pushpc); - fifoout_push_f(acc); - next_fn(); + model1_state *state = machine->driver_data(); + logerror("TGP acc_get (%x)\n", state->pushpc); + fifoout_push_f(state, state->acc); + next_fn(state); } static TGP_FUNCTION( acc_add ) { - float a = fifoin_pop_f(); - logerror("TGP acc_add %f (%x)\n", a, pushpc); - acc += a; - next_fn(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + logerror("TGP acc_add %f (%x)\n", a, state->pushpc); + state->acc += a; + next_fn(state); } static TGP_FUNCTION( acc_sub ) { - float a = fifoin_pop_f(); - logerror("TGP acc_sub %f (%x)\n", a, pushpc); - acc -= a; - next_fn(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + logerror("TGP acc_sub %f (%x)\n", a, state->pushpc); + state->acc -= a; + next_fn(state); } static TGP_FUNCTION( acc_mul ) { - float a = fifoin_pop_f(); - logerror("TGP acc_mul %f (%x)\n", a, pushpc); - acc *= a; - next_fn(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + logerror("TGP acc_mul %f (%x)\n", a, state->pushpc); + state->acc *= a; + next_fn(state); } static TGP_FUNCTION( acc_div ) { - float a = fifoin_pop_f(); - logerror("TGP acc_div %f (%x)\n", a, pushpc); - acc /= a; - next_fn(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + logerror("TGP acc_div %f (%x)\n", a, state->pushpc); + state->acc /= a; + next_fn(state); } static TGP_FUNCTION( f42 ) { - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - float c = fifoin_pop_f(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + float c = fifoin_pop_f(state); (void)a; (void)b; (void)c; - logerror("TGP f42 %f, %f, %f (%x)\n", a, b, c, pushpc); + logerror("TGP f42 %f, %f, %f (%x)\n", a, b, c, state->pushpc); // fifoout_push_f((machine->rand() % 1000) - 500); - fifoout_push_f(0); - fifoout_push_f(0); - fifoout_push_f(0); - fifoout_push_f(0); - fifoout_push_f(0); - fifoout_push_f(0); - next_fn(); + fifoout_push_f(state, 0); + fifoout_push_f(state, 0); + fifoout_push_f(state, 0); + fifoout_push_f(state, 0); + fifoout_push_f(state, 0); + fifoout_push_f(state, 0); + next_fn(state); } @@ -694,98 +705,103 @@ static TGP_FUNCTION( f42 ) static TGP_FUNCTION( xyz2rqf ) { - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - float c = fifoin_pop_f(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + float c = fifoin_pop_f(state); float norm; (void)a; (void)b; (void)c; - logerror("TGP xyz2rqf %f, %f, %f (%x)\n", a, b, c, pushpc); - fifoout_push_f((a*a+b*b+c*c)/sqrt(a*a+b*b+c*c)); + logerror("TGP xyz2rqf %f, %f, %f (%x)\n", a, b, c, state->pushpc); + fifoout_push_f(state, (a*a+b*b+c*c)/sqrt(a*a+b*b+c*c)); norm = sqrt(a*a+c*c); if(!c) { if(a>=0) - fifoout_push(0); + fifoout_push(state, 0); else - fifoout_push((UINT32)-32768); + fifoout_push(state, (UINT32)-32768); } else if(!a) { if(c>=0) - fifoout_push(16384); + fifoout_push(state, 16384); else - fifoout_push((UINT32)-16384); + fifoout_push(state, (UINT32)-16384); } else - fifoout_push((INT16)(atan2(c, a)*32768/M_PI)); + fifoout_push(state, (INT16)(atan2(c, a)*32768/M_PI)); if(!b) - fifoout_push(0); + fifoout_push(state, 0); else if(!norm) { if(b>=0) - fifoout_push(16384); + fifoout_push(state, 16384); else - fifoout_push((UINT32)-16384); + fifoout_push(state, (UINT32)-16384); } else - fifoout_push((INT16)(atan2(b, norm)*32768/M_PI)); + fifoout_push(state, (INT16)(atan2(b, norm)*32768/M_PI)); - next_fn(); + next_fn(state); } static TGP_FUNCTION( f43 ) { - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - float c = fifoin_pop_f(); - float d = fifoin_pop_f(); - float e = fifoin_pop_f(); - float f = fifoin_pop_f(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + float c = fifoin_pop_f(state); + float d = fifoin_pop_f(state); + float e = fifoin_pop_f(state); + float f = fifoin_pop_f(state); (void)a; (void)b; (void)c; (void)d; (void)e; (void)f; - logerror("TGP f43 %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, pushpc); - fifoout_push_f(0); - fifoout_push_f(0); - fifoout_push_f(0); - fifoout_push_f(0); - next_fn(); + logerror("TGP f43 %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, state->pushpc); + fifoout_push_f(state, 0); + fifoout_push_f(state, 0); + fifoout_push_f(state, 0); + fifoout_push_f(state, 0); + next_fn(state); } static TGP_FUNCTION( f43_swa ) { - float a = fifoin_pop_f(); - int b = fifoin_pop(); - int c = fifoin_pop(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + int b = fifoin_pop(state); + int c = fifoin_pop(state); (void)a; (void)b; (void)c; - logerror("TGP f43_swa %f, %d, %d (%x)\n", a, b, c, pushpc); - fifoout_push_f(0); - fifoout_push_f(0); - fifoout_push_f(0); - next_fn(); + logerror("TGP f43_swa %f, %d, %d (%x)\n", a, b, c, state->pushpc); + fifoout_push_f(state, 0); + fifoout_push_f(state, 0); + fifoout_push_f(state, 0); + next_fn(state); } static TGP_FUNCTION( f44 ) { - float a = fifoin_pop_f(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); (void)a; - logerror("TGP f44 %f (%x)\n", a, pushpc); - fifoout_push_f(0); - fifoout_push_f(0); - fifoout_push_f(0); - next_fn(); + logerror("TGP f44 %f (%x)\n", a, state->pushpc); + fifoout_push_f(state, 0); + fifoout_push_f(state, 0); + fifoout_push_f(state, 0); + next_fn(state); } static TGP_FUNCTION( matrix_sdir ) { - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - float c = fifoin_pop_f(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + float c = fifoin_pop_f(state); float norm = sqrt(a*a+b*b+c*c); float t[9], m[9]; - logerror("TGP matrix_sdir %f, %f, %f (%x)\n", a, b, c, pushpc); + logerror("TGP matrix_sdir %f, %f, %f (%x)\n", a, b, c, state->pushpc); memset(t, 0, sizeof(t)); @@ -813,164 +829,174 @@ static TGP_FUNCTION( matrix_sdir ) t[5] /= norm; } - m[0] = t[0]*cmat[0] + t[1]*cmat[3] + t[2]*cmat[6]; - m[1] = t[0]*cmat[1] + t[1]*cmat[4] + t[2]*cmat[7]; - m[2] = t[0]*cmat[2] + t[1]*cmat[5] + t[2]*cmat[8]; - m[3] = t[3]*cmat[0] + t[4]*cmat[3] + t[5]*cmat[6]; - m[4] = t[3]*cmat[1] + t[4]*cmat[4] + t[5]*cmat[7]; - m[5] = t[3]*cmat[2] + t[4]*cmat[5] + t[5]*cmat[8]; - m[6] = t[6]*cmat[0] + t[7]*cmat[3] + t[8]*cmat[6]; - m[7] = t[6]*cmat[1] + t[7]*cmat[4] + t[8]*cmat[7]; - m[8] = t[6]*cmat[2] + t[7]*cmat[5] + t[8]*cmat[8]; + m[0] = t[0]*state->cmat[0] + t[1]*state->cmat[3] + t[2]*state->cmat[6]; + m[1] = t[0]*state->cmat[1] + t[1]*state->cmat[4] + t[2]*state->cmat[7]; + m[2] = t[0]*state->cmat[2] + t[1]*state->cmat[5] + t[2]*state->cmat[8]; + m[3] = t[3]*state->cmat[0] + t[4]*state->cmat[3] + t[5]*state->cmat[6]; + m[4] = t[3]*state->cmat[1] + t[4]*state->cmat[4] + t[5]*state->cmat[7]; + m[5] = t[3]*state->cmat[2] + t[4]*state->cmat[5] + t[5]*state->cmat[8]; + m[6] = t[6]*state->cmat[0] + t[7]*state->cmat[3] + t[8]*state->cmat[6]; + m[7] = t[6]*state->cmat[1] + t[7]*state->cmat[4] + t[8]*state->cmat[7]; + m[8] = t[6]*state->cmat[2] + t[7]*state->cmat[5] + t[8]*state->cmat[8]; - memcpy(cmat, m, sizeof(m)); + memcpy(state->cmat, m, sizeof(m)); - next_fn(); + next_fn(state); } static TGP_FUNCTION( f45 ) { - float a = fifoin_pop_f(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); (void)a; - logerror("TGP f45 %f (%x)\n", a, pushpc); - fifoout_push_f(0); - next_fn(); + logerror("TGP f45 %f (%x)\n", a, state->pushpc); + fifoout_push_f(state, 0); + next_fn(state); } static TGP_FUNCTION( vlength ) { - float a = fifoin_pop_f() - tgp_vr_base[0]; - float b = fifoin_pop_f() - tgp_vr_base[1]; - float c = fifoin_pop_f() - tgp_vr_base[2]; - logerror("TGP vlength %f, %f, %f (%x)\n", a, b, c, pushpc); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state) - state->tgp_vr_base[0]; + float b = fifoin_pop_f(state) - state->tgp_vr_base[1]; + float c = fifoin_pop_f(state) - state->tgp_vr_base[2]; + logerror("TGP vlength %f, %f, %f (%x)\n", a, b, c, state->pushpc); a = (a*a+b*b+c*c); b = 1/sqrt(a); c = a * b; - c -= tgp_vr_base[3]; - fifoout_push_f(c); - next_fn(); + c -= state->tgp_vr_base[3]; + fifoout_push_f(state, c); + next_fn(state); } static TGP_FUNCTION( f47 ) { - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - float c = fifoin_pop_f(); - logerror("TGP f47 %f, %f, %f (%x)\n", a, b, c, pushpc); - fifoout_push_f(a+c); - fifoout_push_f(b+c); - next_fn(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + float c = fifoin_pop_f(state); + logerror("TGP f47 %f, %f, %f (%x)\n", a, b, c, state->pushpc); + fifoout_push_f(state, a+c); + fifoout_push_f(state, b+c); + next_fn(state); } static TGP_FUNCTION( track_read_info ) { + model1_state *state = machine->driver_data(); const UINT32 *tgp_data = (const UINT32 *)machine->region("user2")->base(); - UINT16 a = fifoin_pop(); + UINT16 a = fifoin_pop(state); int offd; - logerror("TGP track_read_info %d (%x)\n", a, pushpc); + logerror("TGP track_read_info %d (%x)\n", a, state->pushpc); - offd = tgp_data[0x20+tgp_vr_select] + 16*a; - fifoout_push(tgp_data[offd+15]); - next_fn(); + offd = tgp_data[0x20+state->tgp_vr_select] + 16*a; + fifoout_push(state, tgp_data[offd+15]); + next_fn(state); } static TGP_FUNCTION( colbox_set ) { - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - float c = fifoin_pop_f(); - float d = fifoin_pop_f(); - float e = fifoin_pop_f(); - float f = fifoin_pop_f(); - float g = fifoin_pop_f(); - float h = fifoin_pop_f(); - float i = fifoin_pop_f(); - float j = fifoin_pop_f(); - float k = fifoin_pop_f(); - float l = fifoin_pop_f(); - logerror("TGP colbox_set %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, pushpc); - tgp_vr_cbox[ 0] = a; - tgp_vr_cbox[ 1] = b; - tgp_vr_cbox[ 2] = c; - tgp_vr_cbox[ 3] = d; - tgp_vr_cbox[ 4] = e; - tgp_vr_cbox[ 5] = f; - tgp_vr_cbox[ 6] = g; - tgp_vr_cbox[ 7] = h; - tgp_vr_cbox[ 8] = i; - tgp_vr_cbox[ 9] = j; - tgp_vr_cbox[10] = k; - tgp_vr_cbox[11] = l; - next_fn(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + float c = fifoin_pop_f(state); + float d = fifoin_pop_f(state); + float e = fifoin_pop_f(state); + float f = fifoin_pop_f(state); + float g = fifoin_pop_f(state); + float h = fifoin_pop_f(state); + float i = fifoin_pop_f(state); + float j = fifoin_pop_f(state); + float k = fifoin_pop_f(state); + float l = fifoin_pop_f(state); + logerror("TGP colbox_set %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, state->pushpc); + state->tgp_vr_cbox[ 0] = a; + state->tgp_vr_cbox[ 1] = b; + state->tgp_vr_cbox[ 2] = c; + state->tgp_vr_cbox[ 3] = d; + state->tgp_vr_cbox[ 4] = e; + state->tgp_vr_cbox[ 5] = f; + state->tgp_vr_cbox[ 6] = g; + state->tgp_vr_cbox[ 7] = h; + state->tgp_vr_cbox[ 8] = i; + state->tgp_vr_cbox[ 9] = j; + state->tgp_vr_cbox[10] = k; + state->tgp_vr_cbox[11] = l; + next_fn(state); } static TGP_FUNCTION( colbox_test ) { - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - float c = fifoin_pop_f(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + float c = fifoin_pop_f(state); (void)a; (void)b; (void)c; - logerror("TGP colbox_test %f, %f, %f (%x)\n", a, b, c, pushpc); + logerror("TGP colbox_test %f, %f, %f (%x)\n", a, b, c, state->pushpc); - // #### Wrong, need to check with the tgp_vr_cbox coordinates + // #### Wrong, need to check with the state->tgp_vr_cbox coordinates // Game only test sign, negative = collision - fifoout_push_f(-1); - next_fn(); + fifoout_push_f(state, -1); + next_fn(state); } static TGP_FUNCTION( f49_swa ) { - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - float c = fifoin_pop_f(); - float d = fifoin_pop_f(); - float e = fifoin_pop_f(); - float f = fifoin_pop_f(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + float c = fifoin_pop_f(state); + float d = fifoin_pop_f(state); + float e = fifoin_pop_f(state); + float f = fifoin_pop_f(state); (void)a; (void)b; (void)c; (void)d; (void)e; (void)f; - logerror("TGP f49_swa %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, pushpc); - next_fn(); + logerror("TGP f49_swa %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, state->pushpc); + next_fn(state); } static TGP_FUNCTION( f50_swa ) { - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - float c = fifoin_pop_f(); - float d = fifoin_pop_f(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + float c = fifoin_pop_f(state); + float d = fifoin_pop_f(state); (void)a; (void)b; (void)c; (void)d; - logerror("TGP f50_swa %f, %f, %f, %f (%x)\n", a, b, c, d, pushpc); - fifoout_push_f(d); - next_fn(); + logerror("TGP f50_swa %f, %f, %f, %f (%x)\n", a, b, c, d, state->pushpc); + fifoout_push_f(state, d); + next_fn(state); } static TGP_FUNCTION( f52 ) { - logerror("TGP f52 (%x)\n", pushpc); - next_fn(); + model1_state *state = machine->driver_data(); + logerror("TGP f52 (%x)\n", state->pushpc); + next_fn(state); } static TGP_FUNCTION( matrix_rdir ) { - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - float c = fifoin_pop_f(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + float c = fifoin_pop_f(state); float norm = sqrt(a*a+c*c); float t1, t2; (void)b; - logerror("TGP matrix_rdir %f, %f, %f (%x)\n", a, b, c, pushpc); + logerror("TGP matrix_rdir %f, %f, %f (%x)\n", a, b, c, state->pushpc); if(!norm) { c = 1; @@ -980,19 +1006,19 @@ static TGP_FUNCTION( matrix_rdir ) a /= norm; } - t1 = cmat[6]; - t2 = cmat[0]; - cmat[6] = c*t1-a*t2; - cmat[0] = a*t1+c*t2; - t1 = cmat[7]; - t2 = cmat[1]; - cmat[7] = c*t1-a*t2; - cmat[1] = a*t1+c*t2; - t1 = cmat[8]; - t2 = cmat[2]; - cmat[8] = c*t1-a*t2; - cmat[2] = a*t1+c*t2; - next_fn(); + t1 = state->cmat[6]; + t2 = state->cmat[0]; + state->cmat[6] = c*t1-a*t2; + state->cmat[0] = a*t1+c*t2; + t1 = state->cmat[7]; + t2 = state->cmat[1]; + state->cmat[7] = c*t1-a*t2; + state->cmat[1] = a*t1+c*t2; + t1 = state->cmat[8]; + t2 = state->cmat[2]; + state->cmat[8] = c*t1-a*t2; + state->cmat[2] = a*t1+c*t2; + next_fn(state); } // A+(B-A)*t1 + (C-A)*t2 = P @@ -1012,21 +1038,22 @@ static void tri_calc_pq(float ax, float ay, float bx, float by, float cx, float static TGP_FUNCTION( track_lookup ) { + model1_state *state = machine->driver_data(); const UINT32 *tgp_data = (const UINT32 *)machine->region("user2")->base(); - float a = fifoin_pop_f(); - UINT32 b = fifoin_pop(); - float c = fifoin_pop_f(); - float d = fifoin_pop_f(); + float a = fifoin_pop_f(state); + UINT32 b = fifoin_pop(state); + float c = fifoin_pop_f(state); + float d = fifoin_pop_f(state); int offi, offd, len; float dist; int i; UINT32 behaviour, entry; float height; - logerror("TGP track_lookup %f, 0x%x, %f, %f (%x)\n", a, b, c, d, pushpc); + logerror("TGP track_lookup %f, 0x%x, %f, %f (%x)\n", a, b, c, d, state->pushpc); - offi = tgp_data[0x10+tgp_vr_select] + b; - offd = tgp_data[0x20+tgp_vr_select]; + offi = tgp_data[0x10+state->tgp_vr_select] + b; + offd = tgp_data[0x20+state->tgp_vr_select]; len = tgp_data[offi++]; @@ -1061,22 +1088,23 @@ static TGP_FUNCTION( track_lookup ) } } - ram_data[0x0000] = 0; // non zero = still computing - ram_data[0x8001] = f2u(height); - ram_data[0x8002] = entry; + state->ram_data[0x0000] = 0; // non zero = still computing + state->ram_data[0x8001] = f2u(height); + state->ram_data[0x8002] = entry; - next_fn(); + next_fn(state); } static TGP_FUNCTION( f56 ) { - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - float c = fifoin_pop_f(); - float d = fifoin_pop_f(); - float e = fifoin_pop_f(); - float f = fifoin_pop_f(); - UINT32 g = fifoin_pop(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + float c = fifoin_pop_f(state); + float d = fifoin_pop_f(state); + float e = fifoin_pop_f(state); + float f = fifoin_pop_f(state); + UINT32 g = fifoin_pop(state); (void)a; (void)b; (void)c; @@ -1085,102 +1113,110 @@ static TGP_FUNCTION( f56 ) (void)f; (void)g; - logerror("TGP f56 %f, %f, %f, %f, %f, %f, %d (%x)\n", a, b, c, d, e, f, g, pushpc); - fifoout_push(0); - next_fn(); + logerror("TGP f56 %f, %f, %f, %f, %f, %f, %d (%x)\n", a, b, c, d, e, f, g, state->pushpc); + fifoout_push(state, 0); + next_fn(state); } static TGP_FUNCTION( f57 ) { - logerror("TGP f57 (%x)\n", pushpc); - fifoout_push_f(0); - fifoout_push_f(0); - fifoout_push_f(0); - next_fn(); + model1_state *state = machine->driver_data(); + logerror("TGP f57 (%x)\n", state->pushpc); + fifoout_push_f(state, 0); + fifoout_push_f(state, 0); + fifoout_push_f(state, 0); + next_fn(state); } static TGP_FUNCTION( matrix_readt ) { - logerror("TGP matrix_readt (%x)\n", pushpc); - fifoout_push_f(cmat[9]); - fifoout_push_f(cmat[10]); - fifoout_push_f(cmat[11]); - next_fn(); + model1_state *state = machine->driver_data(); + logerror("TGP matrix_readt (%x)\n", state->pushpc); + fifoout_push_f(state, state->cmat[9]); + fifoout_push_f(state, state->cmat[10]); + fifoout_push_f(state, state->cmat[11]); + next_fn(state); } static TGP_FUNCTION( acc_geti ) { - logerror("TGP acc_geti (%x)\n", pushpc); - fifoout_push((int)acc); - next_fn(); + model1_state *state = machine->driver_data(); + logerror("TGP acc_geti (%x)\n", state->pushpc); + fifoout_push(state, (int)state->acc); + next_fn(state); } static TGP_FUNCTION( f60 ) { - logerror("TGP f60 (%x)\n", pushpc); - fifoout_push_f(0); - fifoout_push_f(0); - fifoout_push_f(0); - next_fn(); + model1_state *state = machine->driver_data(); + logerror("TGP f60 (%x)\n", state->pushpc); + fifoout_push_f(state, 0); + fifoout_push_f(state, 0); + fifoout_push_f(state, 0); + next_fn(state); } static TGP_FUNCTION( col_setcirc ) { - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - float c = fifoin_pop_f(); - logerror("TGP col_setcirc %f, %f, %f (%x)\n", a, b, c, pushpc); - tgp_vr_circx = a; - tgp_vr_circy = b; - tgp_vr_circrad = c; - next_fn(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + float c = fifoin_pop_f(state); + logerror("TGP col_setcirc %f, %f, %f (%x)\n", a, b, c, state->pushpc); + state->tgp_vr_circx = a; + state->tgp_vr_circy = b; + state->tgp_vr_circrad = c; + next_fn(state); } static TGP_FUNCTION( col_testpt ) { + model1_state *state = machine->driver_data(); float x, y; - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - logerror("TGP col_testpt %f, %f (%x)\n", a, b, pushpc); - x = a - tgp_vr_circx; - y = b - tgp_vr_circy; - fifoout_push_f(((x*x+y*y)/sqrt(x*x+y*y)) - tgp_vr_circrad); - next_fn(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + logerror("TGP col_testpt %f, %f (%x)\n", a, b, state->pushpc); + x = a - state->tgp_vr_circx; + y = b - state->tgp_vr_circy; + fifoout_push_f(state, ((x*x+y*y)/sqrt(x*x+y*y)) - state->tgp_vr_circrad); + next_fn(state); } static TGP_FUNCTION( push_and_ident ) { - if(mat_stack_pos != MAT_STACK_SIZE) { - memcpy(mat_stack[mat_stack_pos], cmat, sizeof(cmat)); - mat_stack_pos++; + model1_state *state = machine->driver_data(); + if(state->mat_stack_pos != MAT_STACK_SIZE) { + memcpy(state->mat_stack[state->mat_stack_pos], state->cmat, sizeof(state->cmat)); + state->mat_stack_pos++; } - logerror("TGP push_and_ident (depth=%d, pc=%x)\n", mat_stack_pos, pushpc); - memset(cmat, 0, sizeof(cmat)); - cmat[0] = 1.0; - cmat[4] = 1.0; - cmat[8] = 1.0; - next_fn(); + logerror("TGP push_and_ident (depth=%d, pc=%x)\n", state->mat_stack_pos, state->pushpc); + memset(state->cmat, 0, sizeof(state->cmat)); + state->cmat[0] = 1.0; + state->cmat[4] = 1.0; + state->cmat[8] = 1.0; + next_fn(state); } static TGP_FUNCTION( catmull_rom ) { - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - float c = fifoin_pop_f(); - float d = fifoin_pop_f(); - float e = fifoin_pop_f(); - float f = fifoin_pop_f(); - float g = fifoin_pop_f(); - float h = fifoin_pop_f(); - float i = fifoin_pop_f(); - float j = fifoin_pop_f(); - float k = fifoin_pop_f(); - float l = fifoin_pop_f(); - float m = fifoin_pop_f(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + float c = fifoin_pop_f(state); + float d = fifoin_pop_f(state); + float e = fifoin_pop_f(state); + float f = fifoin_pop_f(state); + float g = fifoin_pop_f(state); + float h = fifoin_pop_f(state); + float i = fifoin_pop_f(state); + float j = fifoin_pop_f(state); + float k = fifoin_pop_f(state); + float l = fifoin_pop_f(state); + float m = fifoin_pop_f(state); float m2, m3; float w1, w2, w3, w4; - logerror("TGP catmull_rom %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, m, pushpc); + logerror("TGP catmull_rom %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, m, state->pushpc); m2 = m*m; m3 = m*m*m; @@ -1190,61 +1226,64 @@ static TGP_FUNCTION( catmull_rom ) w3 = 0.5*(-3*m3+4*m2+m); w4 = 0.5*(m3-m2); - fifoout_push_f(a*w1+d*w2+g*w3+j*w4); - fifoout_push_f(b*w1+e*w2+h*w3+k*w4); - fifoout_push_f(c*w1+f*w2+i*w3+l*w4); - next_fn(); + fifoout_push_f(state, a*w1+d*w2+g*w3+j*w4); + fifoout_push_f(state, b*w1+e*w2+h*w3+k*w4); + fifoout_push_f(state, c*w1+f*w2+i*w3+l*w4); + next_fn(state); } static TGP_FUNCTION( distance ) { - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - float c = fifoin_pop_f(); - float d = fifoin_pop_f(); - logerror("TGP distance (%f, %f), (%f, %f) (%x)\n", a, b, c, d, pushpc); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + float c = fifoin_pop_f(state); + float d = fifoin_pop_f(state); + logerror("TGP distance (%f, %f), (%f, %f) (%x)\n", a, b, c, d, state->pushpc); c -= a; d -= b; - fifoout_push_f((c*c+d*d)/sqrt(c*c+d*d)); - next_fn(); + fifoout_push_f(state, (c*c+d*d)/sqrt(c*c+d*d)); + next_fn(state); } static TGP_FUNCTION( car_move ) { - INT16 a = fifoin_pop(); - float b = fifoin_pop_f(); - float c = fifoin_pop_f(); - float d = fifoin_pop_f(); + model1_state *state = machine->driver_data(); + INT16 a = fifoin_pop(state); + float b = fifoin_pop_f(state); + float c = fifoin_pop_f(state); + float d = fifoin_pop_f(state); float dx, dy; - logerror("TGP car_move (%d, %f), (%f, %f) (%x)\n", a, b, c, d, pushpc); + logerror("TGP car_move (%d, %f), (%f, %f) (%x)\n", a, b, c, d, state->pushpc); dx = b*tsin(a); dy = b*tcos(a); - fifoout_push_f(dx); - fifoout_push_f(dy); - fifoout_push_f(c+dx); - fifoout_push_f(d+dy); - next_fn(); + fifoout_push_f(state, dx); + fifoout_push_f(state, dy); + fifoout_push_f(state, c+dx); + fifoout_push_f(state, d+dy); + next_fn(state); } static TGP_FUNCTION( cpa ) { + model1_state *state = machine->driver_data(); float dv_x, dv_y, dv_z, dv2, dw_x, dw_y, dw_z, dt; - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - float c = fifoin_pop_f(); - float d = fifoin_pop_f(); - float e = fifoin_pop_f(); - float f = fifoin_pop_f(); - float g = fifoin_pop_f(); - float h = fifoin_pop_f(); - float i = fifoin_pop_f(); - float j = fifoin_pop_f(); - float k = fifoin_pop_f(); - float l = fifoin_pop_f(); - logerror("TGP cpa %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, pushpc); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + float c = fifoin_pop_f(state); + float d = fifoin_pop_f(state); + float e = fifoin_pop_f(state); + float f = fifoin_pop_f(state); + float g = fifoin_pop_f(state); + float h = fifoin_pop_f(state); + float i = fifoin_pop_f(state); + float j = fifoin_pop_f(state); + float k = fifoin_pop_f(state); + float l = fifoin_pop_f(state); + logerror("TGP cpa %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, state->pushpc); dv_x = (b-a) - (d-c); dv_y = (f-e) - (h-g); @@ -1268,353 +1307,377 @@ static TGP_FUNCTION( cpa ) dv_z = (i-k)*(1-dt) + (j-l)*dt; dv2 = dv_x*dv_x + dv_y*dv_y + dv_z*dv_z; - fifoout_push_f(sqrt(dv2)); - next_fn(); + fifoout_push_f(state, sqrt(dv2)); + next_fn(state); } static TGP_FUNCTION( vmat_store ) { - UINT32 a = fifoin_pop(); + model1_state *state = machine->driver_data(); + UINT32 a = fifoin_pop(state); if(a<21) - memcpy(mat_vector[a], cmat, sizeof(cmat)); + memcpy(state->mat_vector[a], state->cmat, sizeof(state->cmat)); else logerror("TGP ERROR bad vector index\n"); - logerror("TGP vmat_store %d (%x)\n", a, pushpc); - next_fn(); + logerror("TGP vmat_store %d (%x)\n", a, state->pushpc); + next_fn(state); } static TGP_FUNCTION( vmat_restore ) { - UINT32 a = fifoin_pop(); + model1_state *state = machine->driver_data(); + UINT32 a = fifoin_pop(state); if(a<21) - memcpy(cmat, mat_vector[a], sizeof(cmat)); + memcpy(state->cmat, state->mat_vector[a], sizeof(state->cmat)); else logerror("TGP ERROR bad vector index\n"); - logerror("TGP vmat_restore %d (%x)\n", a, pushpc); - next_fn(); + logerror("TGP vmat_restore %d (%x)\n", a, state->pushpc); + next_fn(state); } static TGP_FUNCTION( vmat_mul ) { - UINT32 a = fifoin_pop(); - UINT32 b = fifoin_pop(); + model1_state *state = machine->driver_data(); + UINT32 a = fifoin_pop(state); + UINT32 b = fifoin_pop(state); if(a<21 && b<21) { - mat_vector[b][0] = mat_vector[a][ 0]*cmat[0] + mat_vector[a][ 1]*cmat[3] + mat_vector[a][ 2]*cmat[6]; - mat_vector[b][1] = mat_vector[a][ 0]*cmat[1] + mat_vector[a][ 1]*cmat[4] + mat_vector[a][ 2]*cmat[7]; - mat_vector[b][2] = mat_vector[a][ 0]*cmat[2] + mat_vector[a][ 1]*cmat[5] + mat_vector[a][ 2]*cmat[8]; - mat_vector[b][3] = mat_vector[a][ 3]*cmat[0] + mat_vector[a][ 4]*cmat[3] + mat_vector[a][ 5]*cmat[6]; - mat_vector[b][4] = mat_vector[a][ 3]*cmat[1] + mat_vector[a][ 4]*cmat[4] + mat_vector[a][ 5]*cmat[7]; - mat_vector[b][5] = mat_vector[a][ 3]*cmat[2] + mat_vector[a][ 4]*cmat[5] + mat_vector[a][ 5]*cmat[8]; - mat_vector[b][6] = mat_vector[a][ 6]*cmat[0] + mat_vector[a][ 7]*cmat[3] + mat_vector[a][ 8]*cmat[6]; - mat_vector[b][7] = mat_vector[a][ 6]*cmat[1] + mat_vector[a][ 7]*cmat[4] + mat_vector[a][ 8]*cmat[7]; - mat_vector[b][8] = mat_vector[a][ 6]*cmat[2] + mat_vector[a][ 7]*cmat[5] + mat_vector[a][ 8]*cmat[8]; - mat_vector[b][9] = mat_vector[a][ 9]*cmat[0] + mat_vector[a][10]*cmat[3] + mat_vector[a][11]*cmat[6] + cmat[9]; - mat_vector[b][10] = mat_vector[a][ 9]*cmat[1] + mat_vector[a][10]*cmat[4] + mat_vector[a][11]*cmat[7] + cmat[10]; - mat_vector[b][11] = mat_vector[a][ 9]*cmat[2] + mat_vector[a][10]*cmat[5] + mat_vector[a][11]*cmat[8] + cmat[11]; + state->mat_vector[b][0] = state->mat_vector[a][ 0]*state->cmat[0] + state->mat_vector[a][ 1]*state->cmat[3] + state->mat_vector[a][ 2]*state->cmat[6]; + state->mat_vector[b][1] = state->mat_vector[a][ 0]*state->cmat[1] + state->mat_vector[a][ 1]*state->cmat[4] + state->mat_vector[a][ 2]*state->cmat[7]; + state->mat_vector[b][2] = state->mat_vector[a][ 0]*state->cmat[2] + state->mat_vector[a][ 1]*state->cmat[5] + state->mat_vector[a][ 2]*state->cmat[8]; + state->mat_vector[b][3] = state->mat_vector[a][ 3]*state->cmat[0] + state->mat_vector[a][ 4]*state->cmat[3] + state->mat_vector[a][ 5]*state->cmat[6]; + state->mat_vector[b][4] = state->mat_vector[a][ 3]*state->cmat[1] + state->mat_vector[a][ 4]*state->cmat[4] + state->mat_vector[a][ 5]*state->cmat[7]; + state->mat_vector[b][5] = state->mat_vector[a][ 3]*state->cmat[2] + state->mat_vector[a][ 4]*state->cmat[5] + state->mat_vector[a][ 5]*state->cmat[8]; + state->mat_vector[b][6] = state->mat_vector[a][ 6]*state->cmat[0] + state->mat_vector[a][ 7]*state->cmat[3] + state->mat_vector[a][ 8]*state->cmat[6]; + state->mat_vector[b][7] = state->mat_vector[a][ 6]*state->cmat[1] + state->mat_vector[a][ 7]*state->cmat[4] + state->mat_vector[a][ 8]*state->cmat[7]; + state->mat_vector[b][8] = state->mat_vector[a][ 6]*state->cmat[2] + state->mat_vector[a][ 7]*state->cmat[5] + state->mat_vector[a][ 8]*state->cmat[8]; + state->mat_vector[b][9] = state->mat_vector[a][ 9]*state->cmat[0] + state->mat_vector[a][10]*state->cmat[3] + state->mat_vector[a][11]*state->cmat[6] + state->cmat[9]; + state->mat_vector[b][10] = state->mat_vector[a][ 9]*state->cmat[1] + state->mat_vector[a][10]*state->cmat[4] + state->mat_vector[a][11]*state->cmat[7] + state->cmat[10]; + state->mat_vector[b][11] = state->mat_vector[a][ 9]*state->cmat[2] + state->mat_vector[a][10]*state->cmat[5] + state->mat_vector[a][11]*state->cmat[8] + state->cmat[11]; } else logerror("TGP ERROR bad vector index\n"); - logerror("TGP vmat_mul %d, %d (%x)\n", a, b, pushpc); - next_fn(); + logerror("TGP vmat_mul %d, %d (%x)\n", a, b, state->pushpc); + next_fn(state); } static TGP_FUNCTION( vmat_read ) { - UINT32 a = fifoin_pop(); - logerror("TGP vmat_read %d (%x)\n", a, pushpc); + model1_state *state = machine->driver_data(); + UINT32 a = fifoin_pop(state); + logerror("TGP vmat_read %d (%x)\n", a, state->pushpc); if(a<21) { int i; for(i=0; i<12; i++) - fifoout_push_f(mat_vector[a][i]); + fifoout_push_f(state, state->mat_vector[a][i]); } else { int i; logerror("TGP ERROR bad vector index\n"); for(i=0; i<12; i++) - fifoout_push_f(0); + fifoout_push_f(state, 0); } - next_fn(); + next_fn(state); } static TGP_FUNCTION( matrix_rtrans ) { - logerror("TGP matrix_rtrans (%x)\n", pushpc); - fifoout_push_f(cmat[ 9]); - fifoout_push_f(cmat[10]); - fifoout_push_f(cmat[11]); - next_fn(); + model1_state *state = machine->driver_data(); + logerror("TGP matrix_rtrans (%x)\n", state->pushpc); + fifoout_push_f(state, state->cmat[ 9]); + fifoout_push_f(state, state->cmat[10]); + fifoout_push_f(state, state->cmat[11]); + next_fn(state); } static TGP_FUNCTION( matrix_unrot ) { - logerror("TGP matrix_unrot (%x)\n", pushpc); - memset(cmat, 0, 9*sizeof(cmat[0])); - cmat[0] = 1.0; - cmat[4] = 1.0; - cmat[8] = 1.0; - next_fn(); + model1_state *state = machine->driver_data(); + logerror("TGP matrix_unrot (%x)\n", state->pushpc); + memset(state->cmat, 0, 9*sizeof(state->cmat[0])); + state->cmat[0] = 1.0; + state->cmat[4] = 1.0; + state->cmat[8] = 1.0; + next_fn(state); } static TGP_FUNCTION( f80 ) { - logerror("TGP f80 (%x)\n", pushpc); - // cmat[9] = cmat[10] = cmat[11] = 0; - next_fn(); + model1_state *state = machine->driver_data(); + logerror("TGP f80 (%x)\n", state->pushpc); + // state->cmat[9] = state->cmat[10] = state->cmat[11] = 0; + next_fn(state); } static TGP_FUNCTION( vmat_save ) { - UINT32 a = fifoin_pop(); + model1_state *state = machine->driver_data(); + UINT32 a = fifoin_pop(state); int i; - logerror("TGP vmat_save 0x%x (%x)\n", a, pushpc); + logerror("TGP vmat_save 0x%x (%x)\n", a, state->pushpc); for(i=0; i<16; i++) - memcpy(ram_data+a+0x10*i, mat_vector[i], sizeof(cmat)); - next_fn(); + memcpy(state->ram_data+a+0x10*i, state->mat_vector[i], sizeof(state->cmat)); + next_fn(state); } static TGP_FUNCTION( vmat_load ) { - UINT32 a = fifoin_pop(); + model1_state *state = machine->driver_data(); + UINT32 a = fifoin_pop(state); int i; - logerror("TGP vmat_load 0x%x (%x)\n", a, pushpc); + logerror("TGP vmat_load 0x%x (%x)\n", a, state->pushpc); for(i=0; i<16; i++) - memcpy(mat_vector[i], ram_data+a+0x10*i, sizeof(cmat)); - next_fn(); + memcpy(state->mat_vector[i], state->ram_data+a+0x10*i, sizeof(state->cmat)); + next_fn(state); } static TGP_FUNCTION( ram_setadr ) { - ram_scanadr = fifoin_pop() - 0x8000; - logerror("TGP f0 ram_setadr 0x%x (%x)\n", ram_scanadr+0x8000, pushpc); - next_fn(); + model1_state *state = machine->driver_data(); + state->ram_scanadr = fifoin_pop(state) - 0x8000; + logerror("TGP f0 ram_setadr 0x%x (%x)\n", state->ram_scanadr+0x8000, state->pushpc); + next_fn(state); } static TGP_FUNCTION( groundbox_test ) { + model1_state *state = machine->driver_data(); int out_x, out_y, out_z; float x, /*y,*/ z; - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - float c = fifoin_pop_f(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + float c = fifoin_pop_f(state); - logerror("TGP groundbox_test %f, %f, %f (%x)\n", a, b, c, pushpc); - x = cmat[0]*a+cmat[3]*b+cmat[6]*c+cmat[9]; - //y = cmat[1]*a+cmat[4]*b+cmat[7]*c+cmat[10]; - z = cmat[2]*a+cmat[5]*b+cmat[8]*c+cmat[11]; + logerror("TGP groundbox_test %f, %f, %f (%x)\n", a, b, c, state->pushpc); + x = state->cmat[0]*a+state->cmat[3]*b+state->cmat[6]*c+state->cmat[9]; + //y = state->cmat[1]*a+state->cmat[4]*b+state->cmat[7]*c+state->cmat[10]; + z = state->cmat[2]*a+state->cmat[5]*b+state->cmat[8]*c+state->cmat[11]; - out_x = x < tgp_vf_xmin || x > tgp_vf_xmax; - out_z = z < tgp_vf_zmin || z > tgp_vf_zmax; + out_x = x < state->tgp_vf_xmin || x > state->tgp_vf_xmax; + out_z = z < state->tgp_vf_zmin || z > state->tgp_vf_zmax; out_y = 1; // Wrong, but untestable it seems. - fifoout_push(out_x); - fifoout_push(out_y); - fifoout_push(out_z); - next_fn(); + fifoout_push(state, out_x); + fifoout_push(state, out_y); + fifoout_push(state, out_z); + next_fn(state); } static TGP_FUNCTION( f89 ) { - UINT32 a = fifoin_pop(); - UINT32 b = fifoin_pop(); - UINT32 c = fifoin_pop(); - UINT32 d = fifoin_pop(); + model1_state *state = machine->driver_data(); + UINT32 a = fifoin_pop(state); + UINT32 b = fifoin_pop(state); + UINT32 c = fifoin_pop(state); + UINT32 d = fifoin_pop(state); (void)a; (void)b; (void)c; - logerror("TGP list set base 0x%x, 0x%x, %d, length=%d (%x)\n", a, b, c, d, pushpc); - list_length = d; - next_fn(); + logerror("TGP list set base 0x%x, 0x%x, %d, length=%d (%x)\n", a, b, c, d, state->pushpc); + state->list_length = d; + next_fn(state); } static TGP_FUNCTION( f92 ) { - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - float c = fifoin_pop_f(); - float d = fifoin_pop_f(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + float c = fifoin_pop_f(state); + float d = fifoin_pop_f(state); (void)a; (void)b; (void)c; (void)d; - logerror("TGP f92 %f, %f, %f, %f (%x)\n", a, b, c, d, pushpc); - next_fn(); + logerror("TGP f92 %f, %f, %f, %f (%x)\n", a, b, c, d, state->pushpc); + next_fn(state); } static TGP_FUNCTION( f93 ) { - float a = fifoin_pop_f(); + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); (void)a; - logerror("TGP f93 %f (%x)\n", a, pushpc); - next_fn(); + logerror("TGP f93 %f (%x)\n", a, state->pushpc); + next_fn(state); } static TGP_FUNCTION( f94 ) { - UINT32 a = fifoin_pop(); + model1_state *state = machine->driver_data(); + UINT32 a = fifoin_pop(state); (void)a; - logerror("TGP f94 %d (%x)\n", a, pushpc); - next_fn(); + logerror("TGP f94 %d (%x)\n", a, state->pushpc); + next_fn(state); } static TGP_FUNCTION( vmat_flatten ) { + model1_state *state = machine->driver_data(); int i; float m[12]; - logerror("TGP vmat_flatten (%x)\n", pushpc); + logerror("TGP vmat_flatten (%x)\n", state->pushpc); for(i=0; i<16; i++) { - memcpy(m, mat_vector[i], sizeof(cmat)); + memcpy(m, state->mat_vector[i], sizeof(state->cmat)); m[1] = m[4] = m[7] = m[10] = 0; - mat_vector[i][0] = m[ 0]*cmat[0] + m[ 1]*cmat[3] + m[ 2]*cmat[6]; - mat_vector[i][1] = m[ 0]*cmat[1] + m[ 1]*cmat[4] + m[ 2]*cmat[7]; - mat_vector[i][2] = m[ 0]*cmat[2] + m[ 1]*cmat[5] + m[ 2]*cmat[8]; - mat_vector[i][3] = m[ 3]*cmat[0] + m[ 4]*cmat[3] + m[ 5]*cmat[6]; - mat_vector[i][4] = m[ 3]*cmat[1] + m[ 4]*cmat[4] + m[ 5]*cmat[7]; - mat_vector[i][5] = m[ 3]*cmat[2] + m[ 4]*cmat[5] + m[ 5]*cmat[8]; - mat_vector[i][6] = m[ 6]*cmat[0] + m[ 7]*cmat[3] + m[ 8]*cmat[6]; - mat_vector[i][7] = m[ 6]*cmat[1] + m[ 7]*cmat[4] + m[ 8]*cmat[7]; - mat_vector[i][8] = m[ 6]*cmat[2] + m[ 7]*cmat[5] + m[ 8]*cmat[8]; - mat_vector[i][9] = m[ 9]*cmat[0] + m[10]*cmat[3] + m[11]*cmat[6] + cmat[9]; - mat_vector[i][10] = m[ 9]*cmat[1] + m[10]*cmat[4] + m[11]*cmat[7] + cmat[10]; - mat_vector[i][11] = m[ 9]*cmat[2] + m[10]*cmat[5] + m[11]*cmat[8] + cmat[11]; + state->mat_vector[i][0] = m[ 0]*state->cmat[0] + m[ 1]*state->cmat[3] + m[ 2]*state->cmat[6]; + state->mat_vector[i][1] = m[ 0]*state->cmat[1] + m[ 1]*state->cmat[4] + m[ 2]*state->cmat[7]; + state->mat_vector[i][2] = m[ 0]*state->cmat[2] + m[ 1]*state->cmat[5] + m[ 2]*state->cmat[8]; + state->mat_vector[i][3] = m[ 3]*state->cmat[0] + m[ 4]*state->cmat[3] + m[ 5]*state->cmat[6]; + state->mat_vector[i][4] = m[ 3]*state->cmat[1] + m[ 4]*state->cmat[4] + m[ 5]*state->cmat[7]; + state->mat_vector[i][5] = m[ 3]*state->cmat[2] + m[ 4]*state->cmat[5] + m[ 5]*state->cmat[8]; + state->mat_vector[i][6] = m[ 6]*state->cmat[0] + m[ 7]*state->cmat[3] + m[ 8]*state->cmat[6]; + state->mat_vector[i][7] = m[ 6]*state->cmat[1] + m[ 7]*state->cmat[4] + m[ 8]*state->cmat[7]; + state->mat_vector[i][8] = m[ 6]*state->cmat[2] + m[ 7]*state->cmat[5] + m[ 8]*state->cmat[8]; + state->mat_vector[i][9] = m[ 9]*state->cmat[0] + m[10]*state->cmat[3] + m[11]*state->cmat[6] + state->cmat[9]; + state->mat_vector[i][10] = m[ 9]*state->cmat[1] + m[10]*state->cmat[4] + m[11]*state->cmat[7] + state->cmat[10]; + state->mat_vector[i][11] = m[ 9]*state->cmat[2] + m[10]*state->cmat[5] + m[11]*state->cmat[8] + state->cmat[11]; } - next_fn(); + next_fn(state); } static TGP_FUNCTION( vmat_load1 ) { - UINT32 a = fifoin_pop(); - logerror("TGP vmat_load1 0x%x (%x)\n", a, pushpc); - memcpy(cmat, ram_data+a, sizeof(cmat)); - next_fn(); + model1_state *state = machine->driver_data(); + UINT32 a = fifoin_pop(state); + logerror("TGP vmat_load1 0x%x (%x)\n", a, state->pushpc); + memcpy(state->cmat, state->ram_data+a, sizeof(state->cmat)); + next_fn(state); } static TGP_FUNCTION( ram_trans ) { - float a = ram_get_f(); - float b = ram_get_f(); - float c = ram_get_f(); - logerror("TGP ram_trans (%x)\n", pushpc); - cmat[ 9] += cmat[0]*a+cmat[3]*b+cmat[6]*c; - cmat[10] += cmat[1]*a+cmat[4]*b+cmat[7]*c; - cmat[11] += cmat[2]*a+cmat[5]*b+cmat[8]*c; - next_fn(); + model1_state *state = machine->driver_data(); + float a = ram_get_f(state); + float b = ram_get_f(state); + float c = ram_get_f(state); + logerror("TGP ram_trans (%x)\n", state->pushpc); + state->cmat[ 9] += state->cmat[0]*a+state->cmat[3]*b+state->cmat[6]*c; + state->cmat[10] += state->cmat[1]*a+state->cmat[4]*b+state->cmat[7]*c; + state->cmat[11] += state->cmat[2]*a+state->cmat[5]*b+state->cmat[8]*c; + next_fn(state); } static TGP_FUNCTION( f98_load ) { + model1_state *state = machine->driver_data(); int i; - for(i=0; ilist_length; i++) { + float f = fifoin_pop_f(state); (void)f; - logerror("TGP load list (%2d/%2d) %f (%x)\n", i, list_length, f, pushpc); + logerror("TGP load list (%2d/%2d) %f (%x)\n", i, state->list_length, f, state->pushpc); } - next_fn(); + next_fn(state); } static TGP_FUNCTION( f98 ) { - UINT32 a = fifoin_pop(); + model1_state *state = machine->driver_data(); + UINT32 a = fifoin_pop(state); (void)a; - logerror("TGP load list start %d (%x)\n", a, pushpc); - fifoin_cbcount = list_length; - fifoin_cb = f98_load; + logerror("TGP load list start %d (%x)\n", a, state->pushpc); + state->fifoin_cbcount = state->list_length; + state->fifoin_cb = f98_load; } static TGP_FUNCTION( f99 ) { - logerror("TGP f99 (%x)\n", pushpc); - next_fn(); + model1_state *state = machine->driver_data(); + logerror("TGP f99 (%x)\n", state->pushpc); + next_fn(state); } static TGP_FUNCTION( f100 ) { + model1_state *state = machine->driver_data(); int i; - logerror("TGP f100 get list (%x)\n", pushpc); - for(i=0; irand() % 1000)/100.0); - next_fn(); + logerror("TGP f100 get list (%x)\n", state->pushpc); + for(i=0; ilist_length; i++) + fifoout_push_f(state, (machine->rand() % 1000)/100.0); + next_fn(state); } static TGP_FUNCTION( groundbox_set ) { - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - float c = fifoin_pop_f(); - float d = fifoin_pop_f(); - float e = fifoin_pop_f(); - float f = fifoin_pop_f(); - float g = fifoin_pop_f(); - logerror("TGP groundbox_set %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, pushpc); - tgp_vf_xmin = e; - tgp_vf_xmax = d; - tgp_vf_zmin = g; - tgp_vf_zmax = f; - tgp_vf_ygnd = b; - tgp_vf_yflr = a; - tgp_vf_yjmp = c; + model1_state *state = machine->driver_data(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + float c = fifoin_pop_f(state); + float d = fifoin_pop_f(state); + float e = fifoin_pop_f(state); + float f = fifoin_pop_f(state); + float g = fifoin_pop_f(state); + logerror("TGP groundbox_set %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, state->pushpc); + state->tgp_vf_xmin = e; + state->tgp_vf_xmax = d; + state->tgp_vf_zmin = g; + state->tgp_vf_zmax = f; + state->tgp_vf_ygnd = b; + state->tgp_vf_yflr = a; + state->tgp_vf_yjmp = c; - next_fn(); + next_fn(state); } static TGP_FUNCTION( f102 ) { - static int ccount = 0; + model1_state *state = machine->driver_data(); float px, py, pz; - float a = fifoin_pop_f(); - float b = fifoin_pop_f(); - float c = fifoin_pop_f(); - float d = fifoin_pop_f(); - float e = fifoin_pop_f(); - UINT32 f = fifoin_pop(); - UINT32 g = fifoin_pop(); - UINT32 h = fifoin_pop(); + float a = fifoin_pop_f(state); + float b = fifoin_pop_f(state); + float c = fifoin_pop_f(state); + float d = fifoin_pop_f(state); + float e = fifoin_pop_f(state); + UINT32 f = fifoin_pop(state); + UINT32 g = fifoin_pop(state); + UINT32 h = fifoin_pop(state); - ccount++; + state->ccount++; - logerror("TGP f0 mve_calc %f, %f, %f, %f, %f, %d, %d, %d (%d) (%x)\n", a, b, c, d, e, f, g, h, ccount, pushpc); + logerror("TGP f0 mve_calc %f, %f, %f, %f, %f, %d, %d, %d (%d) (%x)\n", a, b, c, d, e, f, g, h, state->ccount, state->pushpc); - px = u2f(ram_data[ram_scanadr+0x16]); - py = u2f(ram_data[ram_scanadr+0x17]); - pz = u2f(ram_data[ram_scanadr+0x18]); + px = u2f(state->ram_data[state->ram_scanadr+0x16]); + py = u2f(state->ram_data[state->ram_scanadr+0x17]); + pz = u2f(state->ram_data[state->ram_scanadr+0x18]); - // memset(cmat, 0, sizeof(cmat)); - // cmat[0] = 1.0; - // cmat[4] = 1.0; - // cmat[8] = 1.0; + // memset(state->cmat, 0, sizeof(state->cmat)); + // state->cmat[0] = 1.0; + // state->cmat[4] = 1.0; + // state->cmat[8] = 1.0; px = c; py = d; pz = e; #if 1 - cmat[ 9] += cmat[0]*a+cmat[3]*b+cmat[6]*c; - cmat[10] += cmat[1]*a+cmat[4]*b+cmat[7]*c; - cmat[11] += cmat[2]*a+cmat[5]*b+cmat[8]*c; + state->cmat[ 9] += state->cmat[0]*a+state->cmat[3]*b+state->cmat[6]*c; + state->cmat[10] += state->cmat[1]*a+state->cmat[4]*b+state->cmat[7]*c; + state->cmat[11] += state->cmat[2]*a+state->cmat[5]*b+state->cmat[8]*c; #else - cmat[ 9] += px; - cmat[10] += py; - cmat[11] += pz; + state->cmat[ 9] += px; + state->cmat[10] += py; + state->cmat[11] += pz; #endif logerror(" f0 mve_calc %f, %f, %f\n", px, py, pz); - fifoout_push_f(c); - fifoout_push_f(d); - fifoout_push_f(e); - fifoout_push(f); - fifoout_push(g); - fifoout_push(h); + fifoout_push_f(state, c); + fifoout_push_f(state, d); + fifoout_push_f(state, e); + fifoout_push(state, f); + fifoout_push(state, g); + fifoout_push(state, h); - next_fn(); + next_fn(state); } static TGP_FUNCTION( f103 ) { - ram_scanadr = fifoin_pop() - 0x8000; - logerror("TGP f0 mve_setadr 0x%x (%x)\n", ram_scanadr, pushpc); - ram_get_i(); - next_fn(); + model1_state *state = machine->driver_data(); + state->ram_scanadr = fifoin_pop(state) - 0x8000; + logerror("TGP f0 mve_setadr 0x%x (%x)\n", state->ram_scanadr, state->pushpc); + ram_get_i(state); + next_fn(state); } struct function { @@ -1818,192 +1881,197 @@ static const struct function ftab_swa[] = { static TGP_FUNCTION( dump ) { - logerror("TGP FIFOIN write %08x (%x)\n", fifoin_pop(), pushpc); - fifoin_cbcount = 1; - fifoin_cb = dump; + model1_state *state = machine->driver_data(); + logerror("TGP FIFOIN write %08x (%x)\n", fifoin_pop(state), state->pushpc); + state->fifoin_cbcount = 1; + state->fifoin_cb = dump; } static TGP_FUNCTION( function_get_vf ) { - UINT32 f = fifoin_pop() >> 23; + model1_state *state = machine->driver_data(); + UINT32 f = fifoin_pop(state) >> 23; - if(fifoout_rpos != fifoout_wpos) { - int count = fifoout_wpos - fifoout_rpos; + if(state->fifoout_rpos != state->fifoout_wpos) { + int count = state->fifoout_wpos - state->fifoout_rpos; if(count < 0) count += FIFO_SIZE; logerror("TGP function called with sizeout = %d\n", count); } if(ARRAY_LENGTH(ftab_vf) > f && NULL != ftab_vf[f].cb) { - fifoin_cbcount = ftab_vf[f].count; - fifoin_cb = ftab_vf[f].cb; - // logerror("TGP function %d request, %d parameters\n", f, fifoin_cbcount); - if(!fifoin_cbcount) - fifoin_cb(machine); + state->fifoin_cbcount = ftab_vf[f].count; + state->fifoin_cb = ftab_vf[f].cb; + // logerror("TGP function %d request, %d parameters\n", f, state->fifoin_cbcount); + if(!state->fifoin_cbcount) + state->fifoin_cb(machine); } else { - logerror("TGP function %d unimplemented (%x)\n", f, pushpc); - fifoin_cbcount = 1; - fifoin_cb = dump; + logerror("TGP function %d unimplemented (%x)\n", f, state->pushpc); + state->fifoin_cbcount = 1; + state->fifoin_cb = dump; } } static TGP_FUNCTION( function_get_swa ) { - UINT32 f = fifoin_pop(); + model1_state *state = machine->driver_data(); + UINT32 f = fifoin_pop(state); - if(fifoout_rpos != fifoout_wpos) { - int count = fifoout_wpos - fifoout_rpos; + if(state->fifoout_rpos != state->fifoout_wpos) { + int count = state->fifoout_wpos - state->fifoout_rpos; if(count < 0) count += FIFO_SIZE; logerror("TGP function called with sizeout = %d\n", count); } if(ARRAY_LENGTH(ftab_swa) > f && NULL != ftab_swa[f].cb) { - fifoin_cbcount = ftab_swa[f].count; - fifoin_cb = ftab_swa[f].cb; - // logerror("TGP function %d request, %d parameters\n", f, fifoin_cbcount); - if(!fifoin_cbcount) - fifoin_cb(machine); + state->fifoin_cbcount = ftab_swa[f].count; + state->fifoin_cb = ftab_swa[f].cb; + // logerror("TGP function %d request, %d parameters\n", f, state->fifoin_cbcount); + if(!state->fifoin_cbcount) + state->fifoin_cb(machine); } else { - logerror("TGP function %d unimplemented (%x)\n", f, pushpc); - fifoin_cbcount = 1; - fifoin_cb = dump; + logerror("TGP function %d unimplemented (%x)\n", f, state->pushpc); + state->fifoin_cbcount = 1; + state->fifoin_cb = dump; } } READ16_HANDLER( model1_tgp_copro_r ) { - static UINT32 cur; + model1_state *state = space->machine->driver_data(); if(!offset) { - cur = fifoout_pop(space); - return cur; + state->copro_r = fifoout_pop(space); + return state->copro_r; } else - return cur >> 16; + return state->copro_r >> 16; } WRITE16_HANDLER( model1_tgp_copro_w ) { - static UINT32 cur; + model1_state *state = space->machine->driver_data(); if(offset) { - cur = (cur & 0x0000ffff) | (data << 16); - pushpc = cpu_get_pc(space->cpu); - fifoin_push(space, cur); + state->copro_w = (state->copro_w & 0x0000ffff) | (data << 16); + state->pushpc = cpu_get_pc(space->cpu); + fifoin_push(space, state->copro_w); } else - cur = (cur & 0xffff0000) | data; + state->copro_w = (state->copro_w & 0xffff0000) | data; } READ16_HANDLER( model1_tgp_copro_adr_r ) { - return ram_adr; + model1_state *state = space->machine->driver_data(); + return state->ram_adr; } WRITE16_HANDLER( model1_tgp_copro_adr_w ) { - COMBINE_DATA(&ram_adr); + model1_state *state = space->machine->driver_data(); + COMBINE_DATA(&state->ram_adr); } READ16_HANDLER( model1_tgp_copro_ram_r ) { + model1_state *state = space->machine->driver_data(); if(!offset) { - logerror("TGP f0 ram read %04x, %08x (%f) (%x)\n", ram_adr, ram_data[ram_adr], u2f(ram_data[ram_adr]), cpu_get_pc(space->cpu)); - return ram_data[ram_adr]; + logerror("TGP f0 ram read %04x, %08x (%f) (%x)\n", state->ram_adr, state->ram_data[state->ram_adr], u2f(state->ram_data[state->ram_adr]), cpu_get_pc(space->cpu)); + return state->ram_data[state->ram_adr]; } else - return ram_data[ram_adr++] >> 16; + return state->ram_data[state->ram_adr++] >> 16; } WRITE16_HANDLER( model1_tgp_copro_ram_w ) { - COMBINE_DATA(ram_latch+offset); + model1_state *state = space->machine->driver_data(); + COMBINE_DATA(state->ram_latch+offset); if(offset) { - UINT32 v = ram_latch[0]|(ram_latch[1]<<16); - logerror("TGP f0 ram write %04x, %08x (%f) (%x)\n", ram_adr, v, u2f(v), cpu_get_pc(space->cpu)); - ram_data[ram_adr] = v; - ram_adr++; + UINT32 v = state->ram_latch[0]|(state->ram_latch[1]<<16); + logerror("TGP f0 ram write %04x, %08x (%f) (%x)\n", state->ram_adr, v, u2f(v), cpu_get_pc(space->cpu)); + state->ram_data[state->ram_adr] = v; + state->ram_adr++; } } MACHINE_START( model1 ) { - ram_data = auto_alloc_array(machine, UINT32, 0x10000); + model1_state *state = machine->driver_data(); + state->ram_data = auto_alloc_array(machine, UINT32, 0x10000); - state_save_register_global_pointer(machine, ram_data, 0x10000); - state_save_register_global(machine, ram_adr); - state_save_register_global(machine, ram_scanadr); - state_save_register_global_array(machine, ram_latch); - state_save_register_global(machine, fifoout_rpos); - state_save_register_global(machine, fifoout_wpos); - state_save_register_global_array(machine, fifoout_data); - state_save_register_global(machine, fifoin_rpos); - state_save_register_global(machine, fifoin_wpos); - state_save_register_global_array(machine, fifoin_data); - state_save_register_global_array(machine, cmat); - state_save_register_global_2d_array(machine, mat_stack); - state_save_register_global_2d_array(machine, mat_vector); - state_save_register_global(machine, mat_stack_pos); - state_save_register_global(machine, acc); - state_save_register_global(machine, list_length); + state_save_register_global_pointer(machine, state->ram_data, 0x10000); + state_save_register_global(machine, state->ram_adr); + state_save_register_global(machine, state->ram_scanadr); + state_save_register_global_array(machine, state->ram_latch); + state_save_register_global(machine, state->fifoout_rpos); + state_save_register_global(machine, state->fifoout_wpos); + state_save_register_global_array(machine, state->fifoout_data); + state_save_register_global(machine, state->fifoin_rpos); + state_save_register_global(machine, state->fifoin_wpos); + state_save_register_global_array(machine, state->fifoin_data); + state_save_register_global_array(machine, state->cmat); + state_save_register_global_2d_array(machine, state->mat_stack); + state_save_register_global_2d_array(machine, state->mat_vector); + state_save_register_global(machine, state->mat_stack_pos); + state_save_register_global(machine, state->acc); + state_save_register_global(machine, state->list_length); } void model1_tgp_reset(running_machine *machine, int swa) { - ram_adr = 0; - memset(ram_data, 0, 0x10000*4); + model1_state *state = machine->driver_data(); + state->ram_adr = 0; + memset(state->ram_data, 0, 0x10000*4); - fifoout_rpos = 0; - fifoout_wpos = 0; - fifoin_rpos = 0; - fifoin_wpos = 0; + state->fifoout_rpos = 0; + state->fifoout_wpos = 0; + state->fifoin_rpos = 0; + state->fifoin_wpos = 0; - acc = 0; - mat_stack_pos = 0; - memset(cmat, 0, sizeof(cmat)); - cmat[0] = 1.0; - cmat[4] = 1.0; - cmat[8] = 1.0; + state->acc = 0; + state->mat_stack_pos = 0; + memset(state->cmat, 0, sizeof(state->cmat)); + state->cmat[0] = 1.0; + state->cmat[4] = 1.0; + state->cmat[8] = 1.0; - model1_dump = 0; - model1_swa = swa; - next_fn(); + state->dump = 0; + state->swa = swa; + next_fn(state); } /*********************************** Virtua Racing ***********************************/ -static int copro_fifoout_rpos, copro_fifoout_wpos; -static UINT32 copro_fifoout_data[FIFO_SIZE]; -static int copro_fifoout_num; -static int copro_fifoin_rpos, copro_fifoin_wpos; -static UINT32 copro_fifoin_data[FIFO_SIZE]; -static int copro_fifoin_num; void model1_vr_tgp_reset( running_machine *machine ) { - ram_adr = 0; - memset(ram_data, 0, 0x8000*4); + model1_state *state = machine->driver_data(); + state->ram_adr = 0; + memset(state->ram_data, 0, 0x8000*4); - copro_fifoout_rpos = 0; - copro_fifoout_wpos = 0; - copro_fifoout_num = 0; - copro_fifoin_rpos = 0; - copro_fifoin_wpos = 0; - copro_fifoin_num = 0; + state->copro_fifoout_rpos = 0; + state->copro_fifoout_wpos = 0; + state->copro_fifoout_num = 0; + state->copro_fifoin_rpos = 0; + state->copro_fifoin_wpos = 0; + state->copro_fifoin_num = 0; } /* FIFO */ static int copro_fifoin_pop(device_t *device, UINT32 *result) { + model1_state *state = device->machine->driver_data(); UINT32 r; - if (copro_fifoin_num == 0) + if (state->copro_fifoin_num == 0) { return 0; } - r = copro_fifoin_data[copro_fifoin_rpos++]; + r = state->copro_fifoin_data[state->copro_fifoin_rpos++]; - if (copro_fifoin_rpos == FIFO_SIZE) + if (state->copro_fifoin_rpos == FIFO_SIZE) { - copro_fifoin_rpos = 0; + state->copro_fifoin_rpos = 0; } - copro_fifoin_num--; + state->copro_fifoin_num--; *result = r; @@ -2012,27 +2080,29 @@ static int copro_fifoin_pop(device_t *device, UINT32 *result) static void copro_fifoin_push(address_space *space, UINT32 data) { - if (copro_fifoin_num == FIFO_SIZE) + model1_state *state = space->machine->driver_data(); + if (state->copro_fifoin_num == FIFO_SIZE) { fatalerror("Copro FIFOIN overflow (at %08X)", cpu_get_pc(space->cpu)); return; } - copro_fifoin_data[copro_fifoin_wpos++] = data; + state->copro_fifoin_data[state->copro_fifoin_wpos++] = data; - if (copro_fifoin_wpos == FIFO_SIZE) + if (state->copro_fifoin_wpos == FIFO_SIZE) { - copro_fifoin_wpos = 0; + state->copro_fifoin_wpos = 0; } - copro_fifoin_num++; + state->copro_fifoin_num++; } static UINT32 copro_fifoout_pop(address_space *space) { + model1_state *state = space->machine->driver_data(); UINT32 r; - if (copro_fifoout_num == 0) + if (state->copro_fifoout_num == 0) { // Reading from empty FIFO causes the v60 to enter wait state v60_stall(space->machine->device("maincpu")); @@ -2042,82 +2112,88 @@ static UINT32 copro_fifoout_pop(address_space *space) return 0; } - r = copro_fifoout_data[copro_fifoout_rpos++]; + r = state->copro_fifoout_data[state->copro_fifoout_rpos++]; - if (copro_fifoout_rpos == FIFO_SIZE) + if (state->copro_fifoout_rpos == FIFO_SIZE) { - copro_fifoout_rpos = 0; + state->copro_fifoout_rpos = 0; } - copro_fifoout_num--; + state->copro_fifoout_num--; return r; } static void copro_fifoout_push(device_t *device, UINT32 data) { - if (copro_fifoout_num == FIFO_SIZE) + model1_state *state = device->machine->driver_data(); + if (state->copro_fifoout_num == FIFO_SIZE) { fatalerror("Copro FIFOOUT overflow (at %08X)", cpu_get_pc(device)); return; } - copro_fifoout_data[copro_fifoout_wpos++] = data; + state->copro_fifoout_data[state->copro_fifoout_wpos++] = data; - if (copro_fifoout_wpos == FIFO_SIZE) + if (state->copro_fifoout_wpos == FIFO_SIZE) { - copro_fifoout_wpos = 0; + state->copro_fifoout_wpos = 0; } - copro_fifoout_num++; + state->copro_fifoout_num++; } static READ32_HANDLER(copro_ram_r) { - return ram_data[offset & 0x7fff]; + model1_state *state = space->machine->driver_data(); + return state->ram_data[offset & 0x7fff]; } static WRITE32_HANDLER(copro_ram_w) { - ram_data[offset&0x7fff] = data; + model1_state *state = space->machine->driver_data(); + state->ram_data[offset&0x7fff] = data; } READ16_HANDLER( model1_tgp_vr_adr_r ) { - if ( ram_adr == 0 && copro_fifoin_num != 0 ) + model1_state *state = space->machine->driver_data(); + if ( state->ram_adr == 0 && state->copro_fifoin_num != 0 ) { /* spin the main cpu and let the TGP catch up */ cpu_spinuntil_time(space->cpu, attotime::from_usec(100)); } - return ram_adr; + return state->ram_adr; } WRITE16_HANDLER( model1_tgp_vr_adr_w ) { - COMBINE_DATA(&ram_adr); + model1_state *state = space->machine->driver_data(); + COMBINE_DATA(&state->ram_adr); } READ16_HANDLER( model1_vr_tgp_ram_r ) { + model1_state *state = space->machine->driver_data(); UINT16 r; if (!offset) { - r = ram_data[ram_adr&0x7fff]; + r = state->ram_data[state->ram_adr&0x7fff]; } else { - r = ram_data[ram_adr&0x7fff] >> 16; + r = state->ram_data[state->ram_adr&0x7fff] >> 16; - if ( ram_adr == 0 && r == 0xffff ) + if ( state->ram_adr == 0 && r == 0xffff ) { /* if the TGP is busy, spin some more */ cpu_spinuntil_time(space->cpu, attotime::from_usec(100)); } - if ( ram_adr & 0x8000 ) - ram_adr++; + if ( state->ram_adr & 0x8000 ) + state->ram_adr++; } return r; @@ -2125,41 +2201,40 @@ READ16_HANDLER( model1_vr_tgp_ram_r ) WRITE16_HANDLER( model1_vr_tgp_ram_w ) { - COMBINE_DATA(ram_latch+offset); + model1_state *state = space->machine->driver_data(); + COMBINE_DATA(state->ram_latch+offset); if (offset) { - UINT32 v = ram_latch[0]|(ram_latch[1]<<16); - ram_data[ram_adr&0x7fff] = v; - if ( ram_adr & 0x8000 ) - ram_adr++; + UINT32 v = state->ram_latch[0]|(state->ram_latch[1]<<16); + state->ram_data[state->ram_adr&0x7fff] = v; + if ( state->ram_adr & 0x8000 ) + state->ram_adr++; } } READ16_HANDLER( model1_vr_tgp_r ) { - static UINT32 cur; - + model1_state *state = space->machine->driver_data(); if (!offset) { - cur = copro_fifoout_pop(space); - return cur; + state->vr_r = copro_fifoout_pop(space); + return state->vr_r; } else - return cur >> 16; + return state->vr_r >> 16; } WRITE16_HANDLER( model1_vr_tgp_w ) { - static UINT32 cur; - + model1_state *state = space->machine->driver_data(); if (offset) { - cur = (cur & 0x0000ffff) | (data << 16); - copro_fifoin_push(space, cur); + state->vr_w = (state->vr_w & 0x0000ffff) | (data << 16); + copro_fifoin_push(space, state->vr_w); } else - cur = (cur & 0xffff0000) | data; + state->vr_w = (state->vr_w & 0xffff0000) | data; } /* TGP config */ diff --git a/src/mame/machine/model3.c b/src/mame/machine/model3.c index 67c198a7d8c..c8692331d3a 100644 --- a/src/mame/machine/model3.c +++ b/src/mame/machine/model3.c @@ -7,7 +7,6 @@ #include "emu.h" #include "includes/model3.h" -static int m3_step; /******************************************************************/ /* Real3D TAP Port */ @@ -20,9 +19,8 @@ static int m3_step; * 167 of the 3D-RAM manual. */ -#define NEXT(new_state) fsm[state][new_state] +#define NEXT(new_state) fsm[state->tap_state][new_state] -static INT32 state; // current state static const INT32 fsm[][2] = { { 1, 0 }, // 0 Test-Logic/Reset { 1, 2 }, // 1 Run-Test/Idle @@ -42,18 +40,6 @@ static const INT32 fsm[][2] = { { 1, 2 } // 15 Update-IR }; -/* - * TAP Registers - */ - -static UINT64 current_instruction; // latched IR (not always equal to IR) -static UINT64 ir; // instruction register (46 bits) - -static UINT8 id_data[32]; // ASIC ID code data buffer -static INT32 id_size; // size of ID data in bits -//static INT32 ptr; // current bit ptr for data - -static int tdo; // bit shifted out to TDO /* * insert_bit(): @@ -78,12 +64,12 @@ static void insert_bit(UINT8 *buf, INT32 bit_num, INT32 bit) * Inserts a 32-bit ID code into the ID bit field. */ -static void insert_id(UINT32 id, INT32 start_bit) +static void insert_id(model3_state *state, UINT32 id, INT32 start_bit) { INT32 i; for (i = 31; i >= 0; i--) - insert_bit(id_data, start_bit++, (id >> i) & 1); + insert_bit(state->id_data, start_bit++, (id >> i) & 1); } /* @@ -136,9 +122,10 @@ static int shift(UINT8 *data, INT32 num_bits) * TDO. */ -int model3_tap_read(void) +int model3_tap_read(running_machine *machine) { - return tdo; + model3_state *state = machine->driver_data(); + return state->tdo; } /* @@ -154,14 +141,15 @@ int model3_tap_read(void) * trst = Reset. */ -void model3_tap_write(int tck, int tms, int tdi, int trst) +void model3_tap_write(running_machine *machine, int tck, int tms, int tdi, int trst) { + model3_state *state = machine->driver_data(); if (!tck) return; - state = NEXT(tms); + state->tap_state = NEXT(tms); - switch (state) + switch (state->tap_state) { case 3: // Capture-DR @@ -187,39 +175,39 @@ void model3_tap_write(int tck, int tms, int tdi, int trst) * data on TAP reset and when the instruction is issued. */ - if (m3_step == 0x10) + if (state->m3_step == 0x10) { - insert_id(0x116C7057, 1 + 0 * 32); - insert_id(0x216C3057, 1 + 1 * 32); - insert_id(0x116C4057, 1 + 2 * 32); - insert_id(0x216C5057, 1 + 3 * 32); - insert_id(0x116C6057, 1 + 4 * 32 + 1); - insert_id(0x116C6057, 1 + 5 * 32 + 1); + insert_id(state, 0x116C7057, 1 + 0 * 32); + insert_id(state, 0x216C3057, 1 + 1 * 32); + insert_id(state, 0x116C4057, 1 + 2 * 32); + insert_id(state, 0x216C5057, 1 + 3 * 32); + insert_id(state, 0x116C6057, 1 + 4 * 32 + 1); + insert_id(state, 0x116C6057, 1 + 5 * 32 + 1); } - else if (m3_step == 0x15) + else if (state->m3_step == 0x15) { - insert_id(0x316C7057, 1 + 0 * 32); - insert_id(0x316C3057, 1 + 1 * 32); - insert_id(0x216C4057, 1 + 2 * 32); // Lost World may to use 0x016C4057 - insert_id(0x316C5057, 1 + 3 * 32); - insert_id(0x216C6057, 1 + 4 * 32 + 1); - insert_id(0x216C6057, 1 + 5 * 32 + 1); + insert_id(state, 0x316C7057, 1 + 0 * 32); + insert_id(state, 0x316C3057, 1 + 1 * 32); + insert_id(state, 0x216C4057, 1 + 2 * 32); // Lost World may to use 0x016C4057 + insert_id(state, 0x316C5057, 1 + 3 * 32); + insert_id(state, 0x216C6057, 1 + 4 * 32 + 1); + insert_id(state, 0x216C6057, 1 + 5 * 32 + 1); } - else if (m3_step >= 0x20) + else if (state->m3_step >= 0x20) { - insert_id(0x416C7057, 1 + 0 * 32); - insert_id(0x416C3057, 1 + 1 * 32); - insert_id(0x316C4057, 1 + 2 * 32); - insert_id(0x416C5057, 1 + 3 * 32); - insert_id(0x316C6057, 1 + 4 * 32 + 1); - insert_id(0x316C6057, 1 + 5 * 32 + 1); + insert_id(state, 0x416C7057, 1 + 0 * 32); + insert_id(state, 0x416C3057, 1 + 1 * 32); + insert_id(state, 0x316C4057, 1 + 2 * 32); + insert_id(state, 0x416C5057, 1 + 3 * 32); + insert_id(state, 0x316C6057, 1 + 4 * 32 + 1); + insert_id(state, 0x316C6057, 1 + 5 * 32 + 1); } break; case 4: // Shift-DR - tdo = shift(id_data, id_size); + state->tdo = shift(state->id_data, state->id_size); break; case 10: // Capture-IR @@ -228,7 +216,7 @@ void model3_tap_write(int tck, int tms, int tdi, int trst) * Load lower 2 bits with 01 as per IEEE 1149.1-1990 */ - ir = 1; + state->ir = 1; break; case 11: // Shift-IR @@ -237,9 +225,9 @@ void model3_tap_write(int tck, int tms, int tdi, int trst) * Shift IR towards output and load in new data from TDI */ - tdo = ir & 1; // shift LSB to output - ir >>= 1; - ir |= ((UINT64) tdi << 45); + state->tdo = state->ir & 1; // shift LSB to output + state->ir >>= 1; + state->ir |= ((UINT64) tdi << 45); break; case 15: // Update-IR @@ -249,8 +237,7 @@ void model3_tap_write(int tck, int tms, int tdi, int trst) * TCK) */ - ir &= U64(0x3fffffffffff); - current_instruction = ir; + state->ir &= U64(0x3fffffffffff); break; default: @@ -265,11 +252,12 @@ void model3_tap_write(int tck, int tms, int tdi, int trst) * Resets the TAP (simulating a power up or SCAN_RST signal.) */ -void model3_tap_reset(void) +void model3_tap_reset(running_machine *machine) { - id_size = 197; // 197 bits + model3_state *state = machine->driver_data(); + state->id_size = 197; // 197 bits - state = 0; // test-logic/reset + state->tap_state = 0; // test-logic/reset } /* @@ -279,9 +267,10 @@ void model3_tap_reset(void) * */ -void model3_machine_init(int step) +void model3_machine_init(running_machine *machine, int step) { - m3_step = step; + model3_state *state = machine->driver_data(); + state->m3_step = step; } /*****************************************************************************/ diff --git a/src/mame/machine/segas32.c b/src/mame/machine/segas32.c index 8cbe1dbbf47..6b393ee5c3b 100644 --- a/src/mame/machine/segas32.c +++ b/src/mame/machine/segas32.c @@ -56,7 +56,8 @@ WRITE16_HANDLER( ga2_dpram_w ) READ16_HANDLER( ga2_dpram_r ) { - return (ga2_dpram[offset])|(ga2_dpram[offset+1]<<8); + segas32_state *state = space->machine->driver_data(); + return (state->ga2_dpram[offset])|(state->ga2_dpram[offset+1]<<8); } @@ -102,26 +103,27 @@ READ16_HANDLER(ga2_wakeup_protection_r) WRITE16_HANDLER(sonic_level_load_protection) { + segas32_state *state = space->machine->driver_data(); UINT16 level; //Perform write - system32_workram[CLEARED_LEVELS / 2] = (data & mem_mask) | (system32_workram[CLEARED_LEVELS / 2] & ~mem_mask); + state->system32_workram[CLEARED_LEVELS / 2] = (data & mem_mask) | (state->system32_workram[CLEARED_LEVELS / 2] & ~mem_mask); //Refresh current level - if (system32_workram[CLEARED_LEVELS / 2] == 0) + if (state->system32_workram[CLEARED_LEVELS / 2] == 0) { level = 0x0007; } else { const UINT8 *ROM = space->machine->region("maincpu")->base(); - level = *((ROM + LEVEL_ORDER_ARRAY) + (system32_workram[CLEARED_LEVELS / 2] * 2) - 1); - level |= *((ROM + LEVEL_ORDER_ARRAY) + (system32_workram[CLEARED_LEVELS / 2] * 2) - 2) << 8; + level = *((ROM + LEVEL_ORDER_ARRAY) + (state->system32_workram[CLEARED_LEVELS / 2] * 2) - 1); + level |= *((ROM + LEVEL_ORDER_ARRAY) + (state->system32_workram[CLEARED_LEVELS / 2] * 2) - 2) << 8; } - system32_workram[CURRENT_LEVEL / 2] = level; + state->system32_workram[CURRENT_LEVEL / 2] = level; //Reset level status - system32_workram[CURRENT_LEVEL_STATUS / 2] = 0x0000; - system32_workram[(CURRENT_LEVEL_STATUS + 2) / 2] = 0x0000; + state->system32_workram[CURRENT_LEVEL_STATUS / 2] = 0x0000; + state->system32_workram[(CURRENT_LEVEL_STATUS + 2) / 2] = 0x0000; } @@ -136,6 +138,7 @@ WRITE16_HANDLER(sonic_level_load_protection) // and can write things into work RAM. we simulate that here for burning rival. READ16_HANDLER(brival_protection_r) { + segas32_state *state = space->machine->driver_data(); if (mem_mask == 0xffff) // only trap on word-wide reads { switch (offset) @@ -147,11 +150,12 @@ READ16_HANDLER(brival_protection_r) } } - return system32_workram[0xba00/2 + offset]; + return state->system32_workram[0xba00/2 + offset]; } WRITE16_HANDLER(brival_protection_w) { + segas32_state *state = space->machine->driver_data(); static const int protAddress[6][2] = { { 0x109517, 0x00/2 }, @@ -195,7 +199,7 @@ WRITE16_HANDLER(brival_protection_w) memcpy(ret, &ROM[protAddress[curProtType][0]], 16); ret[16] = '\0'; - memcpy(&system32_protram[protAddress[curProtType][1]], ret, 16); + memcpy(&state->system32_protram[protAddress[curProtType][1]], ret, 16); } @@ -303,7 +307,8 @@ READ16_HANDLER(arf_wakeup_protection_r) ******************************************************************************/ WRITE16_HANDLER( jleague_protection_w ) { - COMBINE_DATA( &system32_workram[0xf700/2 + offset ] ); + segas32_state *state = space->machine->driver_data(); + COMBINE_DATA( &state->system32_workram[0xf700/2 + offset ] ); switch( offset ) { @@ -343,13 +348,13 @@ WRITE16_HANDLER( jleague_protection_w ) 99.99% of the dsp code is unused because the V60 ROM is hardcoded as part of a twin set, maybe the standalone board was for dev only? nop the 3 bytes at 0x06023A for standalone. (centred intro text) */ -static UINT16 arescue_dsp_io[6] = {0,0,0,0,0,0}; READ16_HANDLER( arescue_dsp_r ) { + segas32_state *state = space->machine->driver_data(); if( offset == 4/2 ) { - switch( arescue_dsp_io[0] ) + switch( state->arescue_dsp_io[0] ) { case 0: case 1: @@ -357,25 +362,26 @@ READ16_HANDLER( arescue_dsp_r ) break; case 3: - arescue_dsp_io[0] = 0x8000; - arescue_dsp_io[2/2] = 0x0001; + state->arescue_dsp_io[0] = 0x8000; + state->arescue_dsp_io[2/2] = 0x0001; break; case 6: - arescue_dsp_io[0] = 4 * arescue_dsp_io[2/2]; + state->arescue_dsp_io[0] = 4 * state->arescue_dsp_io[2/2]; break; default: - logerror("Unhandled DSP cmd %04x (%04x).\n", arescue_dsp_io[0], arescue_dsp_io[1] ); + logerror("Unhandled DSP cmd %04x (%04x).\n", state->arescue_dsp_io[0], state->arescue_dsp_io[1] ); break; } } - return arescue_dsp_io[offset]; + return state->arescue_dsp_io[offset]; } WRITE16_HANDLER( arescue_dsp_w ) { - COMBINE_DATA(&arescue_dsp_io[offset]); + segas32_state *state = space->machine->driver_data(); + COMBINE_DATA(&state->arescue_dsp_io[offset]); } diff --git a/src/mame/video/beezer.c b/src/mame/video/beezer.c index 9e1a8b63138..b2185c05a64 100644 --- a/src/mame/video/beezer.c +++ b/src/mame/video/beezer.c @@ -3,15 +3,15 @@ #include "machine/6522via.h" #include "includes/beezer.h" -static int scanline=0; INTERRUPT_GEN( beezer_interrupt ) { + beezer_state *state = device->machine->driver_data(); via6522_device *via_0 = device->machine->device("via6522_0"); - scanline = (scanline + 1) % 0x80; - via_0->write_ca2((scanline & 0x10) ? 1 : 0); - if ((scanline & 0x78) == 0x78) + state->scanline = (state->scanline + 1) % 0x80; + via_0->write_ca2((state->scanline & 0x10) ? 1 : 0); + if ((state->scanline & 0x78) == 0x78) cpu_set_input_line(device, M6809_FIRQ_LINE, ASSERT_LINE); else cpu_set_input_line(device, M6809_FIRQ_LINE, CLEAR_LINE); @@ -68,6 +68,7 @@ WRITE8_HANDLER( beezer_map_w ) READ8_HANDLER( beezer_line_r ) { - return (scanline & 0xfe) << 1; + beezer_state *state = space->machine->driver_data(); + return (state->scanline & 0xfe) << 1; } diff --git a/src/mame/video/djmain.c b/src/mame/video/djmain.c index 2042ab173f9..4b457abbb5b 100644 --- a/src/mame/video/djmain.c +++ b/src/mame/video/djmain.c @@ -10,11 +10,11 @@ #define NUM_SPRITES (0x800 / 16) #define NUM_LAYERS 2 -UINT32 *djmain_obj_ram; static void draw_sprites(running_machine* machine, bitmap_t *bitmap, const rectangle *cliprect) { + djmain_state *state = machine->driver_data(); device_t *k055555 = machine->device("k055555"); int offs, pri_code; int sortedlist[NUM_SPRITES]; @@ -27,12 +27,12 @@ static void draw_sprites(running_machine* machine, bitmap_t *bitmap, const recta /* prebuild a sorted table */ for (offs = 0; offs < NUM_SPRITES * 4; offs += 4) { - if (djmain_obj_ram[offs] & 0x00008000) + if (state->obj_ram[offs] & 0x00008000) { - if (djmain_obj_ram[offs] & 0x80000000) + if (state->obj_ram[offs] & 0x80000000) continue; - pri_code = djmain_obj_ram[offs] & (NUM_SPRITES - 1); + pri_code = state->obj_ram[offs] & (NUM_SPRITES - 1); sortedlist[pri_code] = offs; } } @@ -53,16 +53,16 @@ static void draw_sprites(running_machine* machine, bitmap_t *bitmap, const recta offs = sortedlist[pri_code]; if (offs == -1) continue; - code = djmain_obj_ram[offs] >> 16; - flipx = (djmain_obj_ram[offs] >> 10) & 1; - flipy = (djmain_obj_ram[offs] >> 11) & 1; - size = sizetab[(djmain_obj_ram[offs] >> 8) & 3]; + code = state->obj_ram[offs] >> 16; + flipx = (state->obj_ram[offs] >> 10) & 1; + flipy = (state->obj_ram[offs] >> 11) & 1; + size = sizetab[(state->obj_ram[offs] >> 8) & 3]; - ox = (INT16)(djmain_obj_ram[offs + 1] & 0xffff); - oy = (INT16)(djmain_obj_ram[offs + 1] >> 16); + ox = (INT16)(state->obj_ram[offs + 1] & 0xffff); + oy = (INT16)(state->obj_ram[offs + 1] >> 16); - xscale = djmain_obj_ram[offs + 2] >> 16; - yscale = djmain_obj_ram[offs + 2] & 0xffff; + xscale = state->obj_ram[offs + 2] >> 16; + yscale = state->obj_ram[offs + 2] & 0xffff; if (!xscale || !yscale) continue; @@ -72,7 +72,7 @@ static void draw_sprites(running_machine* machine, bitmap_t *bitmap, const recta ox -= (size * xscale) >> 13; oy -= (size * yscale) >> 13; - color = (djmain_obj_ram[offs + 3] >> 16) & 15; + color = (state->obj_ram[offs + 3] >> 16) & 15; for (x = 0; x < size; x++) for (y = 0; y < size; y++) diff --git a/src/mame/video/fastfred.c b/src/mame/video/fastfred.c index 0d902886e69..86cfd66c6b9 100644 --- a/src/mame/video/fastfred.c +++ b/src/mame/video/fastfred.c @@ -11,12 +11,6 @@ #include "includes/fastfred.h" #include "includes/galaxold.h" -UINT8 *fastfred_videoram; -UINT8 *fastfred_spriteram; -size_t fastfred_spriteram_size; -UINT8 *fastfred_attributesram; -UINT8 *fastfred_background_color; -UINT8 *imago_fg_videoram; static const rectangle spritevisiblearea = @@ -31,10 +25,6 @@ static const rectangle spritevisibleareaflipx = 2*8, 30*8-1 }; -static UINT16 charbank; -static UINT8 colorbank; -int fastfred_hardware_type; -static tilemap_t *bg_tilemap, *fg_tilemap, *web_tilemap; /*************************************************************************** @@ -105,10 +95,11 @@ PALETTE_INIT( fastfred ) static TILE_GET_INFO( get_tile_info ) { + fastfred_state *state = machine->driver_data(); UINT8 x = tile_index & 0x1f; - UINT16 code = charbank | fastfred_videoram[tile_index]; - UINT8 color = colorbank | (fastfred_attributesram[2 * x + 1] & 0x07); + UINT16 code = state->charbank | state->videoram[tile_index]; + UINT8 color = state->colorbank | (state->attributesram[2 * x + 1] & 0x07); SET_TILE_INFO(0, code, color, 0); } @@ -123,10 +114,11 @@ static TILE_GET_INFO( get_tile_info ) VIDEO_START( fastfred ) { - bg_tilemap = tilemap_create(machine, get_tile_info,tilemap_scan_rows,8,8,32,32); + fastfred_state *state = machine->driver_data(); + state->bg_tilemap = tilemap_create(machine, get_tile_info,tilemap_scan_rows,8,8,32,32); - tilemap_set_transparent_pen(bg_tilemap, 0); - tilemap_set_scroll_cols(bg_tilemap, 32); + tilemap_set_transparent_pen(state->bg_tilemap, 0); + tilemap_set_scroll_cols(state->bg_tilemap, 32); } @@ -138,14 +130,16 @@ VIDEO_START( fastfred ) WRITE8_HANDLER( fastfred_videoram_w ) { - fastfred_videoram[offset] = data; - tilemap_mark_tile_dirty(bg_tilemap, offset); + fastfred_state *state = space->machine->driver_data(); + state->videoram[offset] = data; + tilemap_mark_tile_dirty(state->bg_tilemap, offset); } WRITE8_HANDLER( fastfred_attributes_w ) { - if (fastfred_attributesram[offset] != data) + fastfred_state *state = space->machine->driver_data(); + if (state->attributesram[offset] != data) { if (offset & 0x01) { @@ -153,65 +147,69 @@ WRITE8_HANDLER( fastfred_attributes_w ) int i; for (i = offset / 2; i < 0x0400; i += 32) - tilemap_mark_tile_dirty(bg_tilemap, i); + tilemap_mark_tile_dirty(state->bg_tilemap, i); } else { /* coloumn scroll */ - tilemap_set_scrolly(bg_tilemap, offset / 2, data); + tilemap_set_scrolly(state->bg_tilemap, offset / 2, data); } - fastfred_attributesram[offset] = data; + state->attributesram[offset] = data; } } WRITE8_HANDLER( fastfred_charbank1_w ) { - UINT16 new_data = (charbank & 0x0200) | ((data & 0x01) << 8); + fastfred_state *state = space->machine->driver_data(); + UINT16 new_data = (state->charbank & 0x0200) | ((data & 0x01) << 8); - if (new_data != charbank) + if (new_data != state->charbank) { - tilemap_mark_all_tiles_dirty(bg_tilemap); + tilemap_mark_all_tiles_dirty(state->bg_tilemap); - charbank = new_data; + state->charbank = new_data; } } WRITE8_HANDLER( fastfred_charbank2_w ) { - UINT16 new_data = (charbank & 0x0100) | ((data & 0x01) << 9); + fastfred_state *state = space->machine->driver_data(); + UINT16 new_data = (state->charbank & 0x0100) | ((data & 0x01) << 9); - if (new_data != charbank) + if (new_data != state->charbank) { - tilemap_mark_all_tiles_dirty(bg_tilemap); + tilemap_mark_all_tiles_dirty(state->bg_tilemap); - charbank = new_data; + state->charbank = new_data; } } WRITE8_HANDLER( fastfred_colorbank1_w ) { - UINT8 new_data = (colorbank & 0x10) | ((data & 0x01) << 3); + fastfred_state *state = space->machine->driver_data(); + UINT8 new_data = (state->colorbank & 0x10) | ((data & 0x01) << 3); - if (new_data != colorbank) + if (new_data != state->colorbank) { - tilemap_mark_all_tiles_dirty(bg_tilemap); + tilemap_mark_all_tiles_dirty(state->bg_tilemap); - colorbank = new_data; + state->colorbank = new_data; } } WRITE8_HANDLER( fastfred_colorbank2_w ) { - UINT8 new_data = (colorbank & 0x08) | ((data & 0x01) << 4); + fastfred_state *state = space->machine->driver_data(); + UINT8 new_data = (state->colorbank & 0x08) | ((data & 0x01) << 4); - if (new_data != colorbank) + if (new_data != state->colorbank) { - tilemap_mark_all_tiles_dirty(bg_tilemap); + tilemap_mark_all_tiles_dirty(state->bg_tilemap); - colorbank = new_data; + state->colorbank = new_data; } } @@ -219,21 +217,23 @@ WRITE8_HANDLER( fastfred_colorbank2_w ) WRITE8_HANDLER( fastfred_flip_screen_x_w ) { + fastfred_state *state = space->machine->driver_data(); if (flip_screen_x_get(space->machine) != (data & 0x01)) { flip_screen_x_set(space->machine, data & 0x01); - tilemap_set_flip(bg_tilemap, (flip_screen_x_get(space->machine) ? TILEMAP_FLIPX : 0) | (flip_screen_y_get(space->machine) ? TILEMAP_FLIPY : 0)); + tilemap_set_flip(state->bg_tilemap, (flip_screen_x_get(space->machine) ? TILEMAP_FLIPX : 0) | (flip_screen_y_get(space->machine) ? TILEMAP_FLIPY : 0)); } } WRITE8_HANDLER( fastfred_flip_screen_y_w ) { + fastfred_state *state = space->machine->driver_data(); if (flip_screen_y_get(space->machine) != (data & 0x01)) { flip_screen_y_set(space->machine, data & 0x01); - tilemap_set_flip(bg_tilemap, (flip_screen_x_get(space->machine) ? TILEMAP_FLIPX : 0) | (flip_screen_y_get(space->machine) ? TILEMAP_FLIPY : 0)); + tilemap_set_flip(state->bg_tilemap, (flip_screen_x_get(space->machine) ? TILEMAP_FLIPX : 0) | (flip_screen_y_get(space->machine) ? TILEMAP_FLIPY : 0)); } } @@ -247,43 +247,44 @@ WRITE8_HANDLER( fastfred_flip_screen_y_w ) static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect) { + fastfred_state *state = machine->driver_data(); int offs; - for (offs = fastfred_spriteram_size - 4; offs >= 0; offs -= 4) + for (offs = state->spriteram_size - 4; offs >= 0; offs -= 4) { UINT8 code,sx,sy; int flipx,flipy; - sx = fastfred_spriteram[offs + 3]; - sy = 240 - fastfred_spriteram[offs]; + sx = state->spriteram[offs + 3]; + sy = 240 - state->spriteram[offs]; - if (fastfred_hardware_type == 3) + if (state->hardware_type == 3) { // Imago - code = (fastfred_spriteram[offs + 1]) & 0x3f; + code = (state->spriteram[offs + 1]) & 0x3f; flipx = 0; flipy = 0; } - else if (fastfred_hardware_type == 2) + else if (state->hardware_type == 2) { // Boggy 84 - code = fastfred_spriteram[offs + 1] & 0x7f; + code = state->spriteram[offs + 1] & 0x7f; flipx = 0; - flipy = fastfred_spriteram[offs + 1] & 0x80; + flipy = state->spriteram[offs + 1] & 0x80; } - else if (fastfred_hardware_type == 1) + else if (state->hardware_type == 1) { // Fly-Boy/Fast Freddie/Red Robin - code = fastfred_spriteram[offs + 1] & 0x7f; + code = state->spriteram[offs + 1] & 0x7f; flipx = 0; - flipy = ~fastfred_spriteram[offs + 1] & 0x80; + flipy = ~state->spriteram[offs + 1] & 0x80; } else { // Jump Coaster - code = (fastfred_spriteram[offs + 1] & 0x3f) | 0x40; - flipx = ~fastfred_spriteram[offs + 1] & 0x40; - flipy = fastfred_spriteram[offs + 1] & 0x80; + code = (state->spriteram[offs + 1] & 0x3f) | 0x40; + flipx = ~state->spriteram[offs + 1] & 0x40; + flipy = state->spriteram[offs + 1] & 0x80; } @@ -300,7 +301,7 @@ static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const recta drawgfx_transpen(bitmap,flip_screen_x_get(machine) ? &spritevisibleareaflipx : &spritevisiblearea,machine->gfx[1], code, - colorbank | (fastfred_spriteram[offs + 2] & 0x07), + state->colorbank | (state->spriteram[offs + 2] & 0x07), flipx,flipy, sx,sy,0); } @@ -309,8 +310,9 @@ static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const recta VIDEO_UPDATE( fastfred ) { - bitmap_fill(bitmap, cliprect, *fastfred_background_color); - tilemap_draw(bitmap,cliprect,bg_tilemap,0,0); + fastfred_state *state = screen->machine->driver_data(); + bitmap_fill(bitmap, cliprect, *state->background_color); + tilemap_draw(bitmap,cliprect,state->bg_tilemap,0,0); draw_sprites(screen->machine, bitmap, cliprect); return 0; @@ -319,17 +321,19 @@ VIDEO_UPDATE( fastfred ) static TILE_GET_INFO( imago_get_tile_info_bg ) { + fastfred_state *state = machine->driver_data(); UINT8 x = tile_index & 0x1f; - UINT16 code = charbank * 0x100 + fastfred_videoram[tile_index]; - UINT8 color = colorbank | (fastfred_attributesram[2 * x + 1] & 0x07); + UINT16 code = state->charbank * 0x100 + state->videoram[tile_index]; + UINT8 color = state->colorbank | (state->attributesram[2 * x + 1] & 0x07); SET_TILE_INFO(0, code, color, 0); } static TILE_GET_INFO( imago_get_tile_info_fg ) { - int code = imago_fg_videoram[tile_index]; + fastfred_state *state = machine->driver_data(); + int code = state->imago_fg_videoram[tile_index]; SET_TILE_INFO(2, code, 2, 0); } @@ -340,27 +344,30 @@ static TILE_GET_INFO( imago_get_tile_info_web ) WRITE8_HANDLER( imago_fg_videoram_w ) { - imago_fg_videoram[offset] = data; - tilemap_mark_tile_dirty(fg_tilemap, offset); + fastfred_state *state = space->machine->driver_data(); + state->imago_fg_videoram[offset] = data; + tilemap_mark_tile_dirty(state->fg_tilemap, offset); } WRITE8_HANDLER( imago_charbank_w ) { - if( charbank != data ) + fastfred_state *state = space->machine->driver_data(); + if( state->charbank != data ) { - charbank = data; - tilemap_mark_all_tiles_dirty(bg_tilemap); + state->charbank = data; + tilemap_mark_all_tiles_dirty(state->bg_tilemap); } } VIDEO_START( imago ) { - web_tilemap = tilemap_create(machine, imago_get_tile_info_web,tilemap_scan_rows, 8,8,32,32); - bg_tilemap = tilemap_create(machine, imago_get_tile_info_bg, tilemap_scan_rows,8,8,32,32); - fg_tilemap = tilemap_create(machine, imago_get_tile_info_fg, tilemap_scan_rows,8,8,32,32); + fastfred_state *state = machine->driver_data(); + state->web_tilemap = tilemap_create(machine, imago_get_tile_info_web,tilemap_scan_rows, 8,8,32,32); + state->bg_tilemap = tilemap_create(machine, imago_get_tile_info_bg, tilemap_scan_rows,8,8,32,32); + state->fg_tilemap = tilemap_create(machine, imago_get_tile_info_fg, tilemap_scan_rows,8,8,32,32); - tilemap_set_transparent_pen(bg_tilemap, 0); - tilemap_set_transparent_pen(fg_tilemap, 0); + tilemap_set_transparent_pen(state->bg_tilemap, 0); + tilemap_set_transparent_pen(state->fg_tilemap, 0); /* the game has a galaxian starfield */ galaxold_init_stars(machine, 256); @@ -373,11 +380,12 @@ VIDEO_START( imago ) VIDEO_UPDATE( imago ) { - tilemap_draw(bitmap,cliprect,web_tilemap,0,0); + fastfred_state *state = screen->machine->driver_data(); + tilemap_draw(bitmap,cliprect,state->web_tilemap,0,0); galaxold_draw_stars(screen->machine, bitmap, cliprect); - tilemap_draw(bitmap,cliprect,bg_tilemap,0,0); + tilemap_draw(bitmap,cliprect,state->bg_tilemap,0,0); draw_sprites(screen->machine, bitmap, cliprect); - tilemap_draw(bitmap,cliprect,fg_tilemap,0,0); + tilemap_draw(bitmap,cliprect,state->fg_tilemap,0,0); return 0; } diff --git a/src/mame/video/gticlub.c b/src/mame/video/gticlub.c index 78e7de56b4a..cf9a5e42a7a 100644 --- a/src/mame/video/gticlub.c +++ b/src/mame/video/gticlub.c @@ -1,6 +1,7 @@ #include "emu.h" #include "cpu/sharc/sharc.h" #include "machine/konppc.h" +#include "video/voodoo.h" #include "video/poly.h" #include "video/konicdev.h" #include "video/gticlub.h" @@ -17,8 +18,12 @@ struct _poly_extra_data int texture_mirror_y; }; -extern UINT8 gticlub_led_reg0; -extern UINT8 gticlub_led_reg1; +static UINT8 gticlub_led_reg[2]; + +void gticlub_led_setreg(int offset, UINT8 data) +{ + gticlub_led_reg[offset] = data; +} /*****************************************************************************/ @@ -967,6 +972,7 @@ static int debug_tex_palette = 0; VIDEO_START( gticlub ) { + gticlub_led_reg[0] = gticlub_led_reg[1] = 0x7f; tick = 0; debug_tex_page = 0; debug_tex_palette = 0; @@ -1035,11 +1041,44 @@ VIDEO_UPDATE( gticlub ) } #endif - draw_7segment_led(bitmap, 3, 3, gticlub_led_reg0); - draw_7segment_led(bitmap, 9, 3, gticlub_led_reg1); + draw_7segment_led(bitmap, 3, 3, gticlub_led_reg[0]); + draw_7segment_led(bitmap, 9, 3, gticlub_led_reg[1]); //cputag_set_input_line(screen->machine, "dsp", SHARC_INPUT_FLAG1, ASSERT_LINE); sharc_set_flag_input(screen->machine->device("dsp"), 1, ASSERT_LINE); return 0; } +VIDEO_UPDATE( hangplt ) +{ + bitmap_fill(bitmap, cliprect, screen->machine->pens[0]); + + if (strcmp(screen->tag(), "lscreen") == 0) + { + device_t *k001604 = screen->machine->device("k001604_1"); + device_t *voodoo = screen->machine->device("voodoo0"); + + // k001604_draw_back_layer(k001604, bitmap, cliprect); + + voodoo_update(voodoo, bitmap, cliprect); + + k001604_draw_front_layer(k001604, bitmap, cliprect); + } + else if (strcmp(screen->tag(), "rscreen") == 0) + { + device_t *k001604 = screen->machine->device("k001604_2"); + device_t *voodoo = screen->machine->device("voodoo1"); + + // k001604_draw_back_layer(k001604, bitmap, cliprect); + + voodoo_update(voodoo, bitmap, cliprect); + + k001604_draw_front_layer(k001604, bitmap, cliprect); + } + + draw_7segment_led(bitmap, 3, 3, gticlub_led_reg[0]); + draw_7segment_led(bitmap, 9, 3, gticlub_led_reg[1]); + + return 0; +} + diff --git a/src/mame/video/gticlub.h b/src/mame/video/gticlub.h index f9b48c2abd6..2ff02e8dced 100644 --- a/src/mame/video/gticlub.h +++ b/src/mame/video/gticlub.h @@ -1,3 +1,5 @@ +void gticlub_led_setreg(int offset, UINT8 data); + void K001005_draw(bitmap_t *bitmap, const rectangle *cliprect); void K001005_swap_buffers(running_machine *machine); void K001005_init(running_machine *machine); @@ -14,3 +16,4 @@ WRITE32_HANDLER(K001006_1_w); VIDEO_START( gticlub ); VIDEO_UPDATE( gticlub ); +VIDEO_UPDATE( hangplt ); diff --git a/src/mame/video/hexion.c b/src/mame/video/hexion.c index 896cfbf2feb..0fd315341fe 100644 --- a/src/mame/video/hexion.c +++ b/src/mame/video/hexion.c @@ -1,9 +1,6 @@ #include "emu.h" #include "includes/hexion.h" -static UINT8 *vram[2],*unkram; -static int bankctrl,rambank,pmcbank,gfxrom_select; -static tilemap_t *bg_tilemap[2]; @@ -25,12 +22,14 @@ INLINE void get_tile_info(running_machine *machine,tile_data *tileinfo,int tile_ static TILE_GET_INFO( get_tile_info0 ) { - get_tile_info(machine,tileinfo,tile_index,vram[0]); + hexion_state *state = machine->driver_data(); + get_tile_info(machine,tileinfo,tile_index,state->vram[0]); } static TILE_GET_INFO( get_tile_info1 ) { - get_tile_info(machine,tileinfo,tile_index,vram[1]); + hexion_state *state = machine->driver_data(); + get_tile_info(machine,tileinfo,tile_index,state->vram[1]); } @@ -43,16 +42,17 @@ static TILE_GET_INFO( get_tile_info1 ) VIDEO_START( hexion ) { - bg_tilemap[0] = tilemap_create(machine, get_tile_info0,tilemap_scan_rows,8,8,64,32); - bg_tilemap[1] = tilemap_create(machine, get_tile_info1,tilemap_scan_rows, 8,8,64,32); + hexion_state *state = machine->driver_data(); + state->bg_tilemap[0] = tilemap_create(machine, get_tile_info0,tilemap_scan_rows,8,8,64,32); + state->bg_tilemap[1] = tilemap_create(machine, get_tile_info1,tilemap_scan_rows, 8,8,64,32); - tilemap_set_transparent_pen(bg_tilemap[0],0); - tilemap_set_scrollx(bg_tilemap[1],0,-4); - tilemap_set_scrolly(bg_tilemap[1],0,4); + tilemap_set_transparent_pen(state->bg_tilemap[0],0); + tilemap_set_scrollx(state->bg_tilemap[1],0,-4); + tilemap_set_scrolly(state->bg_tilemap[1],0,4); - vram[0] = machine->region("maincpu")->base() + 0x30000; - vram[1] = vram[0] + 0x2000; - unkram = vram[1] + 0x2000; + state->vram[0] = machine->region("maincpu")->base() + 0x30000; + state->vram[1] = state->vram[0] + 0x2000; + state->unkram = state->vram[1] + 0x2000; } @@ -65,6 +65,7 @@ VIDEO_START( hexion ) WRITE8_HANDLER( hexion_bankswitch_w ) { + hexion_state *state = space->machine->driver_data(); UINT8 *rom = space->machine->region("maincpu")->base() + 0x10000; /* bits 0-3 select ROM bank */ @@ -73,12 +74,12 @@ WRITE8_HANDLER( hexion_bankswitch_w ) /* does bit 6 trigger the 052591? */ if (data & 0x40) { - int bank = unkram[0]&1; - memset(vram[bank],unkram[1],0x2000); - tilemap_mark_all_tiles_dirty(bg_tilemap[bank]); + int bank = state->unkram[0]&1; + memset(state->vram[bank],state->unkram[1],0x2000); + tilemap_mark_all_tiles_dirty(state->bg_tilemap[bank]); } /* bit 7 = PMC-BK */ - pmcbank = (data & 0x80) >> 7; + state->pmcbank = (data & 0x80) >> 7; /* other bits unknown */ if (data & 0x30) @@ -89,67 +90,71 @@ if (data & 0x30) READ8_HANDLER( hexion_bankedram_r ) { - if (gfxrom_select && offset < 0x1000) + hexion_state *state = space->machine->driver_data(); + if (state->gfxrom_select && offset < 0x1000) { - return space->machine->region("gfx1")->base()[((gfxrom_select & 0x7f) << 12) + offset]; + return space->machine->region("gfx1")->base()[((state->gfxrom_select & 0x7f) << 12) + offset]; } - else if (bankctrl == 0) + else if (state->bankctrl == 0) { - return vram[rambank][offset]; + return state->vram[state->rambank][offset]; } - else if (bankctrl == 2 && offset < 0x800) + else if (state->bankctrl == 2 && offset < 0x800) { - return unkram[offset]; + return state->unkram[offset]; } else { -//logerror("%04x: bankedram_r offset %04x, bankctrl = %02x\n",cpu_get_pc(space->cpu),offset,bankctrl); +//logerror("%04x: bankedram_r offset %04x, state->bankctrl = %02x\n",cpu_get_pc(space->cpu),offset,state->bankctrl); return 0; } } WRITE8_HANDLER( hexion_bankedram_w ) { - if (bankctrl == 3 && offset == 0 && (data & 0xfe) == 0) + hexion_state *state = space->machine->driver_data(); + if (state->bankctrl == 3 && offset == 0 && (data & 0xfe) == 0) { -//logerror("%04x: bankedram_w offset %04x, data %02x, bankctrl = %02x\n",cpu_get_pc(space->cpu),offset,data,bankctrl); - rambank = data & 1; +//logerror("%04x: bankedram_w offset %04x, data %02x, state->bankctrl = %02x\n",cpu_get_pc(space->cpu),offset,data,state->bankctrl); + state->rambank = data & 1; } - else if (bankctrl == 0) + else if (state->bankctrl == 0) { - if (pmcbank) + if (state->pmcbank) { -//logerror("%04x: bankedram_w offset %04x, data %02x, bankctrl = %02x\n",cpu_get_pc(space->cpu),offset,data,bankctrl); - vram[rambank][offset] = data; - tilemap_mark_tile_dirty(bg_tilemap[rambank],offset/4); +//logerror("%04x: bankedram_w offset %04x, data %02x, state->bankctrl = %02x\n",cpu_get_pc(space->cpu),offset,data,state->bankctrl); + state->vram[state->rambank][offset] = data; + tilemap_mark_tile_dirty(state->bg_tilemap[state->rambank],offset/4); } else logerror("%04x pmc internal ram %04x = %02x\n",cpu_get_pc(space->cpu),offset,data); } - else if (bankctrl == 2 && offset < 0x800) + else if (state->bankctrl == 2 && offset < 0x800) { - if (pmcbank) + if (state->pmcbank) { -//logerror("%04x: unkram_w offset %04x, data %02x, bankctrl = %02x\n",cpu_get_pc(space->cpu),offset,data,bankctrl); - unkram[offset] = data; +//logerror("%04x: unkram_w offset %04x, data %02x, state->bankctrl = %02x\n",cpu_get_pc(space->cpu),offset,data,state->bankctrl); + state->unkram[offset] = data; } else logerror("%04x pmc internal ram %04x = %02x\n",cpu_get_pc(space->cpu),offset,data); } else -logerror("%04x: bankedram_w offset %04x, data %02x, bankctrl = %02x\n",cpu_get_pc(space->cpu),offset,data,bankctrl); +logerror("%04x: bankedram_w offset %04x, data %02x, state->bankctrl = %02x\n",cpu_get_pc(space->cpu),offset,data,state->bankctrl); } WRITE8_HANDLER( hexion_bankctrl_w ) { + hexion_state *state = space->machine->driver_data(); //logerror("%04x: bankctrl_w %02x\n",cpu_get_pc(space->cpu),data); - bankctrl = data; + state->bankctrl = data; } WRITE8_HANDLER( hexion_gfxrom_select_w ) { + hexion_state *state = space->machine->driver_data(); //logerror("%04x: gfxrom_select_w %02x\n",cpu_get_pc(space->cpu),data); - gfxrom_select = data; + state->gfxrom_select = data; } @@ -162,7 +167,8 @@ WRITE8_HANDLER( hexion_gfxrom_select_w ) VIDEO_UPDATE( hexion ) { - tilemap_draw(bitmap,cliprect,bg_tilemap[1],0,0); - tilemap_draw(bitmap,cliprect,bg_tilemap[0],0,0); + hexion_state *state = screen->machine->driver_data(); + tilemap_draw(bitmap,cliprect,state->bg_tilemap[1],0,0); + tilemap_draw(bitmap,cliprect,state->bg_tilemap[0],0,0); return 0; } diff --git a/src/mame/video/konamigx.c b/src/mame/video/konamigx.c index 72422cd282f..1dbaa2def4d 100644 --- a/src/mame/video/konamigx.c +++ b/src/mame/video/konamigx.c @@ -72,7 +72,7 @@ static bitmap_t *gxtype1_roz_dstbitmap; static bitmap_t *gxtype1_roz_dstbitmap2; static rectangle gxtype1_roz_dstbitmapclip; -static void (*game_tile_callback)(int layer, int *code, int *color, int *flags); +static void (*game_tile_callback)(running_machine *machine, int layer, int *code, int *color, int *flags); // Localized K053936/ROZ+ #define K053936_MAX_CHIPS 2 @@ -923,7 +923,7 @@ INLINE int K055555GX_decode_inpri(int c18) // (see p.59 7.2.2) return(c18 | op); } -static void konamigx_type2_sprite_callback(int *code, int *color, int *priority) +static void konamigx_type2_sprite_callback(running_machine *machine, int *code, int *color, int *priority) { int num = *code; int c18 = *color; @@ -934,7 +934,7 @@ static void konamigx_type2_sprite_callback(int *code, int *color, int *priority) *priority = K055555GX_decode_inpri(c18); } -static void konamigx_dragoonj_sprite_callback(int *code, int *color, int *priority) +static void konamigx_dragoonj_sprite_callback(running_machine *machine, int *code, int *color, int *priority) { int num, op, pri, c18; @@ -952,7 +952,7 @@ static void konamigx_dragoonj_sprite_callback(int *code, int *color, int *priori *color = K055555GX_decode_objcolor(c18); } -static void konamigx_salmndr2_sprite_callback(int *code, int *color, int *priority) +static void konamigx_salmndr2_sprite_callback(running_machine *machine, int *code, int *color, int *priority) { int num, op, pri, c18; @@ -970,7 +970,7 @@ static void konamigx_salmndr2_sprite_callback(int *code, int *color, int *priori *color = K055555GX_decode_objcolor(c18); } -static void konamigx_le2_sprite_callback(int *code, int *color, int *priority) +static void konamigx_le2_sprite_callback(running_machine *machine, int *code, int *color, int *priority) { int num, op, pri; @@ -1116,7 +1116,7 @@ static int gx_objdma, gx_primode; // mirrored K053247 and K054338 settings UINT16 *K053247_ram; static gfx_element *K053247_gfx; -static void (*K053247_callback)(int *code,int *color,int *priority); +static void (*K053247_callback)(running_machine *machine, int *code,int *color,int *priority); static int K053247_dx, K053247_dy; static int *K054338_shdRGB; @@ -1362,7 +1362,7 @@ void konamigx_mixer(running_machine *machine, bitmap_t *bitmap, const rectangle color = k = gx_spriteram[offs+6]; l = gx_spriteram[offs+7]; - (*K053247_callback)(&code, &color, &pri); + (*K053247_callback)(machine, &code, &color, &pri); /* shadow = shadow code @@ -1955,7 +1955,7 @@ static TILE_GET_INFO( get_gx_psac1b_tile_info ) SET_TILE_INFO(0, tileno, colour, flip); } -static void konamigx_type2_tile_callback(int layer, int *code, int *color, int *flags) +static void konamigx_type2_tile_callback(running_machine *machine, int layer, int *code, int *color, int *flags) { int d = *code; @@ -1963,7 +1963,7 @@ static void konamigx_type2_tile_callback(int layer, int *code, int *color, int * K055555GX_decode_vmixcolor(layer, color); } -static void konamigx_alpha_tile_callback(int layer, int *code, int *color, int *flags) +static void konamigx_alpha_tile_callback(running_machine *machine, int layer, int *code, int *color, int *flags) { int mixcode; int d = *code; diff --git a/src/mame/video/konamiic.c b/src/mame/video/konamiic.c index 4e897156c13..6ff0aa28bf7 100644 --- a/src/mame/video/konamiic.c +++ b/src/mame/video/konamiic.c @@ -3721,10 +3721,10 @@ static UINT8 K053246_regs[8]; static UINT16 K053247_regs[16]; static UINT16 *K053247_ram=0; static gfx_element *K053247_gfx; -static void (*K053247_callback)(int *code,int *color,int *priority); +static void (*K053247_callback)(running_machine *machine, int *code,int *color,int *priority); static UINT8 K053246_OBJCHA_line; -void K053247_export_config(UINT16 **ram, gfx_element **gfx, void (**callback)(int *, int *, int *), int *dx, int *dy) +void K053247_export_config(UINT16 **ram, gfx_element **gfx, void (**callback)(running_machine *, int *, int *, int *), int *dx, int *dy) { if(ram) *ram = K053247_ram; @@ -3841,7 +3841,7 @@ void K053247_vh_start(running_machine *machine, const char *gfx_memory_region, i #endif /* K055673 used with the 54246 in PreGX/Run and Gun/System GX games */ -void K055673_vh_start(running_machine *machine, const char *gfx_memory_region, int layout, int dx, int dy, void (*callback)(int *code,int *color,int *priority)) +void K055673_vh_start(running_machine *machine, const char *gfx_memory_region, int layout, int dx, int dy, void (*callback)(running_machine *machine, int *code,int *color,int *priority)) { int gfx_index; UINT32 total; @@ -5542,7 +5542,7 @@ int K056832_get_lookup(int bits) } #endif -static void (*K056832_callback)(int layer, int *code, int *color, int *flags); +static void (*K056832_callback)(running_machine *machine, int layer, int *code, int *color, int *flags); INLINE void K056832_get_tile_info( running_machine *machine, tile_data *tileinfo, int tile_index, int pageIndex ) { @@ -5579,7 +5579,7 @@ INLINE void K056832_get_tile_info( running_machine *machine, tile_data *tileinfo color = (attr & smptr->palm1) | (attr>>smptr->pals2 & smptr->palm2); flags = TILE_FLIPYX(flip); - (*K056832_callback)(layer, &code, &color, &flags); + (*K056832_callback)(machine, layer, &code, &color, &flags); SET_TILE_INFO(K056832_gfxnum, code, @@ -5678,7 +5678,7 @@ static STATE_POSTLOAD( K056832_postload ) void K056832_vh_start(running_machine *machine, const char *gfx_memory_region, int bpp, int big, int (*scrolld)[4][2], - void (*callback)(int layer, int *code, int *color, int *flags), + void (*callback)(running_machine *machine, int layer, int *code, int *color, int *flags), int djmain_hack) { tilemap_t *tmap; diff --git a/src/mame/video/konamiic.h b/src/mame/video/konamiic.h index 1a10770d111..ba6e1af8fc5 100644 --- a/src/mame/video/konamiic.h +++ b/src/mame/video/konamiic.h @@ -144,7 +144,7 @@ void K053245_set_SpriteOffset(int chip,int offsx, int offsy); #define K055673_LAYOUT_GX6 3 void K055673_vh_start(running_machine *machine, const char *gfx_memory_region, int alt_layout, int dx, int dy, - void (*callback)(int *code,int *color,int *priority)); + void (*callback)(running_machine *machine, int *code,int *color,int *priority)); READ16_HANDLER( K055673_rom_word_r ); READ16_HANDLER( K055673_GX6bpp_rom_word_r ); @@ -179,7 +179,7 @@ void K053247_set_SpriteOffset(int offsx, int offsy); void K053247_wraparound_enable(int status); void K05324x_set_z_rejection(int zcode); // common to K053245/6/7 #endif -void K053247_export_config(UINT16 **ram, gfx_element **gfx, void (**callback)(int *, int *, int *), int *dx, int *dy); +void K053247_export_config(UINT16 **ram, gfx_element **gfx, void (**callback)(running_machine *, int *, int *, int *), int *dx, int *dy); #ifdef UNUSED_FUNCTION READ8_HANDLER( K053246_r ); @@ -280,7 +280,7 @@ void K056832_SetExtLinescroll(void); /* Lethal Enforcers */ void K056832_vh_start(running_machine *machine, const char *gfx_memory_region, int bpp, int big, int (*scrolld)[4][2], - void (*callback)(int layer, int *code, int *color, int *flags), + void (*callback)(running_machine *machine, int layer, int *code, int *color, int *flags), int djmain_hack); READ16_HANDLER( K056832_ram_word_r ); WRITE16_HANDLER( K056832_ram_word_w ); diff --git a/src/mame/video/m3raster.c b/src/mame/video/m3raster.c index de1f9f2f97c..ec992c6a935 100644 --- a/src/mame/video/m3raster.c +++ b/src/mame/video/m3raster.c @@ -4,7 +4,7 @@ static void draw_scanline_normal(void *dest, INT32 scanline, const poly_extent * const cached_texture *texture = extra->texture; bitmap_t *destmap = (bitmap_t *)dest; UINT16 *p = BITMAP_ADDR16(destmap, scanline, 0); - UINT32 *d = BITMAP_ADDR32(zbuffer, scanline, 0); + UINT32 *d = BITMAP_ADDR32(extra->zbuffer, scanline, 0); float ooz = extent->param[0].start; float uoz = extent->param[1].start; float voz = extent->param[2].start; @@ -53,7 +53,7 @@ static void draw_scanline_trans(void *dest, INT32 scanline, const poly_extent *e const cached_texture *texture = extra->texture; bitmap_t *destmap = (bitmap_t *)dest; UINT16 *p = BITMAP_ADDR16(destmap, scanline, 0); - UINT32 *d = BITMAP_ADDR32(zbuffer, scanline, 0); + UINT32 *d = BITMAP_ADDR32(extra->zbuffer, scanline, 0); float ooz = extent->param[0].start; float uoz = extent->param[1].start; float voz = extent->param[2].start; @@ -108,7 +108,7 @@ static void draw_scanline_alpha(void *dest, INT32 scanline, const poly_extent *e const cached_texture *texture = extra->texture; bitmap_t *destmap = (bitmap_t *)dest; UINT16 *p = BITMAP_ADDR16(destmap, scanline, 0); - UINT32 *d = BITMAP_ADDR32(zbuffer, scanline, 0); + UINT32 *d = BITMAP_ADDR32(extra->zbuffer, scanline, 0); float ooz = extent->param[0].start; float uoz = extent->param[1].start; float voz = extent->param[2].start; @@ -166,7 +166,7 @@ static void draw_scanline_alpha_test(void *dest, INT32 scanline, const poly_exte const cached_texture *texture = extra->texture; bitmap_t *destmap = (bitmap_t *)dest; UINT16 *p = BITMAP_ADDR16(destmap, scanline, 0); - UINT32 *d = BITMAP_ADDR32(zbuffer, scanline, 0); + UINT32 *d = BITMAP_ADDR32(extra->zbuffer, scanline, 0); float ooz = extent->param[0].start; float uoz = extent->param[1].start; float voz = extent->param[2].start; @@ -225,7 +225,7 @@ static void draw_scanline_color(void *dest, INT32 scanline, const poly_extent *e const poly_extra_data *extra = (const poly_extra_data *)extradata; bitmap_t *destmap = (bitmap_t *)dest; UINT16 *p = BITMAP_ADDR16(destmap, scanline, 0); - UINT32 *d = BITMAP_ADDR32(zbuffer, scanline, 0); + UINT32 *d = BITMAP_ADDR32(extra->zbuffer, scanline, 0); float ooz = extent->param[0].start; float doozdx = extent->param[0].dpdx; int fr = extra->color & 0x7c00; diff --git a/src/mame/video/model1.c b/src/mame/video/model1.c index cb267f64b34..057c5761f90 100644 --- a/src/mame/video/model1.c +++ b/src/mame/video/model1.c @@ -7,31 +7,33 @@ #define LOG_TGP(x) do { if (LOG_TGP_VIDEO) logerror x; } while (0) -UINT16 *model1_display_list0, *model1_display_list1; -UINT16 *model1_color_xlat; -static UINT16 listctl[2]; -static UINT16 *glist; // Model 1 geometrizer TGP and rasterizer simulation enum { FRAC_SHIFT = 16 }; +enum { MOIRE = 0x00010000 }; -static int render_done; -static UINT16 *tgp_ram; -static float trans_mat[12]; -static UINT16 *paletteram16; -static float vxx, vyy, vzz, ayy, ayyc, ayys; struct vector { float x, y, z; }; -static struct { +struct lightparam { + float a; + float d; + float s; + int p; +}; + +struct view { int xc, yc, x1, y1, x2, y2; float zoomx, zoomy, transx, transy; float a_bottom, a_top, a_left, a_right; + float vxx, vyy, vzz, ayy, ayyc, ayys; + float trans_mat[12]; struct vector light; -} view; + struct lightparam lightparams[32]; +}; struct spoint { INT32 x, y; @@ -43,15 +45,6 @@ struct point { struct spoint s; }; -static struct lightparam -{ - float a; - float d; - float s; - int p; -} lightparams[32]; - -enum { MOIRE = 0x00010000 }; struct quad_m1 { struct point *p[4]; @@ -59,11 +52,7 @@ struct quad_m1 { int col; }; -static struct point *pointdb, *pointpt; -static struct quad_m1 *quaddb, *quadpt; -static struct quad_m1 **quadind; -static UINT32 *poly_rom,*poly_ram; static UINT32 readi(const UINT16 *adr) { @@ -80,23 +69,25 @@ static float readf(const UINT16 *adr) return u2f(readi(adr)); } -static void transform_point(struct point *p) +static void transform_point(struct view *view, struct point *p) { struct point q = *p; + float *trans = view->trans_mat; float xx, zz; - xx = trans_mat[0]*q.x+trans_mat[3]*q.y+trans_mat[6]*q.z+trans_mat[9]+vxx; - p->y = trans_mat[1]*q.x+trans_mat[4]*q.y+trans_mat[7]*q.z+trans_mat[10]+vyy; - zz = trans_mat[2]*q.x+trans_mat[5]*q.y+trans_mat[8]*q.z+trans_mat[11]+vzz; - p->x = ayyc*xx-ayys*zz; - p->z = ayys*xx+ayyc*zz; + xx = trans[0]*q.x+trans[3]*q.y+trans[6]*q.z+trans[9]+view->vxx; + p->y = trans[1]*q.x+trans[4]*q.y+trans[7]*q.z+trans[10]+view->vyy; + zz = trans[2]*q.x+trans[5]*q.y+trans[8]*q.z+trans[11]+view->vzz; + p->x = view->ayyc*xx-view->ayys*zz; + p->z = view->ayys*xx+view->ayyc*zz; } -static void transform_vector(struct vector *p) +static void transform_vector(struct view *view, struct vector *p) { struct vector q = *p; - p->x = trans_mat[0]*q.x+trans_mat[3]*q.y+trans_mat[6]*q.z; - p->y = trans_mat[1]*q.x+trans_mat[4]*q.y+trans_mat[7]*q.z; - p->z = trans_mat[2]*q.x+trans_mat[5]*q.y+trans_mat[8]*q.z; + float *trans = view->trans_mat; + p->x = trans[0]*q.x+trans[3]*q.y+trans[6]*q.z; + p->y = trans[1]*q.x+trans[4]*q.y+trans[7]*q.z; + p->z = trans[2]*q.x+trans[5]*q.y+trans[8]*q.z; } static void normalize_vector(struct vector *p) @@ -127,20 +118,20 @@ static float view_determinant(const struct point *p1, const struct point *p2, co } -static void project_point(struct point *p) +static void project_point(struct view *view, struct point *p) { p->xx = p->x / p->z; p->yy = p->y / p->z; - p->s.x = view.xc+(p->xx*view.zoomx+view.transx); - p->s.y = view.yc-(p->yy*view.zoomy+view.transy); + p->s.x = view->xc+(p->xx*view->zoomx+view->transx); + p->s.y = view->yc-(p->yy*view->zoomy+view->transy); } -static void project_point_direct(struct point *p) +static void project_point_direct(struct view *view, struct point *p) { p->xx = p->x /*/ p->z*/; p->yy = p->y /*/ p->z*/; - p->s.x = view.xc+(p->xx); - p->s.y = view.yc-(p->yy); + p->s.x = view->xc+(p->xx); + p->s.y = view->yc-(p->yy); } @@ -163,26 +154,26 @@ static void draw_hline_moired(bitmap_t *bitmap, int x1, int x2, int y, int color } } -static void fill_slope(bitmap_t *bitmap, int color, INT32 x1, INT32 x2, INT32 sl1, INT32 sl2, INT32 y1, INT32 y2, INT32 *nx1, INT32 *nx2) +static void fill_slope(bitmap_t *bitmap, struct view *view, int color, INT32 x1, INT32 x2, INT32 sl1, INT32 sl2, INT32 y1, INT32 y2, INT32 *nx1, INT32 *nx2) { - if(y1 > view.y2) + if(y1 > view->y2) return; - if(y2 <= view.y1) { + if(y2 <= view->y1) { int delta = y2-y1; *nx1 = x1+delta*sl1; *nx2 = x2+delta*sl2; return; } - if(y2 > view.y2) - y2 = view.y2+1; + if(y2 > view->y2) + y2 = view->y2+1; - if(y1 < view.y1) { - int delta = view.y1 - y1; + if(y1 < view->y1) { + int delta = view->y1 - y1; x1 += delta*sl1; x2 += delta*sl2; - y1 = view.y1; + y1 = view->y1; } if(x1 > x2 || (x1==x2 && sl1 > sl2)) { @@ -199,14 +190,14 @@ static void fill_slope(bitmap_t *bitmap, int color, INT32 x1, INT32 x2, INT32 sl } while(y1 < y2) { - if(y1 >= view.y1) { + if(y1 >= view->y1) { int xx1 = x1>>FRAC_SHIFT; int xx2 = x2>>FRAC_SHIFT; - if(xx1 <= view.x2 || xx2 >= view.x1) { - if(xx1 < view.x1) - xx1 = view.x1; - if(xx2 > view.x2) - xx2 = view.x2; + if(xx1 <= view->x2 || xx2 >= view->x1) { + if(xx1 < view->x1) + xx1 = view->x1; + if(xx2 > view->x2) + xx2 = view->x2; if(color & MOIRE) draw_hline_moired(bitmap, xx1, xx2, y1, color); @@ -223,19 +214,19 @@ static void fill_slope(bitmap_t *bitmap, int color, INT32 x1, INT32 x2, INT32 sl *nx2 = x2; } -static void fill_line(bitmap_t *bitmap, int color, INT32 y, INT32 x1, INT32 x2) +static void fill_line(bitmap_t *bitmap, struct view *view, int color, INT32 y, INT32 x1, INT32 x2) { int xx1 = x1>>FRAC_SHIFT; int xx2 = x2>>FRAC_SHIFT; - if(y > view.y2 || y < view.y1) + if(y > view->y2 || y < view->y1) return; - if(xx1 <= view.x2 || xx2 >= view.x1) { - if(xx1 < view.x1) - xx1 = view.x1; - if(xx2 > view.x2) - xx2 = view.x2; + if(xx1 <= view->x2 || xx2 >= view->x1) { + if(xx1 < view->x1) + xx1 = view->x1; + if(xx2 > view->x2) + xx2 = view->x2; if(color & MOIRE) draw_hline_moired(bitmap, xx1, xx2, y, color); @@ -244,7 +235,7 @@ static void fill_line(bitmap_t *bitmap, int color, INT32 y, INT32 x1, INT32 x2) } } -static void fill_quad(bitmap_t *bitmap, const struct quad_m1 *q) +static void fill_quad(bitmap_t *bitmap, struct view *view, const struct quad_m1 *q) { INT32 sl1, sl2, cury, limy, x1, x2; int pmin, pmax, i, ps1, ps2; @@ -284,17 +275,17 @@ static void fill_quad(bitmap_t *bitmap, const struct quad_m1 *q) if(p[i].x > x2) x2 = p[i].x; } - fill_line(bitmap, color, cury, x1, x2); + fill_line(bitmap, view, color, cury, x1, x2); return; } - if(cury > view.y2) + if(cury > view->y2) return; - if(limy <= view.y1) + if(limy <= view->y1) return; - if(limy > view.y2) - limy = view.y2; + if(limy > view->y2) + limy = view->y2; ps1 = pmin+4; ps2 = pmin; @@ -303,7 +294,7 @@ static void fill_quad(bitmap_t *bitmap, const struct quad_m1 *q) for(;;) { if(p[ps1-1].y == p[ps2+1].y) { - fill_slope(bitmap, color, x1, x2, sl1, sl2, cury, p[ps1-1].y, &x1, &x2); + fill_slope(bitmap, view, color, x1, x2, sl1, sl2, cury, p[ps1-1].y, &x1, &x2); cury = p[ps1-1].y; if(cury >= limy) break; @@ -320,7 +311,7 @@ static void fill_quad(bitmap_t *bitmap, const struct quad_m1 *q) sl1 = (x1-p[ps1-1].x)/(cury-p[ps1-1].y); sl2 = (x2-p[ps2+1].x)/(cury-p[ps2+1].y); } else if(p[ps1-1].y < p[ps2+1].y) { - fill_slope(bitmap, color, x1, x2, sl1, sl2, cury, p[ps1-1].y, &x1, &x2); + fill_slope(bitmap, view, color, x1, x2, sl1, sl2, cury, p[ps1-1].y, &x1, &x2); cury = p[ps1-1].y; if(cury >= limy) break; @@ -330,7 +321,7 @@ static void fill_quad(bitmap_t *bitmap, const struct quad_m1 *q) x1 = p[ps1].x; sl1 = (x1-p[ps1-1].x)/(cury-p[ps1-1].y); } else { - fill_slope(bitmap, color, x1, x2, sl1, sl2, cury, p[ps2+1].y, &x1, &x2); + fill_slope(bitmap, view, color, x1, x2, sl1, sl2, cury, p[ps2+1].y, &x1, &x2); cury = p[ps2+1].y; if(cury >= limy) break; @@ -342,20 +333,20 @@ static void fill_quad(bitmap_t *bitmap, const struct quad_m1 *q) } } if(cury == limy) - fill_line(bitmap, color, cury, x1, x2); + fill_line(bitmap, view, color, cury, x1, x2); } #if 0 -static void draw_line(bitmap_t *bitmap, int color, int x1, int y1, int x2, int y2) +static void draw_line(bitmap_t *bitmap, struct view *view, int color, int x1, int y1, int x2, int y2) { int s1x, s1y, s2x, s2y; int d1, d2; int cur; int x, y; - if((x1 < view.x1 && x2 < view.x1) || - (x1 > view.x2 && x2 > view.x2) || - (y1 < view.y1 && y2 < view.y1) || - (y1 > view.y2 && y2 > view.y2)) + if((x1 < view->x1 && x2 < view->x1) || + (x1 > view->x2 && x2 > view->x2) || + (y1 < view->y1 && y2 < view->y1) || + (y1 > view->y2 && y2 > view->y2)) return; x = x1; @@ -393,7 +384,7 @@ static void draw_line(bitmap_t *bitmap, int color, int x1, int y1, int x2, int y cur = 0; while(x != x2 || y != y2) { - if(x>=view.x1 && x<=view.x2 && y>=view.y1 && y<=view.y2) + if(x>=view->x1 && x<=view->x2 && y>=view->y1 && y<=view->y2) *BITMAP_ADDR16(bitmap, y, x) = color; x += s1x; y += s1y; @@ -404,7 +395,7 @@ static void draw_line(bitmap_t *bitmap, int color, int x1, int y1, int x2, int y y += s2y; } } - if(x>=view.x1 && x<=view.x2 && y>=view.y1 && y<=view.y2) + if(x>=view->x1 && x<=view->x2 && y>=view->y1 && y<=view->y2) *BITMAP_ADDR16(bitmap, y, x) = color; } #endif @@ -418,49 +409,50 @@ static int comp_quads(const void *q1, const void *q2) if(z1>z2) return -1; - if (*(const struct quad_m1 **)q1 - quaddb < *(const struct quad_m1 **)q2 - quaddb) + if (*(const struct quad_m1 **)q1 - *(const struct quad_m1 **)q2 < 0) return -1; return +1; } -static void sort_quads(void) +static void sort_quads(model1_state *state) { - int count = quadpt - quaddb; + int count = state->quadpt - state->quaddb; int i; for(i=0; iquadind[i] = state->quaddb+i; + qsort(state->quadind, count, sizeof(struct quad_m1 *), comp_quads); } -static void unsort_quads(void) +static void unsort_quads(model1_state *state) { - int count = quadpt - quaddb; + int count = state->quadpt - state->quaddb; int i; for(i=0; iquadind[i] = state->quaddb+i; } -static void draw_quads(bitmap_t *bitmap, const rectangle *cliprect) +static void draw_quads(model1_state *state, bitmap_t *bitmap, const rectangle *cliprect) { - int count = quadpt - quaddb; + struct view *view = state->view; + int count = state->quadpt - state->quaddb; int i; /* clip to the cliprect */ - int save_x1 = view.x1; - int save_x2 = view.x2; - int save_y1 = view.y1; - int save_y2 = view.y2; - view.x1 = MAX(view.x1, cliprect->min_x); - view.x2 = MIN(view.x2, cliprect->max_x); - view.y1 = MAX(view.y1, cliprect->min_y); - view.y2 = MIN(view.y2, cliprect->max_y); + int save_x1 = view->x1; + int save_x2 = view->x2; + int save_y1 = view->y1; + int save_y2 = view->y2; + view->x1 = MAX(view->x1, cliprect->min_x); + view->x2 = MIN(view->x2, cliprect->max_x); + view->y1 = MAX(view->y1, cliprect->min_y); + view->y2 = MIN(view->y2, cliprect->max_y); for(i=0; iquadind[i]; - fill_quad(bitmap, q); + fill_quad(bitmap, view, q); #if 0 draw_line(bitmap, get_black_pen(screen->machine), q->p[0]->s.x, q->p[0]->s.y, q->p[1]->s.x, q->p[1]->s.y); draw_line(bitmap, get_black_pen(screen->machine), q->p[1]->s.x, q->p[1]->s.y, q->p[2]->s.x, q->p[2]->s.y); @@ -469,10 +461,10 @@ static void draw_quads(bitmap_t *bitmap, const rectangle *cliprect) #endif } - view.x1 = save_x1; - view.x2 = save_x2; - view.y1 = save_y1; - view.y2 = save_y2; + view->x1 = save_x1; + view->x2 = save_x2; + view->y1 = save_y1; + view->y2 = save_y2; } #if 0 static UINT16 scale_color(UINT16 color, float level) @@ -500,77 +492,73 @@ static UINT16 scale_color(UINT16 color, float level) // => t*(x1-x2+a*(z2-z1) = -x2+a*z2 // => t = (z2*a-x2)/((z2-z1)*a-(x2-x1)) -static void recompute_frustrum(void) +static void recompute_frustrum(struct view *view) { - view.a_left = ( view.x1-view.xc-view.transx)/view.zoomx; - view.a_right = ( view.x2-view.xc-view.transx)/view.zoomx; - view.a_bottom = (-view.y1+view.yc-view.transy)/view.zoomy; - view.a_top = (-view.y2+view.yc-view.transy)/view.zoomy; + view->a_left = ( view->x1-view->xc-view->transx)/view->zoomx; + view->a_right = ( view->x2-view->xc-view->transx)/view->zoomx; + view->a_bottom = (-view->y1+view->yc-view->transy)/view->zoomy; + view->a_top = (-view->y2+view->yc-view->transy)/view->zoomy; } -static int fclip_isc_bottom(struct point *p) +static int fclip_isc_bottom(struct view *view, struct point *p) { - return p->y > p->z*view.a_bottom; + return p->y > p->z*view->a_bottom; } -static struct point *fclip_clip_bottom(struct point *p1, struct point *p2) +static void fclip_clip_bottom(struct view *view, struct point *pt, struct point *p1, struct point *p2) { - float t = (p2->z*view.a_bottom-p2->y)/((p2->z-p1->z)*view.a_bottom-(p2->y-p1->y)); - pointpt->x = p1->x*t + p2->x*(1-t); - pointpt->y = p1->y*t + p2->y*(1-t); - pointpt->z = p1->z*t + p2->z*(1-t); - project_point(pointpt); - return pointpt++; + float t = (p2->z*view->a_bottom-p2->y)/((p2->z-p1->z)*view->a_bottom-(p2->y-p1->y)); + pt->x = p1->x*t + p2->x*(1-t); + pt->y = p1->y*t + p2->y*(1-t); + pt->z = p1->z*t + p2->z*(1-t); + project_point(view, pt); } -static int fclip_isc_top(struct point *p) +static int fclip_isc_top(struct view *view, struct point *p) { - return p->y < p->z*view.a_top; + return p->y < p->z*view->a_top; } -static struct point *fclip_clip_top(struct point *p1, struct point *p2) +static void fclip_clip_top(struct view *view, struct point *pt, struct point *p1, struct point *p2) { - float t = (p2->z*view.a_top-p2->y)/((p2->z-p1->z)*view.a_top-(p2->y-p1->y)); - pointpt->x = p1->x*t + p2->x*(1-t); - pointpt->y = p1->y*t + p2->y*(1-t); - pointpt->z = p1->z*t + p2->z*(1-t); - project_point(pointpt); - return pointpt++; + float t = (p2->z*view->a_top-p2->y)/((p2->z-p1->z)*view->a_top-(p2->y-p1->y)); + pt->x = p1->x*t + p2->x*(1-t); + pt->y = p1->y*t + p2->y*(1-t); + pt->z = p1->z*t + p2->z*(1-t); + project_point(view, pt); } -static int fclip_isc_left(struct point *p) +static int fclip_isc_left(struct view *view, struct point *p) { - return p->x < p->z*view.a_left; + return p->x < p->z*view->a_left; } -static struct point *fclip_clip_left(struct point *p1, struct point *p2) +static void fclip_clip_left(struct view *view, struct point *pt, struct point *p1, struct point *p2) { - float t = (p2->z*view.a_left-p2->x)/((p2->z-p1->z)*view.a_left-(p2->x-p1->x)); - pointpt->x = p1->x*t + p2->x*(1-t); - pointpt->y = p1->y*t + p2->y*(1-t); - pointpt->z = p1->z*t + p2->z*(1-t); - project_point(pointpt); - return pointpt++; + float t = (p2->z*view->a_left-p2->x)/((p2->z-p1->z)*view->a_left-(p2->x-p1->x)); + pt->x = p1->x*t + p2->x*(1-t); + pt->y = p1->y*t + p2->y*(1-t); + pt->z = p1->z*t + p2->z*(1-t); + project_point(view, pt); } -static int fclip_isc_right(struct point *p) +static int fclip_isc_right(struct view *view, struct point *p) { - return p->x > p->z*view.a_right; + return p->x > p->z*view->a_right; } -static struct point *fclip_clip_right(struct point *p1, struct point *p2) +static void fclip_clip_right(struct view *view, struct point *pt, struct point *p1, struct point *p2) { - float t = (p2->z*view.a_right-p2->x)/((p2->z-p1->z)*view.a_right-(p2->x-p1->x)); - pointpt->x = p1->x*t + p2->x*(1-t); - pointpt->y = p1->y*t + p2->y*(1-t); - pointpt->z = p1->z*t + p2->z*(1-t); - project_point(pointpt); - return pointpt++; + float t = (p2->z*view->a_right-p2->x)/((p2->z-p1->z)*view->a_right-(p2->x-p1->x)); + pt->x = p1->x*t + p2->x*(1-t); + pt->y = p1->y*t + p2->y*(1-t); + pt->z = p1->z*t + p2->z*(1-t); + project_point(view, pt); } static const struct { - int (*isclipped)(struct point *p); - struct point *(*clip)(struct point *p1, struct point *p2); + int (*isclipped)(struct view *view, struct point *p); + void (*clip)(struct view *view, struct point *pt, struct point *p1, struct point *p2); } clipfn[4] = { { fclip_isc_bottom, fclip_clip_bottom }, { fclip_isc_top, fclip_clip_top }, @@ -578,9 +566,9 @@ static const struct { { fclip_isc_right, fclip_clip_right }, }; -static void fclip_push_quad(int level, struct quad_m1 *q); +static void fclip_push_quad(model1_state *state, int level, struct quad_m1 *q); -static void fclip_push_quad_next(int level, struct quad_m1 *q, +static void fclip_push_quad_next(model1_state *state, int level, struct quad_m1 *q, struct point *p1, struct point *p2, struct point *p3, struct point *p4) { struct quad_m1 q2; @@ -591,28 +579,29 @@ static void fclip_push_quad_next(int level, struct quad_m1 *q, q2.p[2] = p3; q2.p[3] = p4; - fclip_push_quad(level+1, &q2); + fclip_push_quad(state, level+1, &q2); } -static void fclip_push_quad(int level, struct quad_m1 *q) +static void fclip_push_quad(model1_state *state, int level, struct quad_m1 *q) { + struct view *view = state->view; int i, j; struct point *pt[4], *pi1, *pi2; int is_out[4], is_out2[4]; - struct point *(*fclip_point)(struct point *p1, struct point *p2); + void (*fclip_point)(struct view *view, struct point *pt, struct point *p1, struct point *p2); if(level == 4) { LOG_TGP(("VIDEOCQ %d", level)); for(i=0; i<4; i++) LOG_TGP((" (%f, %f, %f)", q->p[i]->x, q->p[i]->y, q->p[i]->z)); LOG_TGP(("\n")); - *quadpt = *q; - quadpt++; + *state->quadpt = *q; + state->quadpt++; return; } for(i=0; i<4; i++) - is_out[i] = clipfn[level].isclipped(q->p[i]); + is_out[i] = clipfn[level].isclipped(view, q->p[i]); LOG_TGP(("VIDEOCQ %d", level)); for(i=0; i<4; i++) @@ -621,7 +610,7 @@ static void fclip_push_quad(int level, struct quad_m1 *q) // No clipping if(!is_out[0] && !is_out[1] && !is_out[2] && !is_out[3]) { - fclip_push_quad(level+1, q); + fclip_push_quad(state, level+1, q); return; } @@ -645,30 +634,40 @@ static void fclip_push_quad(int level, struct quad_m1 *q) if(is_out2[1]) if(is_out2[2]) { // pt 0,1,2 clipped out, one triangle left - pi1 = fclip_point(pt[2], pt[3]); - pi2 = fclip_point(pt[3], pt[0]); - fclip_push_quad_next(level, q, pi1, pt[3], pi2, pi2); + fclip_point(view, state->pointpt, pt[2], pt[3]); + pi1 = state->pointpt++; + fclip_point(view, state->pointpt, pt[3], pt[0]); + pi2 = state->pointpt++; + fclip_push_quad_next(state, level, q, pi1, pt[3], pi2, pi2); } else { // pt 0,1 clipped out, one quad left - pi1 = fclip_point(pt[1], pt[2]); - pi2 = fclip_point(pt[3], pt[0]); - fclip_push_quad_next(level, q, pi1, pt[2], pt[3], pi2); + fclip_point(view, state->pointpt, pt[1], pt[2]); + pi1 = state->pointpt++; + fclip_point(view, state->pointpt, pt[3], pt[0]); + pi2 = state->pointpt++; + fclip_push_quad_next(state, level, q, pi1, pt[2], pt[3], pi2); } else if(is_out2[2]) { // pt 0,2 clipped out, shouldn't happen, two triangles - pi1 = fclip_point(pt[0], pt[1]); - pi2 = fclip_point(pt[1], pt[2]); - fclip_push_quad_next(level, q, pi1, pt[1], pi2, pi2); - pi1 = fclip_point(pt[2], pt[3]); - pi2 = fclip_point(pt[3], pt[0]); - fclip_push_quad_next(level, q, pi1, pt[3], pi2, pi2); + fclip_point(view, state->pointpt, pt[0], pt[1]); + pi1 = state->pointpt++; + fclip_point(view, state->pointpt, pt[1], pt[2]); + pi2 = state->pointpt++; + fclip_push_quad_next(state, level, q, pi1, pt[1], pi2, pi2); + fclip_point(view, state->pointpt, pt[2], pt[3]); + pi1 = state->pointpt++; + fclip_point(view, state->pointpt, pt[3], pt[0]); + pi2 = state->pointpt++; + fclip_push_quad_next(state, level, q, pi1, pt[3], pi2, pi2); } else { // pt 0 clipped out, one decagon left, split in quad+tri - pi1 = fclip_point(pt[0], pt[1]); - pi2 = fclip_point(pt[3], pt[0]); - fclip_push_quad_next(level, q, pi1, pt[1], pt[2], pt[3]); - fclip_push_quad_next(level, q, pt[3], pi2, pi1, pi1); + fclip_point(view, state->pointpt, pt[0], pt[1]); + pi1 = state->pointpt++; + fclip_point(view, state->pointpt, pt[3], pt[0]); + pi2 = state->pointpt++; + fclip_push_quad_next(state, level, q, pi1, pt[1], pt[2], pt[3]); + fclip_push_quad_next(state, level, q, pt[3], pi2, pi1, pi1); } } @@ -703,9 +702,9 @@ static float compute_specular(struct vector *normal, struct vector *light,float { #if 0 float s; - int p=lightparams[lmode].p&7; + int p=view->lightparams[lmode].p&7; int i; - float sv=lightparams[lmode].s; + float sv=view->lightparams[lmode].s; //This is how it should be according to model2 geo program, but doesn't work fine s=2*(diffuse*normal->z-light->z); @@ -727,6 +726,8 @@ static float compute_specular(struct vector *normal, struct vector *light,float static void push_object(running_machine *machine, UINT32 tex_adr, UINT32 poly_adr, UINT32 size) { + model1_state *state = machine->driver_data(); + struct view *view = state->view; int i; UINT32 flags; struct point *old_p0, *old_p1, *p0, *p1; @@ -741,9 +742,9 @@ static void push_object(running_machine *machine, UINT32 tex_adr, UINT32 poly_ad float *poly_data; if(poly_adr & 0x800000) - poly_data=(float *) poly_ram; + poly_data=(float *) state->poly_ram; else - poly_data=(float *) poly_rom; + poly_data=(float *) state->poly_rom; poly_adr &= 0x7fffff; #if 0 @@ -772,8 +773,8 @@ static void push_object(running_machine *machine, UINT32 tex_adr, UINT32 poly_ad if(!size) size = 0xffffffff; - old_p0 = pointpt++; - old_p1 = pointpt++; + old_p0 = state->pointpt++; + old_p1 = state->pointpt++; old_p0->x = poly_data[poly_adr+0]; old_p0->y = poly_data[poly_adr+1]; @@ -781,14 +782,14 @@ static void push_object(running_machine *machine, UINT32 tex_adr, UINT32 poly_ad old_p1->x = poly_data[poly_adr+3]; old_p1->y = poly_data[poly_adr+4]; old_p1->z = poly_data[poly_adr+5]; - transform_point(old_p0); - transform_point(old_p1); + transform_point(view, old_p0); + transform_point(view, old_p1); if(old_p0->z > 0) - project_point(old_p0); + project_point(view, old_p0); else old_p0->s.x = old_p0->s.y = 0; if(old_p1->z > 0) - project_point(old_p1); + project_point(view, old_p1); else old_p1->s.x = old_p1->s.y = 0; @@ -814,8 +815,8 @@ static void push_object(running_machine *machine, UINT32 tex_adr, UINT32 poly_ad tex_adr ++; lightmode=(flags>>17)&15; - p0 = pointpt++; - p1 = pointpt++; + p0 = state->pointpt++; + p1 = state->pointpt++; vn.x = poly_data[poly_adr+1]; vn.y = poly_data[poly_adr+2]; @@ -829,16 +830,16 @@ static void push_object(running_machine *machine, UINT32 tex_adr, UINT32 poly_ad link = (flags >> 8) & 3; - transform_vector(&vn); + transform_vector(view, &vn); - transform_point(p0); - transform_point(p1); + transform_point(view, p0); + transform_point(view, p1); if(p0->z > 0) - project_point(p0); + project_point(view, p0); else p0->s.x = p0->s.y = 0; if(p1->z > 0) - project_point(p1); + project_point(view, p1); else p1->s.x = p1->s.y = 0; @@ -892,32 +893,33 @@ static void push_object(running_machine *machine, UINT32 tex_adr, UINT32 poly_ad } { - /*float dif=mult_vector(&vn, &view.light); - float ln=lightparams[lightmode].a + lightparams[lightmode].d*MAX(0.0,dif); - cquad.col = scale_color(machine->pens[0x1000|(tgp_ram[tex_adr-0x40000] & 0x3ff)], MIN(1.0,ln)); - cquad.col = scale_color(machine->pens[0x1000|(tgp_ram[tex_adr-0x40000] & 0x3ff)], MIN(1.0,ln)); - */ - float dif=mult_vector(&vn, &view.light); - float spec=compute_specular(&vn,&view.light,dif,lightmode); - float ln=lightparams[lightmode].a + lightparams[lightmode].d*MAX(0.0,dif) + spec; +#if 0 + float dif=mult_vector(&vn, &view->light); + float ln=view->lightparams[lightmode].a + view->lightparams[lightmode].d*MAX(0.0,dif); + cquad.col = scale_color(machine->pens[0x1000|(state->tgp_ram[tex_adr-0x40000] & 0x3ff)], MIN(1.0,ln)); + cquad.col = scale_color(machine->pens[0x1000|(state->tgp_ram[tex_adr-0x40000] & 0x3ff)], MIN(1.0,ln)); +#endif + float dif=mult_vector(&vn, &view->light); + float spec=compute_specular(&vn,&view->light,dif,lightmode); + float ln=view->lightparams[lightmode].a + view->lightparams[lightmode].d*MAX(0.0,dif) + spec; int lumval=255.0*MIN(1.0,ln); - int color=paletteram16[0x1000|(tgp_ram[tex_adr-0x40000] & 0x3ff)]; + int color=state->paletteram16[0x1000|(state->tgp_ram[tex_adr-0x40000] & 0x3ff)]; int r=(color>>0x0)&0x1f; int g=(color>>0x5)&0x1f; int b=(color>>0xA)&0x1f; lumval>>=2; //there must be a luma translation table somewhere if(lumval>0x3f) lumval=0x3f; else if(lumval<0) lumval=0; - r=(model1_color_xlat[(r<<8)|lumval|0x0]>>3)&0x1f; - g=(model1_color_xlat[(g<<8)|lumval|0x2000]>>3)&0x1f; - b=(model1_color_xlat[(b<<8)|lumval|0x4000]>>3)&0x1f; + r=(state->color_xlat[(r<<8)|lumval|0x0]>>3)&0x1f; + g=(state->color_xlat[(g<<8)|lumval|0x2000]>>3)&0x1f; + b=(state->color_xlat[(b<<8)|lumval|0x4000]>>3)&0x1f; cquad.col=(r<<10)|(g<<5)|(b<<0); } if(flags & 0x00002000) cquad.col |= MOIRE; - fclip_push_quad(0, &cquad); + fclip_push_quad(state, 0, &cquad); next: poly_adr += 10; @@ -937,8 +939,9 @@ static void push_object(running_machine *machine, UINT32 tex_adr, UINT32 poly_ad } } -static UINT16 *push_direct(UINT16 *list) +static UINT16 *push_direct(model1_state *state, UINT16 *list) { + struct view *view = state->view; UINT32 flags; UINT32 tex_adr, lum, v1, v2; struct point *old_p0, *old_p1, *p0, *p1; @@ -950,8 +953,8 @@ static UINT16 *push_direct(UINT16 *list) v1 = readi(list+2); v2 = readi(list+10); - old_p0 = pointpt++; - old_p1 = pointpt++; + old_p0 = state->pointpt++; + old_p1 = state->pointpt++; old_p0->x = readf(list+4); old_p0->y = readf(list+6); @@ -965,14 +968,14 @@ static UINT16 *push_direct(UINT16 *list) old_p0->x, old_p0->y, old_p0->z, old_p1->x, old_p1->y, old_p1->z)); -// transform_point(old_p0); -// transform_point(old_p1); + //transform_point(view, old_p0); + //transform_point(view, old_p1); if(old_p0->z > 0) - project_point_direct(old_p0); + project_point_direct(view, old_p0); else old_p0->s.x = old_p0->s.y = 0; if(old_p1->z > 0) - project_point_direct(old_p1); + project_point_direct(view, old_p1); else old_p1->s.x = old_p1->s.y = 0; @@ -992,8 +995,8 @@ static UINT16 *push_direct(UINT16 *list) // list+4 is 0? // list+12 is z? - p0 = pointpt++; - p1 = pointpt++; + p0 = state->pointpt++; + p1 = state->pointpt++; lum = readi(list+2); v1 = readi(list+4); @@ -1025,12 +1028,12 @@ static UINT16 *push_direct(UINT16 *list) link = (flags >> 8) & 3; -// transform_point(p0); -// transform_point(p1); + //transform_point(view, p0); + //transform_point(view, p1); if(p0->z > 0) - project_point_direct(p0); + project_point_direct(view, p0); if(p1->z > 0) - project_point_direct(p1); + project_point_direct(view, p1); #if 1 if(old_p0 && old_p1) @@ -1058,23 +1061,23 @@ static UINT16 *push_direct(UINT16 *list) cquad.z = z; { int lumval=((float) (lum>>24)) * 2.0; - int color=paletteram16[0x1000|(tgp_ram[tex_adr-0x40000] & 0x3ff)]; + int color=state->paletteram16[0x1000|(state->tgp_ram[tex_adr-0x40000] & 0x3ff)]; int r=(color>>0x0)&0x1f; int g=(color>>0x5)&0x1f; int b=(color>>0xA)&0x1f; lumval>>=2; //there must be a luma translation table somewhere if(lumval>0x3f) lumval=0x3f; else if(lumval<0) lumval=0; - r=(model1_color_xlat[(r<<8)|lumval|0x0]>>3)&0x1f; - g=(model1_color_xlat[(g<<8)|lumval|0x2000]>>3)&0x1f; - b=(model1_color_xlat[(b<<8)|lumval|0x4000]>>3)&0x1f; + r=(state->color_xlat[(r<<8)|lumval|0x0]>>3)&0x1f; + g=(state->color_xlat[(g<<8)|lumval|0x2000]>>3)&0x1f; + b=(state->color_xlat[(b<<8)|lumval|0x4000]>>3)&0x1f; cquad.col=(r<<10)|(g<<5)|(b<<0); } - //cquad.col = scale_color(machine->pens[0x1000|(tgp_ram[tex_adr-0x40000] & 0x3ff)],((float) (lum>>24)) / 128.0); + //cquad.col = scale_color(machine->pens[0x1000|(state->tgp_ram[tex_adr-0x40000] & 0x3ff)],((float) (lum>>24)) / 128.0); if(flags & 0x00002000) cquad.col |= MOIRE; - fclip_push_quad(0, &cquad); + fclip_push_quad(state, 0, &cquad); next: switch(link) { @@ -1116,84 +1119,89 @@ static UINT16 *skip_direct(UINT16 *list) return list+2; } -static void draw_objects(bitmap_t *bitmap, const rectangle *cliprect) +static void draw_objects(model1_state *state, bitmap_t *bitmap, const rectangle *cliprect) { - if(quadpt != quaddb) { + if(state->quadpt != state->quaddb) { LOG_TGP(("VIDEO: sort&draw\n")); - sort_quads(); - draw_quads(bitmap, cliprect); + sort_quads(state); + draw_quads(state, bitmap, cliprect); } - quadpt = quaddb; - pointpt = pointdb; + state->quadpt = state->quaddb; + state->pointpt = state->pointdb; } -static UINT16 *draw_direct(UINT16 *list, bitmap_t *bitmap, const rectangle *cliprect) +static UINT16 *draw_direct(model1_state *state, bitmap_t *bitmap, const rectangle *cliprect, UINT16 *list) { UINT16 *res; LOG_TGP(("VIDEO: draw direct %x\n", readi(list))); - draw_objects(bitmap, cliprect); - res = push_direct(list); - unsort_quads(); - draw_quads(bitmap, cliprect); + draw_objects(state, bitmap, cliprect); + res = push_direct(state, list); + unsort_quads(state); + draw_quads(state, bitmap, cliprect); - quadpt = quaddb; - pointpt = pointdb; + state->quadpt = state->quaddb; + state->pointpt = state->pointdb; return res; } -static UINT16 *get_list(void) +static UINT16 *get_list(model1_state *state) { - if(!(listctl[0] & 4)) - listctl[0] = (listctl[0] & ~0x40) | (listctl[0] & 8 ? 0x40 : 0); - return listctl[0] & 0x40 ? model1_display_list1 : model1_display_list0; + if(!(state->listctl[0] & 4)) + state->listctl[0] = (state->listctl[0] & ~0x40) | (state->listctl[0] & 8 ? 0x40 : 0); + return state->listctl[0] & 0x40 ? state->display_list1 : state->display_list0; } -static int get_list_number(void) +static int get_list_number(model1_state *state) { - if(!(listctl[0] & 4)) - listctl[0] = (listctl[0] & ~0x40) | (listctl[0] & 8 ? 0x40 : 0); - return listctl[0] & 0x40 ? 0 : 1; + if(!(state->listctl[0] & 4)) + state->listctl[0] = (state->listctl[0] & ~0x40) | (state->listctl[0] & 8 ? 0x40 : 0); + return state->listctl[0] & 0x40 ? 0 : 1; } static void end_frame(running_machine *machine) { - if((listctl[0] & 4) && (machine->primary_screen->frame_number() & 1)) - listctl[0] ^= 0x40; + model1_state *state = machine->driver_data(); + if((state->listctl[0] & 4) && (machine->primary_screen->frame_number() & 1)) + state->listctl[0] ^= 0x40; } READ16_HANDLER( model1_listctl_r ) { + model1_state *state = space->machine->driver_data(); if(!offset) - return listctl[0] | 0x30; + return state->listctl[0] | 0x30; else - return listctl[1]; + return state->listctl[1]; } WRITE16_HANDLER( model1_listctl_w ) { - COMBINE_DATA(listctl+offset); - LOG_TGP(("VIDEO: control=%08x\n", (listctl[1]<<16)|listctl[0])); + model1_state *state = space->machine->driver_data(); + COMBINE_DATA(state->listctl+offset); + LOG_TGP(("VIDEO: control=%08x\n", (state->listctl[1]<<16)|state->listctl[0])); } static void tgp_render(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect) { - render_done = 1; - if((listctl[1] & 0x1f) == 0x1f) { - UINT16 *list = get_list(); + model1_state *state = machine->driver_data(); + struct view *view = state->view; + state->render_done = 1; + if((state->listctl[1] & 0x1f) == 0x1f) { + UINT16 *list = get_list(state); int zz = 0; - LOG_TGP(("VIDEO: render list %d\n", get_list_number())); + LOG_TGP(("VIDEO: render list %d\n", get_list_number(state))); - memset(trans_mat, 0, sizeof(trans_mat)); - trans_mat[0] = 1.0; - trans_mat[4] = 1.0; - trans_mat[8] = 1.0; + memset(view->trans_mat, 0, sizeof(view->trans_mat)); + view->trans_mat[0] = 1.0; + view->trans_mat[4] = 1.0; + view->trans_mat[8] = 1.0; for(;;) { int type = (list[1]<<16)|list[0]; - glist=list; + state->glist=list; switch(type & 15) { case 0: list += 2; @@ -1211,7 +1219,7 @@ static void tgp_render(running_machine *machine, bitmap_t *bitmap, const rectang list += 8; break; case 2: - list = draw_direct(list+2, bitmap, cliprect); + list = draw_direct(state, bitmap, cliprect, list+2); break; case 3: LOG_TGP(("VIDEO: viewport (%d, %d, %d, %d, %d, %d, %d)\n", @@ -1219,16 +1227,16 @@ static void tgp_render(running_machine *machine, bitmap_t *bitmap, const rectang readi16(list+4), readi16(list+6), readi16(list+8), readi16(list+10), readi16(list+12), readi16(list+14))); - draw_objects(bitmap, cliprect); + draw_objects(state, bitmap, cliprect); - view.xc = readi16(list+4); - view.yc = 383-(readi16(list+6)-39); - view.x1 = readi16(list+8); - view.y2 = 383-(readi16(list+10)-39); - view.x2 = readi16(list+12); - view.y1 = 383-(readi16(list+14)-39); + view->xc = readi16(list+4); + view->yc = 383-(readi16(list+6)-39); + view->x1 = readi16(list+8); + view->y2 = 383-(readi16(list+10)-39); + view->x2 = readi16(list+12); + view->y1 = 383-(readi16(list+14)-39); - recompute_frustrum(); + recompute_frustrum(view); list += 16; break; @@ -1238,7 +1246,7 @@ static void tgp_render(running_machine *machine, bitmap_t *bitmap, const rectang int i; LOG_TGP(("ZVIDEO: color write, adr=%x, len=%x\n", adr, len)); for(i=0; itgp_ram[adr-0x40000+i] = list[6+2*i]; list += 6+len*2; break; } @@ -1249,7 +1257,7 @@ static void tgp_render(running_machine *machine, bitmap_t *bitmap, const rectang int i; for(i=0;ipoly_ram[adr-0x800000+i]=readi(list+2*i+6); } list+=6+len*2; } @@ -1262,10 +1270,10 @@ static void tgp_render(running_machine *machine, bitmap_t *bitmap, const rectang for(i=0;i>8)&0xff))/255.0; - lightparams[i+adr].s=((float) ((v>>16)&0xff))/255.0; - lightparams[i+adr].p=(v>>24)&0xff; + view->lightparams[i+adr].d=((float) (v&0xff))/255.0; + view->lightparams[i+adr].a=((float) ((v>>8)&0xff))/255.0; + view->lightparams[i+adr].s=((float) ((v>>16)&0xff))/255.0; + view->lightparams[i+adr].p=(v>>24)&0xff; } list += 6+len*2; break; @@ -1281,19 +1289,19 @@ static void tgp_render(running_machine *machine, bitmap_t *bitmap, const rectang break; case 9: LOG_TGP(("VIDEO: zoom (%f, %f)\n", readf(list+2), readf(list+4))); - view.zoomx = readf(list+2)*4; - view.zoomy = readf(list+4)*4; + view->zoomx = readf(list+2)*4; + view->zoomy = readf(list+4)*4; - recompute_frustrum(); + recompute_frustrum(view); list += 6; break; case 0xa: LOG_TGP(("VIDEO: light vector (%f, %f, %f)\n", readf(list+2), readf(list+4), readf(list+6))); - view.light.x = readf(list+2); - view.light.y = readf(list+4); - view.light.z = readf(list+6); - normalize_vector(&view.light); + view->light.x = readf(list+2); + view->light.y = readf(list+4); + view->light.z = readf(list+6); + normalize_vector(&view->light); list += 8; break; case 0xb: { @@ -1304,16 +1312,16 @@ static void tgp_render(running_machine *machine, bitmap_t *bitmap, const rectang readf(list+14), readf(list+16), readf(list+18), readf(list+20), readf(list+22), readf(list+24))); for(i=0; i<12; i++) - trans_mat[i] = readf(list+2+2*i); + view->trans_mat[i] = readf(list+2+2*i); list += 26; break; } case 0xc: LOG_TGP(("VIDEO: trans (%f, %f)\n", readf(list+2), readf(list+4))); - view.transx = readf(list+2); - view.transy = readf(list+4); + view->transx = readf(list+2); + view->transy = readf(list+4); - recompute_frustrum(); + recompute_frustrum(view); list += 6; break; @@ -1326,29 +1334,31 @@ static void tgp_render(running_machine *machine, bitmap_t *bitmap, const rectang } } end: - draw_objects(bitmap, cliprect); + draw_objects(state, bitmap, cliprect); } } -static void tgp_scan(void) +static void tgp_scan(running_machine *machine) { + model1_state *state = machine->driver_data(); + struct view *view = state->view; #if 0 if (input_code_pressed_once(machine, KEYCODE_F)) { - FILE *fp; - fp=fopen("tgp-ram.bin", "w+b"); - if (fp) + FILE *fp; + fp=fopen("tgp-ram.bin", "w+b"); + if (fp) { - fwrite(tgp_ram, (0x100000-0x40000)*2, 1, fp); - fclose(fp); + fwrite(state->tgp_ram, (0x100000-0x40000)*2, 1, fp); + fclose(fp); } - exit(0); + exit(0); } #endif - if(!render_done && (listctl[1] & 0x1f) == 0x1f) { - UINT16 *list = get_list(); + if(!state->render_done && (state->listctl[1] & 0x1f) == 0x1f) { + UINT16 *list = get_list(state); // Skip everything but the data uploads - LOG_TGP(("VIDEO: scan list %d\n", get_list_number())); + LOG_TGP(("VIDEO: scan list %d\n", get_list_number(state))); for(;;) { int type = (list[1]<<16)|list[0]; switch(type) { @@ -1370,7 +1380,7 @@ static void tgp_scan(void) int i; LOG_TGP(("ZVIDEO: scan color write, adr=%x, len=%x\n", adr, len)); for(i=0; itgp_ram[adr-0x40000+i] = list[6+2*i]; list += 6+len*2; break; } @@ -1381,7 +1391,7 @@ static void tgp_scan(void) int i; for(i=0;ipoly_ram[adr-0x800000+i]=readi(list+2*i+6); } list+=6+len*2; } @@ -1394,10 +1404,10 @@ static void tgp_scan(void) for(i=0;i>8)&0xff))/255.0; - lightparams[i+adr].s=((float) ((v>>16)&0xff))/255.0; - lightparams[i+adr].p=(v>>24)&0xff; + view->lightparams[i+adr].d=((float) (v&0xff))/255.0; + view->lightparams[i+adr].a=((float) ((v>>8)&0xff))/255.0; + view->lightparams[i+adr].s=((float) ((v>>16)&0xff))/255.0; + view->lightparams[i+adr].p=(v>>24)&0xff; //LOG_TGP((" %02X\n",v)); } list += 6+len*2; @@ -1432,36 +1442,38 @@ static void tgp_scan(void) end: ; } - render_done = 0; + state->render_done = 0; } VIDEO_START(model1) { - paletteram16 = machine->generic.paletteram.u16; + model1_state *state = machine->driver_data(); + state->paletteram16 = machine->generic.paletteram.u16; - vxx=vyy=vzz=0; - ayy = 0; + state->view = auto_alloc_clear(machine, struct view); sys24_tile_vh_start(machine, 0x3fff); - poly_rom = (UINT32 *)machine->region("user1")->base(); - poly_ram = auto_alloc_array_clear(machine, UINT32, 0x400000); - tgp_ram = auto_alloc_array_clear(machine, UINT16, 0x100000-0x40000); - pointdb = auto_alloc_array_clear(machine, struct point, 1000000*2); - quaddb = auto_alloc_array_clear(machine, struct quad_m1, 1000000); - quadind = auto_alloc_array_clear(machine, struct quad_m1 *, 1000000); + state->poly_rom = (UINT32 *)machine->region("user1")->base(); + state->poly_ram = auto_alloc_array_clear(machine, UINT32, 0x400000); + state->tgp_ram = auto_alloc_array_clear(machine, UINT16, 0x100000-0x40000); + state->pointdb = auto_alloc_array_clear(machine, struct point, 1000000*2); + state->quaddb = auto_alloc_array_clear(machine, struct quad_m1, 1000000); + state->quadind = auto_alloc_array_clear(machine, struct quad_m1 *, 1000000); - pointpt = pointdb; - quadpt = quaddb; - listctl[0] = listctl[1] = 0; + state->pointpt = state->pointdb; + state->quadpt = state->quaddb; + state->listctl[0] = state->listctl[1] = 0; - state_save_register_global_pointer(machine, tgp_ram, 0x100000-0x40000); - state_save_register_global_pointer(machine, poly_ram, 0x40000); - state_save_register_global_array(machine, listctl); + state_save_register_global_pointer(machine, state->tgp_ram, 0x100000-0x40000); + state_save_register_global_pointer(machine, state->poly_ram, 0x40000); + state_save_register_global_array(machine, state->listctl); } VIDEO_UPDATE(model1) { + model1_state *state = screen->machine->driver_data(); + struct view *view = state->view; #if 0 { int mod = 0; @@ -1470,43 +1482,43 @@ VIDEO_UPDATE(model1) if(input_code_pressed(screen->machine, KEYCODE_F)) { mod = 1; - vxx -= delta; + view->vxx -= delta; } if(input_code_pressed(screen->machine, KEYCODE_G)) { mod = 1; - vxx += delta; + view->vxx += delta; } if(input_code_pressed(screen->machine, KEYCODE_H)) { mod = 1; - vyy -= delta; + view->vyy -= delta; } if(input_code_pressed(screen->machine, KEYCODE_J)) { mod = 1; - vyy += delta; + view->vyy += delta; } if(input_code_pressed(screen->machine, KEYCODE_K)) { mod = 1; - vzz -= delta; + view->vzz -= delta; } if(input_code_pressed(screen->machine, KEYCODE_L)) { mod = 1; - vzz += delta; + view->vzz += delta; } if(input_code_pressed(screen->machine, KEYCODE_U)) { mod = 1; - ayy -= 0.05; + view->ayy -= 0.05; } if(input_code_pressed(screen->machine, KEYCODE_I)) { mod = 1; - ayy += 0.05; + view->ayy += 0.05; } if(mod) - popmessage("%g,%g,%g:%g", vxx, vyy, vzz, ayy); + popmessage("%g,%g,%g:%g", view->vxx, view->vyy, view->vzz, view->ayy); } #endif - ayyc = cos(ayy); - ayys = sin(ayy); + view->ayyc = cos(view->ayy); + view->ayys = sin(view->ayy); bitmap_fill(screen->machine->priority_bitmap, NULL, 0); bitmap_fill(bitmap, cliprect, screen->machine->pens[0]); @@ -1528,7 +1540,7 @@ VIDEO_UPDATE(model1) VIDEO_EOF(model1) { - tgp_scan(); + tgp_scan(machine); end_frame(machine); LOG_TGP(("TGP: vsync\n")); } diff --git a/src/mame/video/model2.c b/src/mame/video/model2.c index 5612b04ce75..d7f01f982b3 100644 --- a/src/mame/video/model2.c +++ b/src/mame/video/model2.c @@ -92,7 +92,6 @@ #define DEBUG 0 -static poly_manager *poly; #define pz p[0] #define pu p[1] @@ -141,6 +140,7 @@ typedef struct typedef struct _poly_extra_data poly_extra_data; struct _poly_extra_data { + model2_state * state; UINT32 lumabase; UINT32 colorbase; UINT32 * texsheet; @@ -292,18 +292,16 @@ static INT32 clip_polygon(poly_vertex *v, INT32 num_vertices, plane *cp, poly_ve /******************************************* * - * Hardware 3D Rasterizer Interal State + * Hardware 3D Rasterizer Internal State * *******************************************/ #define MAX_TRIANGLES 32768 -typedef struct +struct _raster_state { UINT32 mode; /* bit 0 = Test Mode, bit 2 = Switch 60Hz(1)/30Hz(0) operation */ UINT16 * texture_rom; /* Texture ROM pointer */ - UINT16 * texture_ram; /* Texture RAM pointer */ - UINT8 * log_ram; /* Log RAM pointer */ INT16 viewport[4]; /* View port (startx,starty,endx,endy) */ INT16 center[4][2]; /* Centers (eye 0[x,y],1[x,y],2[x,y],3[x,y]) */ UINT16 center_sel; /* Selected center */ @@ -314,15 +312,15 @@ typedef struct UINT32 cur_command; /* Current command */ UINT32 command_buffer[32]; /* Command buffer */ UINT32 command_index; /* Command buffer index */ - triangle * tri_list; /* Triangle list */ + triangle tri_list[MAX_TRIANGLES]; /* Triangle list */ UINT32 tri_list_index; /* Triangle list index */ - triangle ** tri_sorted_list; /* Sorted Triangle list */ + triangle * tri_sorted_list[0x10000]; /* Sorted Triangle list */ UINT16 min_z; /* Minimum sortable Z value */ UINT16 max_z; /* Maximum sortable Z value */ + UINT16 texture_ram[0x10000]; /* Texture RAM pointer */ + UINT8 log_ram[0x40000]; /* Log RAM pointer */ +}; -} raster_state; - -static raster_state raster; /******************************************* * @@ -332,13 +330,11 @@ static raster_state raster; static void model2_3d_init( running_machine *machine, UINT16 *texture_rom ) { - memset( &raster, 0, sizeof( raster_state ) ); + model2_state *state = machine->driver_data(); - raster.texture_rom = texture_rom; - raster.texture_ram = auto_alloc_array(machine, UINT16, 0x10000); - raster.log_ram = auto_alloc_array(machine, UINT8, 0x40000); - raster.tri_list = auto_alloc_array(machine, triangle, MAX_TRIANGLES); - raster.tri_sorted_list = auto_alloc_array(machine, triangle *, 0x10000); + state->raster = auto_alloc_clear( machine, raster_state ); + + state->raster->texture_rom = texture_rom; } /******************************************* @@ -347,9 +343,10 @@ static void model2_3d_init( running_machine *machine, UINT16 *texture_rom ) * *******************************************/ -void model2_3d_set_zclip( UINT8 clip ) +void model2_3d_set_zclip( running_machine *machine, UINT8 clip ) { - raster.master_z_clip = clip; + model2_state *state = machine->driver_data(); + state->raster->master_z_clip = clip; } /******************************************* @@ -358,7 +355,7 @@ void model2_3d_set_zclip( UINT8 clip ) * *******************************************/ -static void model2_3d_process_quad( UINT32 attr ) +static void model2_3d_process_quad( raster_state *raster, UINT32 attr ) { _quad_m2 object; UINT16 *th, *tp; @@ -368,24 +365,24 @@ static void model2_3d_process_quad( UINT32 attr ) float min_z, max_z; /* extract P0(n-1) */ - object.v[1].x = u2f( raster.command_buffer[2] << 8 ); - object.v[1].y = u2f( raster.command_buffer[3] << 8 ); - object.v[1].pz = u2f( raster.command_buffer[4] << 8 ); + object.v[1].x = u2f( raster->command_buffer[2] << 8 ); + object.v[1].y = u2f( raster->command_buffer[3] << 8 ); + object.v[1].pz = u2f( raster->command_buffer[4] << 8 ); /* extract P1(n-1) */ - object.v[0].x = u2f( raster.command_buffer[5] << 8 ); - object.v[0].y = u2f( raster.command_buffer[6] << 8 ); - object.v[0].pz = u2f( raster.command_buffer[7] << 8 ); + object.v[0].x = u2f( raster->command_buffer[5] << 8 ); + object.v[0].y = u2f( raster->command_buffer[6] << 8 ); + object.v[0].pz = u2f( raster->command_buffer[7] << 8 ); /* extract P0(n) */ - object.v[2].x = u2f( raster.command_buffer[11] << 8 ); - object.v[2].y = u2f( raster.command_buffer[12] << 8 ); - object.v[2].pz = u2f( raster.command_buffer[13] << 8 ); + object.v[2].x = u2f( raster->command_buffer[11] << 8 ); + object.v[2].y = u2f( raster->command_buffer[12] << 8 ); + object.v[2].pz = u2f( raster->command_buffer[13] << 8 ); /* extract P1(n) */ - object.v[3].x = u2f( raster.command_buffer[14] << 8 ); - object.v[3].y = u2f( raster.command_buffer[15] << 8 ); - object.v[3].pz = u2f( raster.command_buffer[16] << 8 ); + object.v[3].x = u2f( raster->command_buffer[14] << 8 ); + object.v[3].y = u2f( raster->command_buffer[15] << 8 ); + object.v[3].pz = u2f( raster->command_buffer[16] << 8 ); /* always calculate the min z and max z value */ min_z = object.v[0].pz; @@ -401,10 +398,10 @@ static void model2_3d_process_quad( UINT32 attr ) /* read in the texture information */ /* texture point data */ - if ( raster.command_buffer[0] & 0x800000 ) - tp = &raster.texture_ram[raster.command_buffer[0] & 0xFFFF]; + if ( raster->command_buffer[0] & 0x800000 ) + tp = &raster->texture_ram[raster->command_buffer[0] & 0xFFFF]; else - tp = &raster.texture_rom[raster.command_buffer[0] & 0x7FFFFF]; + tp = &raster->texture_rom[raster->command_buffer[0] & 0x7FFFFF]; object.v[0].pv = *tp++; object.v[0].pu = *tp++; @@ -416,13 +413,13 @@ static void model2_3d_process_quad( UINT32 attr ) object.v[3].pu = *tp++; /* update the address */ - raster.command_buffer[0] += 8; + raster->command_buffer[0] += 8; /* texture header data */ - if ( raster.command_buffer[1] & 0x800000 ) - th = &raster.texture_ram[raster.command_buffer[1] & 0xFFFF]; + if ( raster->command_buffer[1] & 0x800000 ) + th = &raster->texture_ram[raster->command_buffer[1] & 0xFFFF]; else - th = &raster.texture_rom[raster.command_buffer[1] & 0x7FFFFF]; + th = &raster->texture_rom[raster->command_buffer[1] & 0x7FFFFF]; object.texheader[0] = *th++; object.texheader[1] = *th++; @@ -437,10 +434,10 @@ static void model2_3d_process_quad( UINT32 attr ) tho |= -16; /* update the address */ - raster.command_buffer[1] += tho * 4; + raster->command_buffer[1] += tho * 4; /* set the luma value of this quad */ - object.luma = (raster.command_buffer[9] >> 15) & 0xFF; + object.luma = (raster->command_buffer[9] >> 15) & 0xFF; /* determine wether we can cull this quad */ cull = 0; @@ -449,7 +446,7 @@ static void model2_3d_process_quad( UINT32 attr ) if ( ((attr >> 17) & 1) == 0 ) { /* if it's the backface, cull it */ - if ( raster.command_buffer[9] & 0x00800000 ) + if ( raster->command_buffer[9] & 0x00800000 ) cull = 1; } @@ -458,7 +455,7 @@ static void model2_3d_process_quad( UINT32 attr ) cull = 1; /* if the minimum z value is bigger than the master z clip value, don't render */ - if ( (INT32)(1.0/min_z) > raster.master_z_clip ) + if ( (INT32)(1.0/min_z) > raster->master_z_clip ) cull = 1; /* if the maximum z value is < 0 then we can safely clip the entire polygon */ @@ -466,7 +463,7 @@ static void model2_3d_process_quad( UINT32 attr ) cull = 1; /* set the object's z value */ - zvalue = raster.triangle_z; + zvalue = raster->triangle_z; /* see if we need to recompute min/max z */ if ( (attr >> 10) & 3 ) @@ -480,7 +477,7 @@ static void model2_3d_process_quad( UINT32 attr ) zvalue = max_z; } - raster.triangle_z = zvalue; + raster->triangle_z = zvalue; } if ( cull == 0 ) @@ -502,10 +499,10 @@ static void model2_3d_process_quad( UINT32 attr ) triangle *ztri; /* adjust and set the object z-sort value */ - object.z = float_to_zval( zvalue + raster.z_adjust ); + object.z = float_to_zval( zvalue + raster->z_adjust ); /* get our list read to add the triangles */ - ztri = raster.tri_sorted_list[object.z]; + ztri = raster->tri_sorted_list[object.z]; if ( ztri != NULL ) { @@ -518,9 +515,9 @@ static void model2_3d_process_quad( UINT32 attr ) { triangle *tri; - tri = &raster.tri_list[raster.tri_list_index++]; + tri = &raster->tri_list[raster->tri_list_index++]; - if ( raster.tri_list_index >= MAX_TRIANGLES ) + if ( raster->tri_list_index >= MAX_TRIANGLES ) { fatalerror( "SEGA 3D: Max triangle limit exceeded\n" ); } @@ -534,14 +531,14 @@ static void model2_3d_process_quad( UINT32 attr ) tri->luma = object.luma; /* set the viewport */ - tri->viewport[0] = raster.viewport[0]; - tri->viewport[1] = raster.viewport[1]; - tri->viewport[2] = raster.viewport[2]; - tri->viewport[3] = raster.viewport[3]; + tri->viewport[0] = raster->viewport[0]; + tri->viewport[1] = raster->viewport[1]; + tri->viewport[2] = raster->viewport[2]; + tri->viewport[3] = raster->viewport[3]; /* set the center */ - tri->center[0] = raster.center[raster.center_sel][0]; - tri->center[1] = raster.center[raster.center_sel][1]; + tri->center[0] = raster->center[raster->center_sel][0]; + tri->center[1] = raster->center[raster->center_sel][1]; memcpy( &tri->v[0], &verts[0], sizeof( poly_vertex ) ); memcpy( &tri->v[1], &verts[i-1], sizeof( poly_vertex ) ); @@ -552,7 +549,7 @@ static void model2_3d_process_quad( UINT32 attr ) if ( ztri == NULL ) { - raster.tri_sorted_list[object.z] = tri; + raster->tri_sorted_list[object.z] = tri; } else { @@ -563,8 +560,8 @@ static void model2_3d_process_quad( UINT32 attr ) } /* keep around the min and max z values for this frame */ - if ( object.z < raster.min_z ) raster.min_z = object.z; - if ( object.z > raster.max_z ) raster.max_z = object.z; + if ( object.z < raster->min_z ) raster->min_z = object.z; + if ( object.z > raster->max_z ) raster->max_z = object.z; } } @@ -576,7 +573,7 @@ static void model2_3d_process_quad( UINT32 attr ) { /* reuse P0(n) and P1(n) */ for( i = 0; i < 6; i++ ) /* P0(n) -> P0(n-1) */ - raster.command_buffer[2+i] = raster.command_buffer[11+i]; /* P1(n) -> P1(n-1) */ + raster->command_buffer[2+i] = raster->command_buffer[11+i]; /* P1(n) -> P1(n-1) */ } break; @@ -584,7 +581,7 @@ static void model2_3d_process_quad( UINT32 attr ) { /* reuse P0(n-1) and P0(n) */ for( i = 0; i < 3; i++ ) - raster.command_buffer[5+i] = raster.command_buffer[11+i]; /* P0(n) -> P1(n-1) */ + raster->command_buffer[5+i] = raster->command_buffer[11+i]; /* P0(n) -> P1(n-1) */ } break; @@ -592,13 +589,13 @@ static void model2_3d_process_quad( UINT32 attr ) { /* reuse P1(n-1) and P1(n) */ for( i = 0; i < 3; i++ ) - raster.command_buffer[2+i] = raster.command_buffer[14+i]; /* P1(n) -> P1(n-1) */ + raster->command_buffer[2+i] = raster->command_buffer[14+i]; /* P1(n) -> P1(n-1) */ } break; } } -static void model2_3d_process_triangle( UINT32 attr ) +static void model2_3d_process_triangle( raster_state *raster, UINT32 attr ) { triangle object; UINT16 *th, *tp; @@ -608,24 +605,24 @@ static void model2_3d_process_triangle( UINT32 attr ) float min_z, max_z; /* extract P0(n-1) */ - object.v[1].x = u2f( raster.command_buffer[2] << 8 ); - object.v[1].y = u2f( raster.command_buffer[3] << 8 ); - object.v[1].pz = u2f( raster.command_buffer[4] << 8 ); + object.v[1].x = u2f( raster->command_buffer[2] << 8 ); + object.v[1].y = u2f( raster->command_buffer[3] << 8 ); + object.v[1].pz = u2f( raster->command_buffer[4] << 8 ); /* extract P1(n-1) */ - object.v[0].x = u2f( raster.command_buffer[5] << 8 ); - object.v[0].y = u2f( raster.command_buffer[6] << 8 ); - object.v[0].pz = u2f( raster.command_buffer[7] << 8 ); + object.v[0].x = u2f( raster->command_buffer[5] << 8 ); + object.v[0].y = u2f( raster->command_buffer[6] << 8 ); + object.v[0].pz = u2f( raster->command_buffer[7] << 8 ); /* extract P0(n) */ - object.v[2].x = u2f( raster.command_buffer[11] << 8 ); - object.v[2].y = u2f( raster.command_buffer[12] << 8 ); - object.v[2].pz = u2f( raster.command_buffer[13] << 8 ); + object.v[2].x = u2f( raster->command_buffer[11] << 8 ); + object.v[2].y = u2f( raster->command_buffer[12] << 8 ); + object.v[2].pz = u2f( raster->command_buffer[13] << 8 ); /* for triangles, the rope of P1(n) is achieved by P0(n-1) (linktype 3) */ - raster.command_buffer[14] = raster.command_buffer[11]; - raster.command_buffer[15] = raster.command_buffer[12]; - raster.command_buffer[16] = raster.command_buffer[13]; + raster->command_buffer[14] = raster->command_buffer[11]; + raster->command_buffer[15] = raster->command_buffer[12]; + raster->command_buffer[16] = raster->command_buffer[13]; /* always calculate the min z and max z values */ min_z = object.v[0].pz; @@ -639,10 +636,10 @@ static void model2_3d_process_triangle( UINT32 attr ) /* read in the texture information */ /* texture point data */ - if ( raster.command_buffer[0] & 0x800000 ) - tp = &raster.texture_ram[raster.command_buffer[0] & 0xFFFF]; + if ( raster->command_buffer[0] & 0x800000 ) + tp = &raster->texture_ram[raster->command_buffer[0] & 0xFFFF]; else - tp = &raster.texture_rom[raster.command_buffer[0] & 0x7FFFFF]; + tp = &raster->texture_rom[raster->command_buffer[0] & 0x7FFFFF]; object.v[0].pv = *tp++; object.v[0].pu = *tp++; @@ -652,13 +649,13 @@ static void model2_3d_process_triangle( UINT32 attr ) object.v[2].pu = *tp++; /* update the address */ - raster.command_buffer[0] += 6; + raster->command_buffer[0] += 6; /* texture header data */ - if ( raster.command_buffer[1] & 0x800000 ) - th = &raster.texture_ram[raster.command_buffer[1] & 0xFFFF]; + if ( raster->command_buffer[1] & 0x800000 ) + th = &raster->texture_ram[raster->command_buffer[1] & 0xFFFF]; else - th = &raster.texture_rom[raster.command_buffer[1] & 0x7FFFFF]; + th = &raster->texture_rom[raster->command_buffer[1] & 0x7FFFFF]; object.texheader[0] = *th++; object.texheader[1] = *th++; @@ -673,10 +670,10 @@ static void model2_3d_process_triangle( UINT32 attr ) tho |= -16; /* update the address */ - raster.command_buffer[1] += tho * 4; + raster->command_buffer[1] += tho * 4; /* set the luma value of this quad */ - object.luma = (raster.command_buffer[9] >> 15) & 0xFF; + object.luma = (raster->command_buffer[9] >> 15) & 0xFF; /* determine wether we can cull this quad */ cull = 0; @@ -685,7 +682,7 @@ static void model2_3d_process_triangle( UINT32 attr ) if ( ((attr >> 17) & 1) == 0 ) { /* if it's the backface, cull it */ - if ( raster.command_buffer[9] & 0x00800000 ) + if ( raster->command_buffer[9] & 0x00800000 ) cull = 1; } @@ -694,7 +691,7 @@ static void model2_3d_process_triangle( UINT32 attr ) cull = 1; /* if the minimum z value is bigger than the master z clip value, don't render */ - if ( (INT32)(1.0/min_z) > raster.master_z_clip ) + if ( (INT32)(1.0/min_z) > raster->master_z_clip ) cull = 1; /* if the maximum z value is < 0 then we can safely clip the entire polygon */ @@ -702,7 +699,7 @@ static void model2_3d_process_triangle( UINT32 attr ) cull = 1; /* set the object's z value */ - zvalue = raster.triangle_z; + zvalue = raster->triangle_z; /* see if we need to recompute min/max z */ if ( (attr >> 10) & 3 ) @@ -716,7 +713,7 @@ static void model2_3d_process_triangle( UINT32 attr ) zvalue = max_z; } - raster.triangle_z = zvalue; + raster->triangle_z = zvalue; } /* if we're not culling, do z-clip and add to out triangle list */ @@ -739,10 +736,10 @@ static void model2_3d_process_triangle( UINT32 attr ) triangle *ztri; /* adjust and set the object z-sort value */ - object.z = float_to_zval( zvalue + raster.z_adjust ); + object.z = float_to_zval( zvalue + raster->z_adjust ); /* get our list read to add the triangles */ - ztri = raster.tri_sorted_list[object.z]; + ztri = raster->tri_sorted_list[object.z]; if ( ztri != NULL ) { @@ -755,9 +752,9 @@ static void model2_3d_process_triangle( UINT32 attr ) { triangle *tri; - tri = &raster.tri_list[raster.tri_list_index++]; + tri = &raster->tri_list[raster->tri_list_index++]; - if ( raster.tri_list_index >= MAX_TRIANGLES ) + if ( raster->tri_list_index >= MAX_TRIANGLES ) { fatalerror( "SEGA 3D: Max triangle limit exceeded\n" ); } @@ -771,14 +768,14 @@ static void model2_3d_process_triangle( UINT32 attr ) tri->luma = object.luma; /* set the viewport */ - tri->viewport[0] = raster.viewport[0]; - tri->viewport[1] = raster.viewport[1]; - tri->viewport[2] = raster.viewport[2]; - tri->viewport[3] = raster.viewport[3]; + tri->viewport[0] = raster->viewport[0]; + tri->viewport[1] = raster->viewport[1]; + tri->viewport[2] = raster->viewport[2]; + tri->viewport[3] = raster->viewport[3]; /* set the center */ - tri->center[0] = raster.center[raster.center_sel][0]; - tri->center[1] = raster.center[raster.center_sel][1]; + tri->center[0] = raster->center[raster->center_sel][0]; + tri->center[1] = raster->center[raster->center_sel][1]; memcpy( &tri->v[0], &verts[0], sizeof( poly_vertex ) ); memcpy( &tri->v[1], &verts[i-1], sizeof( poly_vertex ) ); @@ -789,7 +786,7 @@ static void model2_3d_process_triangle( UINT32 attr ) if ( ztri == NULL ) { - raster.tri_sorted_list[object.z] = tri; + raster->tri_sorted_list[object.z] = tri; } else { @@ -800,8 +797,8 @@ static void model2_3d_process_triangle( UINT32 attr ) } /* keep around the min and max z values for this frame */ - if ( object.z < raster.min_z ) raster.min_z = object.z; - if ( object.z > raster.max_z ) raster.max_z = object.z; + if ( object.z < raster->min_z ) raster->min_z = object.z; + if ( object.z > raster->max_z ) raster->max_z = object.z; } } @@ -813,7 +810,7 @@ static void model2_3d_process_triangle( UINT32 attr ) { /* reuse P0(n) and P1(n) */ for( i = 0; i < 6; i++ ) /* P0(n) -> P0(n-1) */ - raster.command_buffer[2+i] = raster.command_buffer[11+i]; /* P1(n) -> P1(n-1) */ + raster->command_buffer[2+i] = raster->command_buffer[11+i]; /* P1(n) -> P1(n-1) */ } break; @@ -821,7 +818,7 @@ static void model2_3d_process_triangle( UINT32 attr ) { /* reuse P0(n-1) and P0(n) */ for( i = 0; i < 3; i++ ) - raster.command_buffer[5+i] = raster.command_buffer[11+i]; /* P0(n) -> P1(n-1) */ + raster->command_buffer[5+i] = raster->command_buffer[11+i]; /* P0(n) -> P1(n-1) */ } break; @@ -829,7 +826,7 @@ static void model2_3d_process_triangle( UINT32 attr ) { /* reuse P1(n-1) and P1(n) */ for( i = 0; i < 3; i++ ) - raster.command_buffer[2+i] = raster.command_buffer[14+i]; /* P1(n) -> P1(n-1) */ + raster->command_buffer[2+i] = raster->command_buffer[14+i]; /* P1(n) -> P1(n-1) */ } break; } @@ -926,8 +923,9 @@ static const poly_draw_scanline_func render_funcs[8] = model2_3d_render_7 /* checker = 1, textured = 1, translucent = 1 */ }; -static void model2_3d_render( bitmap_t *bitmap, triangle *tri, const rectangle *cliprect ) +static void model2_3d_render( model2_state *state, bitmap_t *bitmap, triangle *tri, const rectangle *cliprect ) { + poly_manager *poly = state->poly; poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(poly); UINT8 renderer; rectangle vp; @@ -946,6 +944,7 @@ static void model2_3d_render( bitmap_t *bitmap, triangle *tri, const rectangle * if ( vp.min_y < cliprect->min_y ) vp.min_y = cliprect->min_y; if ( vp.max_y > cliprect->max_y ) vp.max_y = cliprect->max_y; + extra->state = state; extra->lumabase = ((tri->texheader[1] & 0xFF) << 7) + ((tri->luma >> 5) ^ 0x7); extra->colorbase = (tri->texheader[3] >> 6) & 0x3FF; @@ -957,7 +956,7 @@ static void model2_3d_render( bitmap_t *bitmap, triangle *tri, const rectangle * extra->texy = 32 * (((tri->texheader[2] >> 6) & 0x1f) + ( tri->texheader[2] & 0x20 )); extra->texmirrorx = (tri->texheader[0] >> 9) & 1; extra->texmirrory = (tri->texheader[0] >> 8) & 1; - extra->texsheet = (tri->texheader[2] & 0x1000) ? model2_textureram1 : model2_textureram0; + extra->texsheet = (tri->texheader[2] & 0x1000) ? state->textureram1 : state->textureram0; tri->v[0].pz = 1.0f / (1.0f + tri->v[0].pz); tri->v[0].pu = tri->v[0].pu * tri->v[0].pz * (1.0f / 8.0f); @@ -1008,25 +1007,28 @@ static void model2_3d_project( triangle *tri ) } /* 3D Rasterizer frame start: Resets frame variables */ -static void model2_3d_frame_start( void ) +static void model2_3d_frame_start( model2_state *state ) { + raster_state *raster = state->raster; + /* reset the triangle list index */ - raster.tri_list_index = 0; + raster->tri_list_index = 0; /* reset the sorted z list */ - memset( raster.tri_sorted_list, 0, 0x10000 * sizeof( triangle * ) ); + memset( raster->tri_sorted_list, 0, 0x10000 * sizeof( triangle * ) ); /* reset the min-max sortable Z values */ - raster.min_z = 0xFFFF; - raster.max_z = 0; + raster->min_z = 0xFFFF; + raster->max_z = 0; } -static void model2_3d_frame_end( bitmap_t *bitmap, const rectangle *cliprect ) +static void model2_3d_frame_end( model2_state *state, bitmap_t *bitmap, const rectangle *cliprect ) { + raster_state *raster = state->raster; INT32 z; /* if we have nothing to render, bail */ - if ( raster.tri_list_index == 0 ) + if ( raster->tri_list_index == 0 ) return; #if DEBUG @@ -1038,30 +1040,30 @@ static void model2_3d_frame_end( bitmap_t *bitmap, const rectangle *cliprect ) if ( f ) { - for( i = 0; i < raster.tri_list_index; i++ ) + for( i = 0; i < raster->tri_list_index; i++ ) { fprintf( f, "index: %d\n", i ); - fprintf( f, "v0.x = %f, v0.y = %f, v0.z = %f\n", raster.tri_list[i].v[0].x, raster.tri_list[i].v[0].y, raster.tri_list[i].v[0].pz ); - fprintf( f, "v1.x = %f, v1.y = %f, v1.z = %f\n", raster.tri_list[i].v[1].x, raster.tri_list[i].v[1].y, raster.tri_list[i].v[1].pz ); - fprintf( f, "v2.x = %f, v2.y = %f, v2.z = %f\n", raster.tri_list[i].v[2].x, raster.tri_list[i].v[2].y, raster.tri_list[i].v[2].pz ); + fprintf( f, "v0.x = %f, v0.y = %f, v0.z = %f\n", raster->tri_list[i].v[0].x, raster->tri_list[i].v[0].y, raster->tri_list[i].v[0].pz ); + fprintf( f, "v1.x = %f, v1.y = %f, v1.z = %f\n", raster->tri_list[i].v[1].x, raster->tri_list[i].v[1].y, raster->tri_list[i].v[1].pz ); + fprintf( f, "v2.x = %f, v2.y = %f, v2.z = %f\n", raster->tri_list[i].v[2].x, raster->tri_list[i].v[2].y, raster->tri_list[i].v[2].pz ); - fprintf( f, "tri z: %04x\n", raster.tri_list[i].pz ); - fprintf( f, "texheader - 0: %04x\n", raster.tri_list[i].texheader[0] ); - fprintf( f, "texheader - 1: %04x\n", raster.tri_list[i].texheader[1] ); - fprintf( f, "texheader - 2: %04x\n", raster.tri_list[i].texheader[2] ); - fprintf( f, "texheader - 3: %04x\n", raster.tri_list[i].texheader[3] ); - fprintf( f, "luma: %02x\n", raster.tri_list[i].luma ); - fprintf( f, "vp.sx: %04x\n", raster.tri_list[i].viewport[0] ); - fprintf( f, "vp.sy: %04x\n", raster.tri_list[i].viewport[1] ); - fprintf( f, "vp.ex: %04x\n", raster.tri_list[i].viewport[2] ); - fprintf( f, "vp.ey: %04x\n", raster.tri_list[i].viewport[3] ); - fprintf( f, "vp.swx: %04x\n", raster.tri_list[i].center[0] ); - fprintf( f, "vp.swy: %04x\n", raster.tri_list[i].center[1] ); + fprintf( f, "tri z: %04x\n", raster->tri_list[i].pz ); + fprintf( f, "texheader - 0: %04x\n", raster->tri_list[i].texheader[0] ); + fprintf( f, "texheader - 1: %04x\n", raster->tri_list[i].texheader[1] ); + fprintf( f, "texheader - 2: %04x\n", raster->tri_list[i].texheader[2] ); + fprintf( f, "texheader - 3: %04x\n", raster->tri_list[i].texheader[3] ); + fprintf( f, "luma: %02x\n", raster->tri_list[i].luma ); + fprintf( f, "vp.sx: %04x\n", raster->tri_list[i].viewport[0] ); + fprintf( f, "vp.sy: %04x\n", raster->tri_list[i].viewport[1] ); + fprintf( f, "vp.ex: %04x\n", raster->tri_list[i].viewport[2] ); + fprintf( f, "vp.ey: %04x\n", raster->tri_list[i].viewport[3] ); + fprintf( f, "vp.swx: %04x\n", raster->tri_list[i].center[0] ); + fprintf( f, "vp.swy: %04x\n", raster->tri_list[i].center[1] ); fprintf( f, "\n---\n\n" ); } - fprintf( f, "min_z = %04x, max_z = %04x\n", raster.min_z, raster.max_z ); + fprintf( f, "min_z = %04x, max_z = %04x\n", raster->min_z, raster->max_z ); fclose( f ); } @@ -1069,37 +1071,37 @@ static void model2_3d_frame_end( bitmap_t *bitmap, const rectangle *cliprect ) #endif /* go through the Z levels, and render each bucket */ - for( z = raster.max_z; z >= raster.min_z; z-- ) + for( z = raster->max_z; z >= raster->min_z; z-- ) { /* see if we have items at this z level */ - if ( raster.tri_sorted_list[z] != NULL ) + if ( raster->tri_sorted_list[z] != NULL ) { /* get a pointer to the first triangle */ - triangle *tri = raster.tri_sorted_list[z]; + triangle *tri = raster->tri_sorted_list[z]; /* and loop clipping and rendering each triangle */ while( tri != NULL ) { /* project and render */ model2_3d_project( tri ); - model2_3d_render( bitmap, tri, cliprect ); + model2_3d_render( state, bitmap, tri, cliprect ); tri = (triangle *)tri->next; } } } - poly_wait(poly, "End of frame"); + poly_wait(state->poly, "End of frame"); } /* 3D Rasterizer main data input port */ -static void model2_3d_push( UINT32 input ) +static void model2_3d_push( raster_state *raster, UINT32 input ) { /* see if we have a command in progress */ - if ( raster.cur_command != 0 ) + if ( raster->cur_command != 0 ) { - raster.command_buffer[raster.command_index++] = input; + raster->command_buffer[raster->command_index++] = input; - switch( raster.cur_command ) + switch( raster->cur_command ) { case 0x00: /* NOP */ break; @@ -1109,16 +1111,16 @@ static void model2_3d_push( UINT32 input ) UINT32 attr; /* start by looking if we have the basic input data */ - if ( raster.command_index < 9 ) + if ( raster->command_index < 9 ) return; /* get the attributes */ - attr = raster.command_buffer[8]; + attr = raster->command_buffer[8]; /* see if we're done */ if ( (attr & 3) == 0 ) { - raster.cur_command = 0; + raster->cur_command = 0; return; } @@ -1126,26 +1128,26 @@ static void model2_3d_push( UINT32 input ) if ( attr & 1 ) { /* it's a quad, wait for the rest of the points */ - if ( raster.command_index < 17 ) + if ( raster->command_index < 17 ) return; /* we have a full quad info, fill up our quad structure */ - model2_3d_process_quad( attr ); + model2_3d_process_quad( raster, attr ); /* back up and wait for more data */ - raster.command_index = 8; + raster->command_index = 8; } else { /* it's a triangle, wait for the rest of the point */ - if ( raster.command_index < 14 ) + if ( raster->command_index < 14 ) return; /* we have a full quad info, fill up our quad structure */ - model2_3d_process_triangle( attr ); + model2_3d_process_triangle( raster, attr ); /* back up and wait for more data */ - raster.command_index = 8; + raster->command_index = 8; } } break; @@ -1155,105 +1157,105 @@ static void model2_3d_push( UINT32 input ) UINT32 i; /* make sure we have all the data */ - if ( raster.command_index < 6 ) + if ( raster->command_index < 6 ) return; /* coordinates are 12 bit signed */ /* extract the viewport start x */ - raster.viewport[0] = (raster.command_buffer[0] >> 12) & 0xFFF; + raster->viewport[0] = (raster->command_buffer[0] >> 12) & 0xFFF; - if ( raster.viewport[0] & 0x800 ) - raster.viewport[0] = -( 0x800 - (raster.viewport[0] & 0x7FF) ); + if ( raster->viewport[0] & 0x800 ) + raster->viewport[0] = -( 0x800 - (raster->viewport[0] & 0x7FF) ); /* extract the viewport start y */ - raster.viewport[1] = raster.command_buffer[0] & 0xFFF; + raster->viewport[1] = raster->command_buffer[0] & 0xFFF; - if ( raster.viewport[1] & 0x800 ) - raster.viewport[1] = -( 0x800 - (raster.viewport[1] & 0x7FF) ); + if ( raster->viewport[1] & 0x800 ) + raster->viewport[1] = -( 0x800 - (raster->viewport[1] & 0x7FF) ); /* extract the viewport end x */ - raster.viewport[2] = (raster.command_buffer[1] >> 12) & 0xFFF; + raster->viewport[2] = (raster->command_buffer[1] >> 12) & 0xFFF; - if ( raster.viewport[2] & 0x800 ) - raster.viewport[2] = -( 0x800 - (raster.viewport[2] & 0x7FF) ); + if ( raster->viewport[2] & 0x800 ) + raster->viewport[2] = -( 0x800 - (raster->viewport[2] & 0x7FF) ); /* extract the viewport end y */ - raster.viewport[3] = raster.command_buffer[1] & 0xFFF; + raster->viewport[3] = raster->command_buffer[1] & 0xFFF; - if ( raster.viewport[3] & 0x800 ) - raster.viewport[3] = -( 0x800 - (raster.viewport[3] & 0x7FF) ); + if ( raster->viewport[3] & 0x800 ) + raster->viewport[3] = -( 0x800 - (raster->viewport[3] & 0x7FF) ); /* extract the centers */ for( i = 0; i < 4; i++ ) { /* center x */ - raster.center[i][0] = (raster.command_buffer[2+i] >> 12) & 0xFFF; + raster->center[i][0] = (raster->command_buffer[2+i] >> 12) & 0xFFF; - if ( raster.center[i][0] & 0x800 ) - raster.center[i][0] = -( 0x800 - (raster.center[i][0] & 0x7FF) ); + if ( raster->center[i][0] & 0x800 ) + raster->center[i][0] = -( 0x800 - (raster->center[i][0] & 0x7FF) ); /* center y */ - raster.center[i][1] = raster.command_buffer[2+i] & 0xFFF; + raster->center[i][1] = raster->command_buffer[2+i] & 0xFFF; - if ( raster.center[i][1] & 0x800 ) - raster.center[i][1] = -( 0x800 - (raster.center[i][1] & 0x7FF) ); + if ( raster->center[i][1] & 0x800 ) + raster->center[i][1] = -( 0x800 - (raster->center[i][1] & 0x7FF) ); } /* done with this command */ - raster.cur_command = 0; + raster->cur_command = 0; } break; case 0x04: /* Texture/Log Data write */ { /* make sure we have enough data */ - if ( raster.command_index < 2 ) + if ( raster->command_index < 2 ) return; /* see if the count is non-zero */ - if ( raster.command_buffer[1] > 0 ) + if ( raster->command_buffer[1] > 0 ) { /* see if we have data available */ - if ( raster.command_index >= 3 ) + if ( raster->command_index >= 3 ) { /* get the address */ - UINT32 address = raster.command_buffer[0]; + UINT32 address = raster->command_buffer[0]; /* do the write */ if ( address & 0x800000 ) - raster.texture_ram[address&0xFFFF] = raster.command_buffer[2]; + raster->texture_ram[address&0xFFFF] = raster->command_buffer[2]; else - raster.log_ram[address&0xFFFF] = raster.command_buffer[2]; + raster->log_ram[address&0xFFFF] = raster->command_buffer[2]; /* increment the address and decrease the count */ - raster.command_buffer[0]++; - raster.command_buffer[1]--; + raster->command_buffer[0]++; + raster->command_buffer[1]--; /* decrease the index, so we keep placing data in the same slot */ - raster.command_index--; + raster->command_index--; } } /* see if we're done with this command */ - if ( raster.command_buffer[1] == 0 ) - raster.cur_command = 0; + if ( raster->command_buffer[1] == 0 ) + raster->cur_command = 0; } break; case 0x08: /* ZSort mode */ { /* save the zsort mode value */ - raster.z_adjust = u2f( raster.command_buffer[0] << 8 ); + raster->z_adjust = u2f( raster->command_buffer[0] << 8 ); /* done with this command */ - raster.cur_command = 0; + raster->cur_command = 0; } break; default: { - fatalerror( "SEGA 3D: Unknown rasterizer command %08x\n", raster.cur_command ); + fatalerror( "SEGA 3D: Unknown rasterizer command %08x\n", raster->cur_command ); } break; } @@ -1261,20 +1263,20 @@ static void model2_3d_push( UINT32 input ) else { /* new command */ - raster.cur_command = input & 0x0F; - raster.command_index = 0; + raster->cur_command = input & 0x0F; + raster->command_index = 0; /* see if it's object data */ - if ( raster.cur_command == 1 ) + if ( raster->cur_command == 1 ) { /* extract reverse bit */ - raster.reverse = (input >> 4) & 1; + raster->reverse = (input >> 4) & 1; /* extract center select */ - raster.center_sel = ( input >> 6 ) & 3; + raster->center_sel = ( input >> 6 ) & 3; /* reset the triangle z value */ - raster.triangle_z = 0; + raster->triangle_z = 0; } } } @@ -1289,21 +1291,21 @@ static void model2_3d_push( UINT32 input ) * *******************************************/ -typedef struct +struct _geo_state { + raster_state * raster; UINT32 mode; /* bit 0 = Enable Specular, bit 1 = Calculate Normals */ UINT32 * polygon_rom; /* Polygon ROM pointer */ - UINT32 * polygon_ram0; /* Fast Polygon RAM pointer */ - UINT32 * polygon_ram1; /* Slow Polygon RAM pointer */ float matrix[12]; /* Current Transformation Matrix */ poly_vertex focus; /* Focus (x,y) */ poly_vertex light; /* Light Vector */ float lod; /* LOD */ float coef_table[32]; /* Distane Coefficient table */ texture_parameter texture_parameters[32]; /* Texture parameters */ -} geo_state; + UINT32 polygon_ram0[0x8000]; /* Fast Polygon RAM pointer */ + UINT32 polygon_ram1[0x8000]; /* Slow Polygon RAM pointer */ +}; -static geo_state geo; /******************************************* * @@ -1313,11 +1315,11 @@ static geo_state geo; static void geo_init( running_machine *machine, UINT32 *polygon_rom ) { - memset( &geo, 0, sizeof( geo_state ) ); + model2_state *state = machine->driver_data(); + state->geo = auto_alloc_clear(machine, geo_state); - geo.polygon_rom = polygon_rom; - geo.polygon_ram0 = auto_alloc_array(machine, UINT32, 0x8000); - geo.polygon_ram1 = auto_alloc_array(machine, UINT32, 0x8000); + state->geo->raster = state->raster; + state->geo->polygon_rom = polygon_rom; } /******************************************* @@ -1327,8 +1329,9 @@ static void geo_init( running_machine *machine, UINT32 *polygon_rom ) *******************************************/ /* Parse Polygons: Normals Present, No Specular case */ -static void geo_parse_np_ns( UINT32 *input, UINT32 count ) +static void geo_parse_np_ns( geo_state *geo, UINT32 *input, UINT32 count ) { + raster_state *raster = geo->raster; poly_vertex point, normal; UINT32 attr, i; @@ -1338,16 +1341,16 @@ static void geo_parse_np_ns( UINT32 *input, UINT32 count ) point.pz = u2f( *input++ ); /* transform with the current matrix */ - transform_point( &point, geo.matrix ); + transform_point( &point, geo->matrix ); /* apply focus */ - point.x *= geo.focus.x; - point.y *= geo.focus.y; + point.x *= geo->focus.x; + point.y *= geo->focus.y; /* push it to the 3d rasterizer */ - model2_3d_push( f2u(point.x) >> 8 ); - model2_3d_push( f2u(point.y) >> 8 ); - model2_3d_push( f2u(point.pz) >> 8 ); + model2_3d_push( raster, f2u(point.x) >> 8 ); + model2_3d_push( raster, f2u(point.y) >> 8 ); + model2_3d_push( raster, f2u(point.pz) >> 8 ); /* read the 2nd point */ point.x = u2f( *input++ ); @@ -1355,16 +1358,16 @@ static void geo_parse_np_ns( UINT32 *input, UINT32 count ) point.pz = u2f( *input++ ); /* transform with the current matrix */ - transform_point( &point, geo.matrix ); + transform_point( &point, geo->matrix ); /* apply focus */ - point.x *= geo.focus.x; - point.y *= geo.focus.y; + point.x *= geo->focus.x; + point.y *= geo->focus.y; /* push it to the 3d rasterizer */ - model2_3d_push( f2u(point.x) >> 8 ); - model2_3d_push( f2u(point.y) >> 8 ); - model2_3d_push( f2u(point.pz) >> 8 ); + model2_3d_push( raster, f2u(point.x) >> 8 ); + model2_3d_push( raster, f2u(point.y) >> 8 ); + model2_3d_push( raster, f2u(point.pz) >> 8 ); /* loop through the following links */ for( i = 0; i < count; i++ ) @@ -1373,7 +1376,7 @@ static void geo_parse_np_ns( UINT32 *input, UINT32 count ) attr = *input++; /* push to the 3d rasterizer */ - model2_3d_push( attr & 0x0003FFFF ); + model2_3d_push( raster, attr & 0x0003FFFF ); /* read in the normal */ normal.x = u2f(*input++); @@ -1381,7 +1384,7 @@ static void geo_parse_np_ns( UINT32 *input, UINT32 count ) normal.pz = u2f(*input++); /* transform with the current matrix */ - transform_vector( &normal, geo.matrix ); + transform_vector( &normal, geo->matrix ); if ( (attr & 3) != 0 ) /* quad or triangle */ { @@ -1396,24 +1399,24 @@ static void geo_parse_np_ns( UINT32 *input, UINT32 count ) point.pz = u2f( *input++ ); /* transform with the current matrix */ - transform_point( &point, geo.matrix ); + transform_point( &point, geo->matrix ); /* calculate the dot product of the normal and the light vector */ - dotl = dot_product( &normal, &geo.light ); + dotl = dot_product( &normal, &geo->light ); /* calculate the dot product of the normal and the point */ dotp = dot_product( &normal, &point ); /* apply focus */ - point.x *= geo.focus.x; - point.y *= geo.focus.y; + point.x *= geo->focus.x; + point.y *= geo->focus.y; /* determine wether this is the front or the back of the polygon */ face = 0x100; /* rear */ if ( dotp >= 0 ) face = 0; /* front */ /* get the texture parameters */ - texparam = &geo.texture_parameters[(attr>>18) & 0x1f]; + texparam = &geo->texture_parameters[(attr>>18) & 0x1f]; /* calculate luminance */ if ( (dotl * dotp) < 0 ) luminance = 0; @@ -1429,17 +1432,17 @@ static void geo_parse_np_ns( UINT32 *input, UINT32 count ) luma += face; /* extract distance coefficient */ - coef = geo.coef_table[attr>>27]; + coef = geo->coef_table[attr>>27]; /* calculate texture level of detail */ - distance = coef * fabs( dotp ) * geo.lod; + distance = coef * fabs( dotp ) * geo->lod; /* push to the 3d rasterizer */ - model2_3d_push( luma << 15 ); - model2_3d_push( f2u(distance) >> 8 ); - model2_3d_push( f2u(point.x) >> 8 ); - model2_3d_push( f2u(point.y) >> 8 ); - model2_3d_push( f2u(point.pz) >> 8 ); + model2_3d_push( raster, luma << 15 ); + model2_3d_push( raster, f2u(distance) >> 8 ); + model2_3d_push( raster, f2u(point.x) >> 8 ); + model2_3d_push( raster, f2u(point.y) >> 8 ); + model2_3d_push( raster, f2u(point.pz) >> 8 ); /* if it's a quad, push one more point */ if ( attr & 1 ) @@ -1450,16 +1453,16 @@ static void geo_parse_np_ns( UINT32 *input, UINT32 count ) point.pz = u2f( *input++ ); /* transform with the current matrix */ - transform_point( &point, geo.matrix ); + transform_point( &point, geo->matrix ); /* apply focus */ - point.x *= geo.focus.x; - point.y *= geo.focus.y; + point.x *= geo->focus.x; + point.y *= geo->focus.y; /* push to the 3d rasterizer */ - model2_3d_push( f2u(point.x) >> 8 ); - model2_3d_push( f2u(point.y) >> 8 ); - model2_3d_push( f2u(point.pz) >> 8 ); + model2_3d_push( raster, f2u(point.x) >> 8 ); + model2_3d_push( raster, f2u(point.y) >> 8 ); + model2_3d_push( raster, f2u(point.pz) >> 8 ); } else /* triangle */ { @@ -1474,12 +1477,13 @@ static void geo_parse_np_ns( UINT32 *input, UINT32 count ) } /* notify the 3d rasterizer we're done */ - model2_3d_push( 0 ); + model2_3d_push( raster, 0 ); } /* Parse Polygons: Normals Present, Specular case */ -static void geo_parse_np_s( UINT32 *input, UINT32 count ) +static void geo_parse_np_s( geo_state *geo, UINT32 *input, UINT32 count ) { + raster_state *raster = geo->raster; poly_vertex point, normal; UINT32 attr, i; @@ -1489,16 +1493,16 @@ static void geo_parse_np_s( UINT32 *input, UINT32 count ) point.pz = u2f( *input++ ); /* transform with the current matrix */ - transform_point( &point, geo.matrix ); + transform_point( &point, geo->matrix ); /* apply focus */ - point.x *= geo.focus.x; - point.y *= geo.focus.y; + point.x *= geo->focus.x; + point.y *= geo->focus.y; /* push it to the 3d rasterizer */ - model2_3d_push( f2u(point.x) >> 8 ); - model2_3d_push( f2u(point.y) >> 8 ); - model2_3d_push( f2u(point.pz) >> 8 ); + model2_3d_push( raster, f2u(point.x) >> 8 ); + model2_3d_push( raster, f2u(point.y) >> 8 ); + model2_3d_push( raster, f2u(point.pz) >> 8 ); /* read the 2nd point */ point.x = u2f( *input++ ); @@ -1506,16 +1510,16 @@ static void geo_parse_np_s( UINT32 *input, UINT32 count ) point.pz = u2f( *input++ ); /* transform with the current matrix */ - transform_point( &point, geo.matrix ); + transform_point( &point, geo->matrix ); /* apply focus */ - point.x *= geo.focus.x; - point.y *= geo.focus.y; + point.x *= geo->focus.x; + point.y *= geo->focus.y; /* push it to the 3d rasterizer */ - model2_3d_push( f2u(point.x) >> 8 ); - model2_3d_push( f2u(point.y) >> 8 ); - model2_3d_push( f2u(point.pz) >> 8 ); + model2_3d_push( raster, f2u(point.x) >> 8 ); + model2_3d_push( raster, f2u(point.y) >> 8 ); + model2_3d_push( raster, f2u(point.pz) >> 8 ); /* loop through the following links */ for( i = 0; i < count; i++ ) @@ -1524,7 +1528,7 @@ static void geo_parse_np_s( UINT32 *input, UINT32 count ) attr = *input++; /* push to the 3d rasterizer */ - model2_3d_push( attr & 0x0003FFFF ); + model2_3d_push( raster, attr & 0x0003FFFF ); /* read in the normal */ normal.x = u2f(*input++); @@ -1532,7 +1536,7 @@ static void geo_parse_np_s( UINT32 *input, UINT32 count ) normal.pz = u2f(*input++); /* transform with the current matrix */ - transform_vector( &normal, geo.matrix ); + transform_vector( &normal, geo->matrix ); if ( (attr & 3) != 0 ) /* quad or triangle */ { @@ -1547,30 +1551,30 @@ static void geo_parse_np_s( UINT32 *input, UINT32 count ) point.pz = u2f( *input++ ); /* transform with the current matrix */ - transform_point( &point, geo.matrix ); + transform_point( &point, geo->matrix ); /* calculate the dot product of the normal and the light vector */ - dotl = dot_product( &normal, &geo.light ); + dotl = dot_product( &normal, &geo->light ); /* calculate the dot product of the normal and the point */ dotp = dot_product( &normal, &point ); /* apply focus */ - point.x *= geo.focus.x; - point.y *= geo.focus.y; + point.x *= geo->focus.x; + point.y *= geo->focus.y; /* determine wether this is the front or the back of the polygon */ face = 0x100; /* rear */ if ( dotp >= 0 ) face = 0; /* front */ /* get the texture parameters */ - texparam = &geo.texture_parameters[(attr>>18) & 0x1f]; + texparam = &geo->texture_parameters[(attr>>18) & 0x1f]; /* calculate luminance and specular */ if ( (dotl * dotp) < 0 ) luminance = 0; else luminance = fabs( dotl ); - specular = ((2*dotl) * normal.pz) - geo.light.pz; + specular = ((2*dotl) * normal.pz) - geo->light.pz; if ( specular < 0 ) specular = 0; if ( texparam->specular_control == 0 ) specular = 0; if ( (texparam->specular_control >> 1) != 0 ) specular *= specular; @@ -1589,17 +1593,17 @@ static void geo_parse_np_s( UINT32 *input, UINT32 count ) luma += face; /* extract distance coefficient */ - coef = geo.coef_table[attr>>27]; + coef = geo->coef_table[attr>>27]; /* calculate texture level of detail */ - distance = coef * fabs( dotp ) * geo.lod; + distance = coef * fabs( dotp ) * geo->lod; /* push to the 3d rasterizer */ - model2_3d_push( luma << 15 ); - model2_3d_push( f2u(distance) >> 8 ); - model2_3d_push( f2u(point.x) >> 8 ); - model2_3d_push( f2u(point.y) >> 8 ); - model2_3d_push( f2u(point.pz) >> 8 ); + model2_3d_push( raster, luma << 15 ); + model2_3d_push( raster, f2u(distance) >> 8 ); + model2_3d_push( raster, f2u(point.x) >> 8 ); + model2_3d_push( raster, f2u(point.y) >> 8 ); + model2_3d_push( raster, f2u(point.pz) >> 8 ); /* if it's a quad, push one more point */ if ( attr & 1 ) @@ -1610,16 +1614,16 @@ static void geo_parse_np_s( UINT32 *input, UINT32 count ) point.pz = u2f( *input++ ); /* transform with the current matrix */ - transform_point( &point, geo.matrix ); + transform_point( &point, geo->matrix ); /* apply focus */ - point.x *= geo.focus.x; - point.y *= geo.focus.y; + point.x *= geo->focus.x; + point.y *= geo->focus.y; /* push to the 3d rasterizer */ - model2_3d_push( f2u(point.x) >> 8 ); - model2_3d_push( f2u(point.y) >> 8 ); - model2_3d_push( f2u(point.pz) >> 8 ); + model2_3d_push( raster, f2u(point.x) >> 8 ); + model2_3d_push( raster, f2u(point.y) >> 8 ); + model2_3d_push( raster, f2u(point.pz) >> 8 ); } else /* triangle */ { @@ -1634,12 +1638,13 @@ static void geo_parse_np_s( UINT32 *input, UINT32 count ) } /* notify the 3d rasterizer we're done */ - model2_3d_push( 0 ); + model2_3d_push( raster, 0 ); } /* Parse Polygons: No Normals, No Specular case */ -static void geo_parse_nn_ns( UINT32 *input, UINT32 count ) +static void geo_parse_nn_ns( geo_state *geo, UINT32 *input, UINT32 count ) { + raster_state *raster = geo->raster; poly_vertex point, normal, p0, p1, p2, p3; UINT32 attr, i; @@ -1649,19 +1654,19 @@ static void geo_parse_nn_ns( UINT32 *input, UINT32 count ) point.pz = u2f( *input++ ); /* transform with the current matrix */ - transform_point( &point, geo.matrix ); + transform_point( &point, geo->matrix ); /* save for normal calculation */ p0.x = point.x; p0.y = point.y; p0.pz = point.pz; /* apply focus */ - point.x *= geo.focus.x; - point.y *= geo.focus.y; + point.x *= geo->focus.x; + point.y *= geo->focus.y; /* push it to the 3d rasterizer */ - model2_3d_push( f2u(point.x) >> 8 ); - model2_3d_push( f2u(point.y) >> 8 ); - model2_3d_push( f2u(point.pz) >> 8 ); + model2_3d_push( raster, f2u(point.x) >> 8 ); + model2_3d_push( raster, f2u(point.y) >> 8 ); + model2_3d_push( raster, f2u(point.pz) >> 8 ); /* read the 2nd point */ point.x = u2f( *input++ ); @@ -1669,19 +1674,19 @@ static void geo_parse_nn_ns( UINT32 *input, UINT32 count ) point.pz = u2f( *input++ ); /* transform with the current matrix */ - transform_point( &point, geo.matrix ); + transform_point( &point, geo->matrix ); /* save for normal calculation */ p1.x = point.x; p1.y = point.y; p1.pz = point.pz; /* apply focus */ - point.x *= geo.focus.x; - point.y *= geo.focus.y; + point.x *= geo->focus.x; + point.y *= geo->focus.y; /* push it to the 3d rasterizer */ - model2_3d_push( f2u(point.x) >> 8 ); - model2_3d_push( f2u(point.y) >> 8 ); - model2_3d_push( f2u(point.pz) >> 8 ); + model2_3d_push( raster, f2u(point.x) >> 8 ); + model2_3d_push( raster, f2u(point.y) >> 8 ); + model2_3d_push( raster, f2u(point.pz) >> 8 ); /* skip 4 */ input += 4; @@ -1693,7 +1698,7 @@ static void geo_parse_nn_ns( UINT32 *input, UINT32 count ) attr = *input++; /* push to the 3d rasterizer */ - model2_3d_push( attr & 0x0003FFFF ); + model2_3d_push( raster, attr & 0x0003FFFF ); if ( (attr & 3) != 0 ) /* quad or triangle */ { @@ -1708,7 +1713,7 @@ static void geo_parse_nn_ns( UINT32 *input, UINT32 count ) point.pz = u2f( *input++ ); /* transform with the current matrix */ - transform_point( &point, geo.matrix ); + transform_point( &point, geo->matrix ); /* save for normal calculation */ p2.x = point.x; p2.y = point.y; p2.pz = point.pz; @@ -1720,21 +1725,21 @@ static void geo_parse_nn_ns( UINT32 *input, UINT32 count ) normalize_vector( &normal ); /* calculate the dot product of the normal and the light vector */ - dotl = dot_product( &normal, &geo.light ); + dotl = dot_product( &normal, &geo->light ); /* calculate the dot product of the normal and the point */ dotp = dot_product( &normal, &point ); /* apply focus */ - point.x *= geo.focus.x; - point.y *= geo.focus.y; + point.x *= geo->focus.x; + point.y *= geo->focus.y; /* determine wether this is the front or the back of the polygon */ face = 0x100; /* rear */ if ( dotp >= 0 ) face = 0; /* front */ /* get the texture parameters */ - texparam = &geo.texture_parameters[(attr>>18) & 0x1f]; + texparam = &geo->texture_parameters[(attr>>18) & 0x1f]; /* calculate luminance */ if ( (dotl * dotp) < 0 ) luminance = 0; @@ -1750,17 +1755,17 @@ static void geo_parse_nn_ns( UINT32 *input, UINT32 count ) luma += face; /* extract distance coefficient */ - coef = geo.coef_table[attr>>27]; + coef = geo->coef_table[attr>>27]; /* calculate texture level of detail */ - distance = coef * fabs( dotp ) * geo.lod; + distance = coef * fabs( dotp ) * geo->lod; /* push to the 3d rasterizer */ - model2_3d_push( luma << 15 ); - model2_3d_push( f2u(distance) >> 8 ); - model2_3d_push( f2u(point.x) >> 8 ); - model2_3d_push( f2u(point.y) >> 8 ); - model2_3d_push( f2u(point.pz) >> 8 ); + model2_3d_push( raster, luma << 15 ); + model2_3d_push( raster, f2u(distance) >> 8 ); + model2_3d_push( raster, f2u(point.x) >> 8 ); + model2_3d_push( raster, f2u(point.y) >> 8 ); + model2_3d_push( raster, f2u(point.pz) >> 8 ); /* if it's a quad, push one more point */ if ( attr & 1 ) @@ -1771,19 +1776,19 @@ static void geo_parse_nn_ns( UINT32 *input, UINT32 count ) point.pz = u2f( *input++ ); /* transform with the current matrix */ - transform_point( &point, geo.matrix ); + transform_point( &point, geo->matrix ); /* save for normal calculation */ p3.x = point.x; p3.y = point.y; p3.pz = point.pz; /* apply focus */ - point.x *= geo.focus.x; - point.y *= geo.focus.y; + point.x *= geo->focus.x; + point.y *= geo->focus.y; /* push to the 3d rasterizer */ - model2_3d_push( f2u(point.x) >> 8 ); - model2_3d_push( f2u(point.y) >> 8 ); - model2_3d_push( f2u(point.pz) >> 8 ); + model2_3d_push( raster, f2u(point.x) >> 8 ); + model2_3d_push( raster, f2u(point.y) >> 8 ); + model2_3d_push( raster, f2u(point.pz) >> 8 ); } else { @@ -1828,12 +1833,13 @@ static void geo_parse_nn_ns( UINT32 *input, UINT32 count ) } /* notify the 3d rasterizer we're done */ - model2_3d_push( 0 ); + model2_3d_push( raster, 0 ); } /* Parse Polygons: No Normals, Specular case */ -static void geo_parse_nn_s( UINT32 *input, UINT32 count ) +static void geo_parse_nn_s( geo_state *geo, UINT32 *input, UINT32 count ) { + raster_state *raster = geo->raster; poly_vertex point, normal, p0, p1, p2, p3; UINT32 attr, i; @@ -1843,19 +1849,19 @@ static void geo_parse_nn_s( UINT32 *input, UINT32 count ) point.pz = u2f( *input++ ); /* transform with the current matrix */ - transform_point( &point, geo.matrix ); + transform_point( &point, geo->matrix ); /* save for normal calculation */ p0.x = point.x; p0.y = point.y; p0.pz = point.pz; /* apply focus */ - point.x *= geo.focus.x; - point.y *= geo.focus.y; + point.x *= geo->focus.x; + point.y *= geo->focus.y; /* push it to the 3d rasterizer */ - model2_3d_push( f2u(point.x) >> 8 ); - model2_3d_push( f2u(point.y) >> 8 ); - model2_3d_push( f2u(point.pz) >> 8 ); + model2_3d_push( raster, f2u(point.x) >> 8 ); + model2_3d_push( raster, f2u(point.y) >> 8 ); + model2_3d_push( raster, f2u(point.pz) >> 8 ); /* read the 2nd point */ point.x = u2f( *input++ ); @@ -1863,19 +1869,19 @@ static void geo_parse_nn_s( UINT32 *input, UINT32 count ) point.pz = u2f( *input++ ); /* transform with the current matrix */ - transform_point( &point, geo.matrix ); + transform_point( &point, geo->matrix ); /* save for normal calculation */ p1.x = point.x; p1.y = point.y; p1.pz = point.pz; /* apply focus */ - point.x *= geo.focus.x; - point.y *= geo.focus.y; + point.x *= geo->focus.x; + point.y *= geo->focus.y; /* push it to the 3d rasterizer */ - model2_3d_push( f2u(point.x) >> 8 ); - model2_3d_push( f2u(point.y) >> 8 ); - model2_3d_push( f2u(point.pz) >> 8 ); + model2_3d_push( raster, f2u(point.x) >> 8 ); + model2_3d_push( raster, f2u(point.y) >> 8 ); + model2_3d_push( raster, f2u(point.pz) >> 8 ); /* skip 4 */ input += 4; @@ -1887,7 +1893,7 @@ static void geo_parse_nn_s( UINT32 *input, UINT32 count ) attr = *input++; /* push to the 3d rasterizer */ - model2_3d_push( attr & 0x0003FFFF ); + model2_3d_push( raster, attr & 0x0003FFFF ); if ( (attr & 3) != 0 ) /* quad or triangle */ { @@ -1902,7 +1908,7 @@ static void geo_parse_nn_s( UINT32 *input, UINT32 count ) point.pz = u2f( *input++ ); /* transform with the current matrix */ - transform_point( &point, geo.matrix ); + transform_point( &point, geo->matrix ); /* save for normal calculation */ p2.x = point.x; p2.y = point.y; p2.pz = point.pz; @@ -1914,27 +1920,27 @@ static void geo_parse_nn_s( UINT32 *input, UINT32 count ) normalize_vector( &normal ); /* calculate the dot product of the normal and the light vector */ - dotl = dot_product( &normal, &geo.light ); + dotl = dot_product( &normal, &geo->light ); /* calculate the dot product of the normal and the point */ dotp = dot_product( &normal, &point ); /* apply focus */ - point.x *= geo.focus.x; - point.y *= geo.focus.y; + point.x *= geo->focus.x; + point.y *= geo->focus.y; /* determine wether this is the front or the back of the polygon */ face = 0x100; /* rear */ if ( dotp >= 0 ) face = 0; /* front */ /* get the texture parameters */ - texparam = &geo.texture_parameters[(attr>>18) & 0x1f]; + texparam = &geo->texture_parameters[(attr>>18) & 0x1f]; /* calculate luminance and specular */ if ( (dotl * dotp) < 0 ) luminance = 0; else luminance = fabs( dotl ); - specular = ((2*dotl) * normal.pz) - geo.light.pz; + specular = ((2*dotl) * normal.pz) - geo->light.pz; if ( specular < 0 ) specular = 0; if ( texparam->specular_control == 0 ) specular = 0; if ( (texparam->specular_control >> 1) != 0 ) specular *= specular; @@ -1953,17 +1959,17 @@ static void geo_parse_nn_s( UINT32 *input, UINT32 count ) luma += face; /* extract distance coefficient */ - coef = geo.coef_table[attr>>27]; + coef = geo->coef_table[attr>>27]; /* calculate texture level of detail */ - distance = coef * fabs( dotp ) * geo.lod; + distance = coef * fabs( dotp ) * geo->lod; /* push to the 3d rasterizer */ - model2_3d_push( luma << 15 ); - model2_3d_push( f2u(distance) >> 8 ); - model2_3d_push( f2u(point.x) >> 8 ); - model2_3d_push( f2u(point.y) >> 8 ); - model2_3d_push( f2u(point.pz) >> 8 ); + model2_3d_push( raster, luma << 15 ); + model2_3d_push( raster, f2u(distance) >> 8 ); + model2_3d_push( raster, f2u(point.x) >> 8 ); + model2_3d_push( raster, f2u(point.y) >> 8 ); + model2_3d_push( raster, f2u(point.pz) >> 8 ); /* if it's a quad, push one more point */ if ( attr & 1 ) @@ -1974,19 +1980,19 @@ static void geo_parse_nn_s( UINT32 *input, UINT32 count ) point.pz = u2f( *input++ ); /* transform with the current matrix */ - transform_point( &point, geo.matrix ); + transform_point( &point, geo->matrix ); /* save for normal calculation */ p3.x = point.x; p3.y = point.y; p3.pz = point.pz; /* apply focus */ - point.x *= geo.focus.x; - point.y *= geo.focus.y; + point.x *= geo->focus.x; + point.y *= geo->focus.y; /* push to the 3d rasterizer */ - model2_3d_push( f2u(point.x) >> 8 ); - model2_3d_push( f2u(point.y) >> 8 ); - model2_3d_push( f2u(point.pz) >> 8 ); + model2_3d_push( raster, f2u(point.x) >> 8 ); + model2_3d_push( raster, f2u(point.y) >> 8 ); + model2_3d_push( raster, f2u(point.pz) >> 8 ); } else { @@ -2031,7 +2037,7 @@ static void geo_parse_nn_s( UINT32 *input, UINT32 count ) } /* notify the 3d rasterizer we're done */ - model2_3d_push( 0 ); + model2_3d_push( raster, 0 ); } /******************************************* @@ -2041,17 +2047,20 @@ static void geo_parse_nn_s( UINT32 *input, UINT32 count ) *******************************************/ /* Command 00: NOP */ -static UINT32 * geo_nop( UINT32 opcode, UINT32 *input ) +static UINT32 * geo_nop( geo_state *geo, UINT32 opcode, UINT32 *input ) { + raster_state *raster = geo->raster; + /* push the opcode to the 3d rasterizer */ - model2_3d_push( opcode >> 23 ); + model2_3d_push( raster, opcode >> 23 ); return input; } /* Command 01: Object Data */ -static UINT32 * geo_object_data( UINT32 opcode, UINT32 *input ) +static UINT32 * geo_object_data( geo_state *geo, UINT32 opcode, UINT32 *input ) { + raster_state *raster = geo->raster; UINT32 tpa = *input++; /* Texture Point Address */ UINT32 tha = *input++; /* Texture Header Address */ UINT32 oba = *input++; /* Object Address */ @@ -2060,40 +2069,40 @@ static UINT32 * geo_object_data( UINT32 opcode, UINT32 *input ) UINT32 *obp; /* Object Pointer */ /* push the initial set of data to the 3d rasterizer */ - model2_3d_push( opcode >> 23 ); - model2_3d_push( tpa ); - model2_3d_push( tha ); + model2_3d_push( raster, opcode >> 23 ); + model2_3d_push( raster, tpa ); + model2_3d_push( raster, tha ); /* select where we're reading polygon information from */ if ( oba & 0x01000000 ) { /* Fast polygon RAM */ - obp = &geo.polygon_ram0[oba & 0x7FFF]; + obp = &geo->polygon_ram0[oba & 0x7FFF]; } else if ( oba & 0x00800000 ) { /* Polygon ROM */ - obp = &geo.polygon_rom[oba & 0x7FFFFF]; + obp = &geo->polygon_rom[oba & 0x7FFFFF]; } else { /* Slow Polygon RAM */ - obp = &geo.polygon_ram1[oba & 0x7FFF]; + obp = &geo->polygon_ram1[oba & 0x7FFF]; } - switch( geo.mode & 3 ) + switch( geo->mode & 3 ) { /* Normals present, No Specular */ - case 0: geo_parse_np_ns( obp, obc ); break; + case 0: geo_parse_np_ns( geo, obp, obc ); break; /* Normals present, Specular */ - case 1: geo_parse_np_s( obp, obc ); break; + case 1: geo_parse_np_s( geo, obp, obc ); break; /* No Normals present, No Specular */ - case 2: geo_parse_nn_ns( obp, obc ); break; + case 2: geo_parse_nn_ns( geo, obp, obc ); break; /* No Normals present, Specular */ - case 3: geo_parse_nn_s( obp, obc ); break; + case 3: geo_parse_nn_s( geo, obp, obc ); break; } /* move by 4 parameters */ @@ -2101,25 +2110,26 @@ static UINT32 * geo_object_data( UINT32 opcode, UINT32 *input ) } /* Command 02: Direct Data */ -static UINT32 * geo_direct_data( UINT32 opcode, UINT32 *input ) +static UINT32 * geo_direct_data( geo_state *geo, UINT32 opcode, UINT32 *input ) { + raster_state *raster = geo->raster; UINT32 tpa = *input++; /* Texture Point Address */ UINT32 tha = *input++; /* Texture Header Address */ UINT32 attr; /* push the initial set of data to the 3d rasterizer */ - model2_3d_push( (opcode >> 23) - 1 ); - model2_3d_push( tpa ); - model2_3d_push( tha ); + model2_3d_push( raster, (opcode >> 23) - 1 ); + model2_3d_push( raster, tpa ); + model2_3d_push( raster, tha ); /* push the initial points */ - model2_3d_push( (*input++) >> 8 ); /* x */ - model2_3d_push( (*input++) >> 8 ); /* y */ - model2_3d_push( (*input++) >> 8 ); /* z */ + model2_3d_push( raster, (*input++) >> 8 ); /* x */ + model2_3d_push( raster, (*input++) >> 8 ); /* y */ + model2_3d_push( raster, (*input++) >> 8 ); /* z */ - model2_3d_push( (*input++) >> 8 ); /* x */ - model2_3d_push( (*input++) >> 8 ); /* y */ - model2_3d_push( (*input++) >> 8 ); /* z */ + model2_3d_push( raster, (*input++) >> 8 ); /* x */ + model2_3d_push( raster, (*input++) >> 8 ); /* y */ + model2_3d_push( raster, (*input++) >> 8 ); /* z */ do { @@ -2130,41 +2140,42 @@ static UINT32 * geo_direct_data( UINT32 opcode, UINT32 *input ) break; /* push attributes */ - model2_3d_push( attr & 0x00FFFFFF ); + model2_3d_push( raster, attr & 0x00FFFFFF ); /* push luma */ - model2_3d_push( (*input++) >> 8 ); + model2_3d_push( raster, (*input++) >> 8 ); /* push distance */ - model2_3d_push( (*input++) >> 8 ); + model2_3d_push( raster, (*input++) >> 8 ); /* push the next point */ - model2_3d_push( (*input++) >> 8 ); /* x */ - model2_3d_push( (*input++) >> 8 ); /* y */ - model2_3d_push( (*input++) >> 8 ); /* z */ + model2_3d_push( raster, (*input++) >> 8 ); /* x */ + model2_3d_push( raster, (*input++) >> 8 ); /* y */ + model2_3d_push( raster, (*input++) >> 8 ); /* z */ /* if it's a quad, output another point */ if ( attr & 1 ) { - model2_3d_push( (*input++) >> 8 ); /* x */ - model2_3d_push( (*input++) >> 8 ); /* y */ - model2_3d_push( (*input++) >> 8 ); /* z */ + model2_3d_push( raster, (*input++) >> 8 ); /* x */ + model2_3d_push( raster, (*input++) >> 8 ); /* y */ + model2_3d_push( raster, (*input++) >> 8 ); /* z */ } } while( 1 ); /* we're done */ - model2_3d_push( 0 ); + model2_3d_push( raster, 0 ); return input; } /* Command 03: Window Data */ -static UINT32 * geo_window_data( UINT32 opcode, UINT32 *input ) +static UINT32 * geo_window_data( geo_state *geo, UINT32 opcode, UINT32 *input ) { + raster_state *raster = geo->raster; UINT32 x, y, i; /* start by pushing the opcode */ - model2_3d_push( opcode >> 23 ); + model2_3d_push( raster, opcode >> 23 ); /* we're going to move 6 coordinates to the 3d rasterizer: @@ -2186,38 +2197,39 @@ static UINT32 * geo_window_data( UINT32 opcode, UINT32 *input ) y &= 0xFFF; /* push it */ - model2_3d_push( x | y ); + model2_3d_push( raster, x | y ); } return input; } /* Command 04: Texture Data Write */ -static UINT32 * geo_texture_data( UINT32 opcode, UINT32 *input ) +static UINT32 * geo_texture_data( geo_state *geo, UINT32 opcode, UINT32 *input ) { + raster_state *raster = geo->raster; UINT32 i, count; /* start by pushing the opcode */ - model2_3d_push( opcode >> 23 ); + model2_3d_push( raster, opcode >> 23 ); /* push the starting address/dsp id */ - model2_3d_push( *input++ ); + model2_3d_push( raster, *input++ ); /* get the count */ count = *input++; /* push the count */ - model2_3d_push( count ); + model2_3d_push( raster, count ); /* loop and send the data */ for( i = 0; i < count; i++ ) - model2_3d_push( *input++ ); + model2_3d_push( raster, *input++ ); return input; } /* Command 05: Polygon Data */ -static UINT32 * geo_polygon_data( UINT32 opcode, UINT32 *input ) +static UINT32 * geo_polygon_data( geo_state *geo, UINT32 opcode, UINT32 *input ) { UINT32 address, count, i; UINT32 *p; @@ -2231,12 +2243,12 @@ static UINT32 * geo_polygon_data( UINT32 opcode, UINT32 *input ) if ( address & 0x01000000 ) { /* Fast polygon RAM */ - p = &geo.polygon_ram0[address & 0x7FFF]; + p = &geo->polygon_ram0[address & 0x7FFF]; } else { /* Slow Polygon RAM */ - p = &geo.polygon_ram1[address & 0x7FFF]; + p = &geo->polygon_ram1[address & 0x7FFF]; } /* read the count */ @@ -2250,7 +2262,7 @@ static UINT32 * geo_polygon_data( UINT32 opcode, UINT32 *input ) } /* Command 06: Texture Parameters */ -static UINT32 * geo_texture_parameters( UINT32 opcode, UINT32 *input ) +static UINT32 * geo_texture_parameters( geo_state *geo, UINT32 opcode, UINT32 *input ) { UINT32 index, count, i, param; @@ -2267,13 +2279,13 @@ static UINT32 * geo_texture_parameters( UINT32 opcode, UINT32 *input ) /* read in the texture parameters */ param = *input++; - geo.texture_parameters[index].diffuse = (float)( param & 0xFF ); - geo.texture_parameters[index].ambient = (float)( (param >> 8) & 0xFF ); - geo.texture_parameters[index].specular_control = (param >> 24) & 0xFF; - geo.texture_parameters[index].specular_scale = (float)( (param >> 16) & 0xFF ); + geo->texture_parameters[index].diffuse = (float)( param & 0xFF ); + geo->texture_parameters[index].ambient = (float)( (param >> 8) & 0xFF ); + geo->texture_parameters[index].specular_control = (param >> 24) & 0xFF; + geo->texture_parameters[index].specular_scale = (float)( (param >> 16) & 0xFF ); /* read in the distance coefficient */ - geo.coef_table[index] = u2f(*input++); + geo->coef_table[index] = u2f(*input++); index = (index + 1) & 0x1F; } @@ -2282,61 +2294,63 @@ static UINT32 * geo_texture_parameters( UINT32 opcode, UINT32 *input ) } /* Command 07: Geo Mode */ -static UINT32 * geo_mode( UINT32 opcode, UINT32 *input ) +static UINT32 * geo_mode( geo_state *geo, UINT32 opcode, UINT32 *input ) { (void)opcode; /* read in the mode */ - geo.mode = *input++; + geo->mode = *input++; return input; } /* Command 08: ZSort Mode */ -static UINT32 * geo_zsort_mode( UINT32 opcode, UINT32 *input ) +static UINT32 * geo_zsort_mode( geo_state *geo, UINT32 opcode, UINT32 *input ) { + raster_state *raster = geo->raster; + /* push the opcode */ - model2_3d_push( opcode >> 23 ); + model2_3d_push( raster, opcode >> 23 ); /* push the mode */ - model2_3d_push( (*input++) >> 8 ); + model2_3d_push( raster, (*input++) >> 8 ); return input; } /* Command 09: Focal Distance */ -static UINT32 * geo_focal_distance( UINT32 opcode, UINT32 *input ) +static UINT32 * geo_focal_distance( geo_state *geo, UINT32 opcode, UINT32 *input ) { (void)opcode; /* read the x focus value */ - geo.focus.x = u2f( *input++ ); + geo->focus.x = u2f( *input++ ); /* read the y focus value */ - geo.focus.y = u2f( *input++ ); + geo->focus.y = u2f( *input++ ); return input; } /* Command 0A: Light Source Vector Write */ -static UINT32 * geo_light_source( UINT32 opcode, UINT32 *input ) +static UINT32 * geo_light_source( geo_state *geo, UINT32 opcode, UINT32 *input ) { (void)opcode; /* read the x light value */ - geo.light.x = u2f( *input++ ); + geo->light.x = u2f( *input++ ); /* read the y light value */ - geo.light.y = u2f( *input++ ); + geo->light.y = u2f( *input++ ); /* read the z light value */ - geo.light.pz = u2f( *input++ ); + geo->light.pz = u2f( *input++ ); return input; } /* Command 0B: Transformation Matrix Write */ -static UINT32 * geo_matrix_write( UINT32 opcode, UINT32 *input ) +static UINT32 * geo_matrix_write( geo_state *geo, UINT32 opcode, UINT32 *input ) { UINT32 i; @@ -2344,13 +2358,13 @@ static UINT32 * geo_matrix_write( UINT32 opcode, UINT32 *input ) /* read in the transformation matrix */ for( i = 0; i < 12; i++ ) - geo.matrix[i] = u2f( *input++ ); + geo->matrix[i] = u2f( *input++ ); return input; } /* Command 0C: Parallel Transfer Vector Write */ -static UINT32 * geo_translate_write( UINT32 opcode, UINT32 *input ) +static UINT32 * geo_translate_write( geo_state *geo, UINT32 opcode, UINT32 *input ) { UINT32 i; @@ -2358,13 +2372,13 @@ static UINT32 * geo_translate_write( UINT32 opcode, UINT32 *input ) /* read in the translation vector */ for( i = 0; i < 3; i++ ) - geo.matrix[i+9] = u2f( *input++ ); + geo->matrix[i+9] = u2f( *input++ ); return input; } /* Command 0D: Geo Data Memory Push (undocumented, unsupported) */ -static UINT32 * geo_data_mem_push( UINT32 opcode, UINT32 *input ) +static UINT32 * geo_data_mem_push( geo_state *geo, UINT32 opcode, UINT32 *input ) { UINT32 address, count, i; @@ -2401,7 +2415,7 @@ static UINT32 * geo_data_mem_push( UINT32 opcode, UINT32 *input ) } /* Command 0E: Geo Test */ -static UINT32 * geo_test( UINT32 opcode, UINT32 *input ) +static UINT32 * geo_test( geo_state *geo, UINT32 opcode, UINT32 *input ) { UINT32 data, blocks, address, count, checksum, i; @@ -2443,7 +2457,7 @@ static UINT32 * geo_test( UINT32 opcode, UINT32 *input ) for( j = 0; j < count; j++ ) { - data = geo.polygon_rom[address++]; + data = geo->polygon_rom[address++]; address &= 0x7FFFFF; @@ -2471,19 +2485,21 @@ static UINT32 * geo_test( UINT32 opcode, UINT32 *input ) } /* Command 0F: End */ -static UINT32 * geo_end( UINT32 opcode, UINT32 *input ) +static UINT32 * geo_end( geo_state *geo, UINT32 opcode, UINT32 *input ) { + raster_state *raster = geo->raster; + (void)opcode; /* signal the end of this data block the rasterizer */ - model2_3d_push( 0xFF000000 ); + model2_3d_push( raster, 0xFF000000 ); /* signal end by returning NULL */ return NULL; } /* Command 10: Dummy */ -static UINT32 * geo_dummy( UINT32 opcode, UINT32 *input ) +static UINT32 * geo_dummy( geo_state *geo, UINT32 opcode, UINT32 *input ) { UINT32 data; (void)opcode; @@ -2495,49 +2511,50 @@ static UINT32 * geo_dummy( UINT32 opcode, UINT32 *input ) } /* Command 14: Log Data Write */ -static UINT32 * geo_log_data( UINT32 opcode, UINT32 *input ) +static UINT32 * geo_log_data( geo_state *geo, UINT32 opcode, UINT32 *input ) { + raster_state *raster = geo->raster; UINT32 i, count; /* start by pushing the opcode */ - model2_3d_push( opcode >> 23 ); + model2_3d_push( raster, opcode >> 23 ); /* push the starting address/dsp id */ - model2_3d_push( *input++ ); + model2_3d_push( raster, *input++ ); /* get the count */ count = *input++; /* push the count */ - model2_3d_push( count << 2 ); + model2_3d_push( raster, count << 2 ); /* loop and send the data */ for( i = 0; i < count; i++ ) { UINT32 data = *input++; - model2_3d_push( data & 0xff ); - model2_3d_push( (data >> 8) & 0xff ); - model2_3d_push( (data >> 16) & 0xff ); - model2_3d_push( (data >> 24) & 0xff ); + model2_3d_push( raster, data & 0xff ); + model2_3d_push( raster, (data >> 8) & 0xff ); + model2_3d_push( raster, (data >> 16) & 0xff ); + model2_3d_push( raster, (data >> 24) & 0xff ); } return input; } /* Command 16: LOD */ -static UINT32 * geo_lod( UINT32 opcode, UINT32 *input ) +static UINT32 * geo_lod( geo_state *geo, UINT32 opcode, UINT32 *input ) { (void)opcode; /* read in the LOD */ - geo.lod = u2f(*input++); + geo->lod = u2f(*input++); return input; } /* Command 1D: Code Upload (undocumented, unsupported) */ -static UINT32 * geo_code_upload( UINT32 opcode, UINT32 *input ) +static UINT32 * geo_code_upload( geo_state *geo, UINT32 opcode, UINT32 *input ) { UINT32 flags, count, i; @@ -2585,7 +2602,7 @@ static UINT32 * geo_code_upload( UINT32 opcode, UINT32 *input ) } /* Command 1E: Code Jump (undocumented, unsupported) */ -static UINT32 * geo_code_jump( UINT32 opcode, UINT32 *input ) +static UINT32 * geo_code_jump( geo_state *geo, UINT32 opcode, UINT32 *input ) { UINT32 address; @@ -2609,54 +2626,54 @@ static UINT32 * geo_code_jump( UINT32 opcode, UINT32 *input ) return input; } -static UINT32 * geo_process_command( UINT32 opcode, UINT32 *input ) +static UINT32 * geo_process_command( geo_state *geo, UINT32 opcode, UINT32 *input ) { switch( opcode >> 23 ) { - case 0x00: input = geo_nop( opcode, input ); break; - case 0x01: input = geo_object_data( opcode, input ); break; - case 0x02: input = geo_direct_data( opcode, input ); break; - case 0x03: input = geo_window_data( opcode, input ); break; - case 0x04: input = geo_texture_data( opcode, input ); break; - case 0x05: input = geo_polygon_data( opcode, input ); break; - case 0x06: input = geo_texture_parameters( opcode, input ); break; - case 0x07: input = geo_mode( opcode, input ); break; - case 0x08: input = geo_zsort_mode( opcode, input ); break; - case 0x09: input = geo_focal_distance( opcode, input ); break; - case 0x0A: input = geo_light_source( opcode, input ); break; - case 0x0B: input = geo_matrix_write( opcode, input ); break; - case 0x0C: input = geo_translate_write( opcode, input ); break; - case 0x0D: input = geo_data_mem_push( opcode, input ); break; - case 0x0E: input = geo_test( opcode, input ); break; - case 0x0F: input = geo_end( opcode, input ); break; - case 0x10: input = geo_dummy( opcode, input ); break; - case 0x11: input = geo_object_data( opcode, input ); break; - case 0x12: input = geo_direct_data( opcode, input ); break; - case 0x13: input = geo_window_data( opcode, input ); break; - case 0x14: input = geo_log_data( opcode, input ); break; - case 0x15: input = geo_polygon_data( opcode, input ); break; - case 0x16: input = geo_lod( opcode, input ); break; - case 0x17: input = geo_mode( opcode, input ); break; - case 0x18: input = geo_zsort_mode( opcode, input ); break; - case 0x19: input = geo_focal_distance( opcode, input ); break; - case 0x1A: input = geo_light_source( opcode, input ); break; - case 0x1B: input = geo_matrix_write( opcode, input ); break; - case 0x1C: input = geo_translate_write( opcode, input ); break; - case 0x1D: input = geo_code_upload( opcode, input ); break; - case 0x1E: input = geo_code_jump( opcode, input ); break; - case 0x1F: input = geo_end( opcode, input ); break; + case 0x00: input = geo_nop( geo, opcode, input ); break; + case 0x01: input = geo_object_data( geo, opcode, input ); break; + case 0x02: input = geo_direct_data( geo, opcode, input ); break; + case 0x03: input = geo_window_data( geo, opcode, input ); break; + case 0x04: input = geo_texture_data( geo, opcode, input ); break; + case 0x05: input = geo_polygon_data( geo, opcode, input ); break; + case 0x06: input = geo_texture_parameters( geo, opcode, input ); break; + case 0x07: input = geo_mode( geo, opcode, input ); break; + case 0x08: input = geo_zsort_mode( geo, opcode, input ); break; + case 0x09: input = geo_focal_distance( geo, opcode, input ); break; + case 0x0A: input = geo_light_source( geo, opcode, input ); break; + case 0x0B: input = geo_matrix_write( geo, opcode, input ); break; + case 0x0C: input = geo_translate_write( geo, opcode, input ); break; + case 0x0D: input = geo_data_mem_push( geo, opcode, input ); break; + case 0x0E: input = geo_test( geo, opcode, input ); break; + case 0x0F: input = geo_end( geo, opcode, input ); break; + case 0x10: input = geo_dummy( geo, opcode, input ); break; + case 0x11: input = geo_object_data( geo, opcode, input ); break; + case 0x12: input = geo_direct_data( geo, opcode, input ); break; + case 0x13: input = geo_window_data( geo, opcode, input ); break; + case 0x14: input = geo_log_data( geo, opcode, input ); break; + case 0x15: input = geo_polygon_data( geo, opcode, input ); break; + case 0x16: input = geo_lod( geo, opcode, input ); break; + case 0x17: input = geo_mode( geo, opcode, input ); break; + case 0x18: input = geo_zsort_mode( geo, opcode, input ); break; + case 0x19: input = geo_focal_distance( geo, opcode, input ); break; + case 0x1A: input = geo_light_source( geo, opcode, input ); break; + case 0x1B: input = geo_matrix_write( geo, opcode, input ); break; + case 0x1C: input = geo_translate_write( geo, opcode, input ); break; + case 0x1D: input = geo_code_upload( geo, opcode, input ); break; + case 0x1E: input = geo_code_jump( geo, opcode, input ); break; + case 0x1F: input = geo_end( geo, opcode, input ); break; } return input; } -static void geo_parse( void ) +static void geo_parse( model2_state *state ) { - UINT32 address = (geo_read_start_address/4); - UINT32 *input = &model2_bufferram[address]; + UINT32 address = (state->geo_read_start_address/4); + UINT32 *input = &state->bufferram[address]; UINT32 opcode; - while( input != NULL && (input - model2_bufferram) < 0x20000 ) + while( input != NULL && (input - state->bufferram) < 0x20000 ) { /* read in the opcode */ opcode = *input++; @@ -2668,43 +2685,44 @@ static void geo_parse( void ) address = (opcode & 0x7FFFF) / 4; /* update our pointer */ - input = &model2_bufferram[address]; + input = &state->bufferram[address]; /* go again */ continue; } /* process it */ - input = geo_process_command( opcode, input ); + input = geo_process_command( state->geo, opcode, input ); } } /***********************************************************************************************/ -static bitmap_t *sys24_bitmap = NULL; static void model2_exit(running_machine &machine) { - poly_free(poly); + model2_state *state = machine.driver_data(); + poly_free(state->poly); } VIDEO_START(model2) { + model2_state *state = machine->driver_data(); const rectangle &visarea = machine->primary_screen->visible_area(); int width = visarea.max_x - visarea.min_x; int height = visarea.max_y - visarea.min_y; sys24_tile_vh_start(machine, 0x3fff); - sys24_bitmap = auto_alloc(machine, bitmap_t(width, height+4, BITMAP_FORMAT_INDEXED16)); + state->sys24_bitmap = auto_alloc(machine, bitmap_t(width, height+4, BITMAP_FORMAT_INDEXED16)); - poly = poly_alloc(machine, 4000, sizeof(poly_extra_data), 0); + state->poly = poly_alloc(machine, 4000, sizeof(poly_extra_data), 0); machine->add_notifier(MACHINE_NOTIFY_EXIT, model2_exit); - /* initialize the geometry engine */ - geo_init( machine, (UINT32*)machine->region("user2")->base() ); - /* initialize the hardware rasterizer */ model2_3d_init( machine, (UINT16*)machine->region("user3")->base() ); + + /* initialize the geometry engine */ + geo_init( machine, (UINT32*)machine->region("user2")->base() ); } static void convert_bitmap( running_machine *machine, bitmap_t *dst, bitmap_t *src, const rectangle *rect ) @@ -2726,34 +2744,35 @@ static void convert_bitmap( running_machine *machine, bitmap_t *dst, bitmap_t *s VIDEO_UPDATE(model2) { + model2_state *state = screen->machine->driver_data(); logerror("--- frame ---\n"); bitmap_fill(bitmap, cliprect, screen->machine->pens[0]); - bitmap_fill(sys24_bitmap, cliprect, 0); + bitmap_fill(state->sys24_bitmap, cliprect, 0); - sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 7, 0, 0); - sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 6, 0, 0); - sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 5, 0, 0); - sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 4, 0, 0); + sys24_tile_draw(screen->machine, state->sys24_bitmap, cliprect, 7, 0, 0); + sys24_tile_draw(screen->machine, state->sys24_bitmap, cliprect, 6, 0, 0); + sys24_tile_draw(screen->machine, state->sys24_bitmap, cliprect, 5, 0, 0); + sys24_tile_draw(screen->machine, state->sys24_bitmap, cliprect, 4, 0, 0); - convert_bitmap(screen->machine, bitmap, sys24_bitmap, cliprect); + convert_bitmap(screen->machine, bitmap, state->sys24_bitmap, cliprect); /* tell the rasterizer we're starting a frame */ - model2_3d_frame_start(); + model2_3d_frame_start(state); /* let the geometry engine do it's thing */ - geo_parse(); + geo_parse(state); /* have the rasterizer output the frame */ - model2_3d_frame_end( bitmap, cliprect ); + model2_3d_frame_end( state, bitmap, cliprect ); - bitmap_fill(sys24_bitmap, cliprect, 0); - sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 3, 0, 0); - sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 2, 0, 0); - sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 1, 0, 0); - sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 0, 0, 0); + bitmap_fill(state->sys24_bitmap, cliprect, 0); + sys24_tile_draw(screen->machine, state->sys24_bitmap, cliprect, 3, 0, 0); + sys24_tile_draw(screen->machine, state->sys24_bitmap, cliprect, 2, 0, 0); + sys24_tile_draw(screen->machine, state->sys24_bitmap, cliprect, 1, 0, 0); + sys24_tile_draw(screen->machine, state->sys24_bitmap, cliprect, 0, 0, 0); - convert_bitmap(screen->machine, bitmap, sys24_bitmap, cliprect); + convert_bitmap(screen->machine, bitmap, state->sys24_bitmap, cliprect); return 0; } diff --git a/src/mame/video/model2rd.c b/src/mame/video/model2rd.c index bf65bbcf517..d0fd0ffe8ec 100644 --- a/src/mame/video/model2rd.c +++ b/src/mame/video/model2rd.c @@ -58,15 +58,16 @@ static void MODEL2_FUNC_NAME(void *dest, INT32 scanline, const poly_extent *exte { #if !defined( MODEL2_TRANSLUCENT) const poly_extra_data *extra = (const poly_extra_data *)extradata; + model2_state *state = extra->state; bitmap_t *destmap = (bitmap_t *)dest; UINT32 *p = BITMAP_ADDR32(destmap, scanline, 0); /* extract color information */ - const UINT16 *colortable_r = (const UINT16 *)&model2_colorxlat[0x0000/4]; - const UINT16 *colortable_g = (const UINT16 *)&model2_colorxlat[0x4000/4]; - const UINT16 *colortable_b = (const UINT16 *)&model2_colorxlat[0x8000/4]; - const UINT16 *lumaram = (const UINT16 *)model2_lumaram; - const UINT16 *palram = (const UINT16 *)model2_paletteram32; + const UINT16 *colortable_r = (const UINT16 *)&state->colorxlat[0x0000/4]; + const UINT16 *colortable_g = (const UINT16 *)&state->colorxlat[0x4000/4]; + const UINT16 *colortable_b = (const UINT16 *)&state->colorxlat[0x8000/4]; + const UINT16 *lumaram = (const UINT16 *)state->lumaram; + const UINT16 *palram = (const UINT16 *)state->paletteram32; UINT32 lumabase = extra->lumabase; UINT32 color = extra->colorbase; UINT8 luma; @@ -110,6 +111,7 @@ static void MODEL2_FUNC_NAME(void *dest, INT32 scanline, const poly_extent *exte static void MODEL2_FUNC_NAME(void *dest, INT32 scanline, const poly_extent *extent, const void *extradata, int threadid) { const poly_extra_data *extra = (const poly_extra_data *)extradata; + model2_state *state = extra->state; bitmap_t *destmap = (bitmap_t *)dest; UINT32 *p = BITMAP_ADDR32(destmap, scanline, 0); @@ -117,11 +119,11 @@ static void MODEL2_FUNC_NAME(void *dest, INT32 scanline, const poly_extent *exte UINT32 tex_height = extra->texheight; /* extract color information */ - const UINT16 *colortable_r = (const UINT16 *)&model2_colorxlat[0x0000/4]; - const UINT16 *colortable_g = (const UINT16 *)&model2_colorxlat[0x4000/4]; - const UINT16 *colortable_b = (const UINT16 *)&model2_colorxlat[0x8000/4]; - const UINT16 *lumaram = (const UINT16 *)model2_lumaram; - const UINT16 *palram = (const UINT16 *)model2_paletteram32; + const UINT16 *colortable_r = (const UINT16 *)&state->colorxlat[0x0000/4]; + const UINT16 *colortable_g = (const UINT16 *)&state->colorxlat[0x4000/4]; + const UINT16 *colortable_b = (const UINT16 *)&state->colorxlat[0x8000/4]; + const UINT16 *lumaram = (const UINT16 *)state->lumaram; + const UINT16 *palram = (const UINT16 *)state->paletteram32; UINT32 colorbase = extra->colorbase; UINT32 lumabase = extra->lumabase; UINT32 tex_x = extra->texx; diff --git a/src/mame/video/model3.c b/src/mame/video/model3.c index fa1c2edaf6b..1968af4ebdc 100644 --- a/src/mame/video/model3.c +++ b/src/mame/video/model3.c @@ -10,13 +10,7 @@ -typedef float MATRIX[4][4]; -typedef float VECTOR[4]; -typedef float VECTOR3[3]; -typedef struct { - float x,y,z,d; -} PLANE; typedef struct { @@ -29,7 +23,6 @@ typedef struct UINT32 color; } TRIANGLE; -typedef struct _cached_texture cached_texture; struct _cached_texture { cached_texture *next; @@ -44,6 +37,7 @@ typedef struct _poly_extra_data poly_extra_data; struct _poly_extra_data { cached_texture *texture; + bitmap_t *zbuffer; UINT32 color; UINT8 texture_param; int polygon_transparency; @@ -62,12 +56,12 @@ struct _poly_extra_data /* forward declarations */ static void real3d_traverse_display_list(running_machine *machine); static void draw_model(running_machine *machine, UINT32 addr); -static void init_matrix_stack(void); -static void get_top_matrix(MATRIX *out); -static void push_matrix_stack(void); -static void pop_matrix_stack(void); -static void multiply_matrix_stack(MATRIX matrix); -static void translate_matrix_stack(float x, float y, float z); +static void init_matrix_stack(running_machine *machine); +static void get_top_matrix(model3_state *state, MATRIX *out); +static void push_matrix_stack(model3_state *state); +static void pop_matrix_stack(model3_state *state); +static void multiply_matrix_stack(model3_state *state, MATRIX matrix); +static void translate_matrix_stack(model3_state *state, float x, float y, float z); static void traverse_list(running_machine *machine, UINT32 address); static void draw_block(running_machine *machine, UINT32 address); static void draw_viewport(running_machine *machine, int pri, UINT32 address); @@ -75,74 +69,33 @@ static void invalidate_texture(running_machine *machine, int page, int texx, int /*****************************************************************************/ -UINT64 *paletteram64; - -static UINT8 model3_layer_enable = 0; -static UINT32 layer_modulate_r; -static UINT32 layer_modulate_g; -static UINT32 layer_modulate_b; -static UINT32 model3_layer_modulate1; -static UINT32 model3_layer_modulate2; -static UINT64 layer_scroll[2]; - -static UINT64 *m3_char_ram; -static UINT64 *m3_tile_ram; - -static UINT32 *texture_fifo; -static int texture_fifo_pos = 0; - -static UINT16 *texture_ram[2]; -static UINT32 *display_list_ram; -static UINT32 *culling_ram; -static UINT32 *polygon_ram; - -static UINT16 *pal_lookup; - -static int real3d_display_list = 0; - -static bitmap_t *bitmap3d; -static bitmap_t *zbuffer; -static rectangle clip3d; -static rectangle *screen_clip; -static VECTOR3 parallel_light; -static float parallel_light_intensity; -static float ambient_light_intensity; - -static poly_manager *poly; -static cached_texture *texcache[2][1024/32][2048/32]; -static int list_depth = 0; -static int tick = 0; -static int debug_layer_disable = 0; -static UINT64 vid_reg0; + + + + + + + + /* matrix stack */ #define MATRIX_STACK_SIZE 256 -static int matrix_stack_ptr = 0; -static MATRIX matrix_stack[MATRIX_STACK_SIZE]; #ifdef UNUSED_DEFINITION static const int num_bits[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 }; #endif -static MATRIX coordinate_system; -static float viewport_focal_length; -static int viewport_region_x; -static int viewport_region_y; -static int viewport_region_width; -static int viewport_region_height; -static PLANE clip_plane[5]; -static UINT32 matrix_base_address; #define BYTE_REVERSE32(x) (((x >> 24) & 0xff) | \ @@ -155,58 +108,61 @@ static UINT32 matrix_base_address; static void model3_exit(running_machine &machine) { + model3_state *state = machine.driver_data(); invalidate_texture(&machine, 0, 0, 0, 6, 5); invalidate_texture(&machine, 1, 0, 0, 6, 5); - poly_free(poly); + poly_free(state->poly); } VIDEO_START( model3 ) { + model3_state *state = machine->driver_data(); int width, height; - poly = poly_alloc(machine, 4000, sizeof(poly_extra_data), 0); + state->poly = poly_alloc(machine, 4000, sizeof(poly_extra_data), 0); machine->add_notifier(MACHINE_NOTIFY_EXIT, model3_exit); width = machine->primary_screen->width(); height = machine->primary_screen->height(); - bitmap3d = machine->primary_screen->alloc_compatible_bitmap(); - zbuffer = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED32); + state->bitmap3d = machine->primary_screen->alloc_compatible_bitmap(); + state->zbuffer = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED32); - m3_char_ram = auto_alloc_array_clear(machine, UINT64, 0x100000/8); - m3_tile_ram = auto_alloc_array_clear(machine, UINT64, 0x8000/8); + state->m3_char_ram = auto_alloc_array_clear(machine, UINT64, 0x100000/8); + state->m3_tile_ram = auto_alloc_array_clear(machine, UINT64, 0x8000/8); - pal_lookup = auto_alloc_array_clear(machine, UINT16, 65536); + state->pal_lookup = auto_alloc_array_clear(machine, UINT16, 65536); - texture_fifo = auto_alloc_array_clear(machine, UINT32, 0x100000/4); + state->texture_fifo = auto_alloc_array_clear(machine, UINT32, 0x100000/4); /* 2x 4MB texture sheets */ - texture_ram[0] = auto_alloc_array(machine, UINT16, 0x400000/2); - texture_ram[1] = auto_alloc_array(machine, UINT16, 0x400000/2); + state->texture_ram[0] = auto_alloc_array(machine, UINT16, 0x400000/2); + state->texture_ram[1] = auto_alloc_array(machine, UINT16, 0x400000/2); /* 1MB Display List RAM */ - display_list_ram = auto_alloc_array_clear(machine, UINT32, 0x100000/4); + state->display_list_ram = auto_alloc_array_clear(machine, UINT32, 0x100000/4); /* 4MB for nodes (< Step 2.0 have only 2MB) */ - culling_ram = auto_alloc_array_clear(machine, UINT32, 0x400000/4); + state->culling_ram = auto_alloc_array_clear(machine, UINT32, 0x400000/4); /* 4MB Polygon RAM */ - polygon_ram = auto_alloc_array_clear(machine, UINT32, 0x400000/4); + state->polygon_ram = auto_alloc_array_clear(machine, UINT32, 0x400000/4); - tick = 0; - debug_layer_disable = 0; - vid_reg0 = 0; + state->tick = 0; + state->debug_layer_disable = 0; + state->vid_reg0 = 0; - viewport_focal_length = 300.; - viewport_region_x = 0; - viewport_region_y = 0; - viewport_region_width = 496; - viewport_region_height = 384; + state->viewport_focal_length = 300.; + state->viewport_region_x = 0; + state->viewport_region_y = 0; + state->viewport_region_width = 496; + state->viewport_region_height = 384; - init_matrix_stack(); + init_matrix_stack(machine); } -static void draw_tile_4bit(bitmap_t *bitmap, int tx, int ty, int tilenum) +static void draw_tile_4bit(running_machine *machine, bitmap_t *bitmap, int tx, int ty, int tilenum) { + model3_state *state = machine->driver_data(); int x, y; - UINT8 *tile_base = (UINT8*)m3_char_ram; + UINT8 *tile_base = (UINT8*)state->m3_char_ram; UINT8 *tile; int data = (BYTE_REVERSE16(tilenum)); @@ -223,8 +179,8 @@ static void draw_tile_4bit(bitmap_t *bitmap, int tx, int ty, int tilenum) UINT16 pix0, pix1; tile0 = *tile >> 4; tile1 = *tile & 0xf; - pix0 = pal_lookup[c + tile0]; - pix1 = pal_lookup[c + tile1]; + pix0 = state->pal_lookup[c + tile0]; + pix1 = state->pal_lookup[c + tile1]; if((pix0 & 0x8000) == 0) { d[x+0] = pix0; @@ -238,10 +194,11 @@ static void draw_tile_4bit(bitmap_t *bitmap, int tx, int ty, int tilenum) } } -static void draw_tile_8bit(bitmap_t *bitmap, int tx, int ty, int tilenum) +static void draw_tile_8bit(running_machine *machine, bitmap_t *bitmap, int tx, int ty, int tilenum) { + model3_state *state = machine->driver_data(); int x, y; - UINT8 *tile_base = (UINT8*)m3_char_ram; + UINT8 *tile_base = (UINT8*)state->m3_char_ram; UINT8 *tile; int data = (BYTE_REVERSE16(tilenum)); @@ -258,7 +215,7 @@ static void draw_tile_8bit(bitmap_t *bitmap, int tx, int ty, int tilenum) UINT8 tile0; UINT16 pix; tile0 = tile[xx^4]; - pix = pal_lookup[c + tile0]; + pix = state->pal_lookup[c + tile0]; if((pix & 0x8000) == 0) { d[x] = pix; @@ -269,15 +226,16 @@ static void draw_tile_8bit(bitmap_t *bitmap, int tx, int ty, int tilenum) } } #ifdef UNUSED_FUNCTION -static void draw_texture_sheet(bitmap_t *bitmap, const rectangle *cliprect) +static void draw_texture_sheet(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect) { + model3_state *state = machine->driver_data(); int x,y; for(y = cliprect->min_y; y <= cliprect->max_y; y++) { UINT16 *d = BITMAP_ADDR16(bitmap, y, 0); int index = (y*2)*2048; for(x = cliprect->min_x; x <= cliprect->max_x; x++) { - UINT16 pix = texture_ram[0][index]; + UINT16 pix = state->texture_ram[0][index]; index+=4; if(pix != 0) { d[x] = pix; @@ -287,51 +245,52 @@ static void draw_texture_sheet(bitmap_t *bitmap, const rectangle *cliprect) } #endif -static void draw_layer(bitmap_t *bitmap, const rectangle *cliprect, int layer, int bitdepth) +static void draw_layer(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int layer, int bitdepth) { + model3_state *state = machine->driver_data(); int x, y; int tile_index = 0; - UINT16 *tiles = (UINT16*)&m3_tile_ram[layer * 0x400]; + UINT16 *tiles = (UINT16*)&state->m3_tile_ram[layer * 0x400]; //logerror("Layer %d: X: %d, Y: %d\n", layer, x1, y1); if(layer > 1) { - int modr = (model3_layer_modulate2 >> 8) & 0xff; - int modg = (model3_layer_modulate2 >> 16) & 0xff; - int modb = (model3_layer_modulate2 >> 24) & 0xff; + int modr = (state->layer_modulate2 >> 8) & 0xff; + int modg = (state->layer_modulate2 >> 16) & 0xff; + int modb = (state->layer_modulate2 >> 24) & 0xff; if(modr & 0x80) { - layer_modulate_r = -(0x7f - (modr & 0x7f)) << 10; + state->layer_modulate_r = -(0x7f - (modr & 0x7f)) << 10; } else { - layer_modulate_r = (modr & 0x7f) << 10; + state->layer_modulate_r = (modr & 0x7f) << 10; } if(modg & 0x80) { - layer_modulate_g = -(0x7f - (modr & 0x7f)) << 5; + state->layer_modulate_g = -(0x7f - (modr & 0x7f)) << 5; } else { - layer_modulate_g = (modr & 0x7f) << 5; + state->layer_modulate_g = (modr & 0x7f) << 5; } if(modb & 0x80) { - layer_modulate_b = -(0x7f - (modr & 0x7f)); + state->layer_modulate_b = -(0x7f - (modr & 0x7f)); } else { - layer_modulate_b = (modr & 0x7f); + state->layer_modulate_b = (modr & 0x7f); } } else { - int modr = (model3_layer_modulate1 >> 8) & 0xff; - int modg = (model3_layer_modulate1 >> 16) & 0xff; - int modb = (model3_layer_modulate1 >> 24) & 0xff; + int modr = (state->layer_modulate1 >> 8) & 0xff; + int modg = (state->layer_modulate1 >> 16) & 0xff; + int modb = (state->layer_modulate1 >> 24) & 0xff; if(modr & 0x80) { - layer_modulate_r = -(0x7f - (modr & 0x7f)) << 10; + state->layer_modulate_r = -(0x7f - (modr & 0x7f)) << 10; } else { - layer_modulate_r = (modr & 0x7f) << 10; + state->layer_modulate_r = (modr & 0x7f) << 10; } if(modg & 0x80) { - layer_modulate_g = -(0x7f - (modr & 0x7f)) << 5; + state->layer_modulate_g = -(0x7f - (modr & 0x7f)) << 5; } else { - layer_modulate_g = (modr & 0x7f) << 5; + state->layer_modulate_g = (modr & 0x7f) << 5; } if(modb & 0x80) { - layer_modulate_b = -(0x7f - (modr & 0x7f)); + state->layer_modulate_b = -(0x7f - (modr & 0x7f)); } else { - layer_modulate_b = (modr & 0x7f); + state->layer_modulate_b = (modr & 0x7f); } } @@ -342,7 +301,7 @@ static void draw_layer(bitmap_t *bitmap, const rectangle *cliprect, int layer, i tile_index = ((y/8) * 64); for (x = cliprect->min_x; x <= cliprect->max_x; x+=8) { UINT16 tile = tiles[tile_index ^ 0x2]; - draw_tile_4bit(bitmap, x, y, tile); + draw_tile_4bit(machine, bitmap, x, y, tile); ++tile_index; } } @@ -354,7 +313,7 @@ static void draw_layer(bitmap_t *bitmap, const rectangle *cliprect, int layer, i tile_index = ((y/8) * 64); for (x = cliprect->min_x; x <= cliprect->max_x; x+=8) { UINT16 tile = tiles[tile_index ^ 0x2]; - draw_tile_8bit(bitmap, x, y, tile); + draw_tile_8bit(machine, bitmap, x, y, tile); ++tile_index; } } @@ -362,12 +321,13 @@ static void draw_layer(bitmap_t *bitmap, const rectangle *cliprect, int layer, i } #ifdef UNUSED_FUNCTION -static void copy_screen(bitmap_t *bitmap, const rectangle *cliprect) +static void copy_screen(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect) { + model3_state *state = machine->driver_data(); int x,y; for(y=cliprect->min_y; y <= cliprect->max_y; y++) { UINT16 *d = BITMAP_ADDR16(bitmap, y, 0); - UINT16 *s = BITMAP_ADDR16(bitmap3d, y, 0); + UINT16 *s = BITMAP_ADDR16(state->bitmap3d, y, 0); for(x=cliprect->min_x; x <= cliprect->max_x; x++) { UINT16 pix = s[x]; if(!(pix & 0x8000)) { @@ -380,76 +340,79 @@ static void copy_screen(bitmap_t *bitmap, const rectangle *cliprect) VIDEO_UPDATE( model3 ) { -/* - int layer_scroll_x[4], layer_scroll_y[4]; - UINT32 layer_data[4]; + model3_state *state = screen->machine->driver_data(); +#if 0 + int layer_scroll_x[4], layer_scroll_y[4]; + UINT32 layer_data[4]; - layer_data[0] = BYTE_REVERSE32((UINT32)(layer_scroll[0] >> 32)); - layer_data[1] = BYTE_REVERSE32((UINT32)(layer_scroll[0] >> 0)); - layer_data[2] = BYTE_REVERSE32((UINT32)(layer_scroll[1] >> 32)); - layer_data[3] = BYTE_REVERSE32((UINT32)(layer_scroll[1] >> 0)); - layer_scroll_x[0] = (layer_data[0] & 0x8000) ? (layer_data[0] & 0x1ff) : -(layer_data[0] & 0x1ff); - layer_scroll_y[0] = (layer_data[0] & 0x8000) ? (layer_data[0] & 0x1ff) : -(layer_data[0] & 0x1ff); - layer_scroll_x[1] = (layer_data[1] & 0x8000) ? (layer_data[1] & 0x1ff) : -(layer_data[1] & 0x1ff); - layer_scroll_y[1] = (layer_data[1] & 0x8000) ? (layer_data[1] & 0x1ff) : -(layer_data[1] & 0x1ff); - layer_scroll_x[2] = (layer_data[2] & 0x8000) ? (layer_data[2] & 0x1ff) : -(layer_data[2] & 0x1ff); - layer_scroll_y[2] = (layer_data[2] & 0x8000) ? (layer_data[2] & 0x1ff) : -(layer_data[2] & 0x1ff); - layer_scroll_x[3] = (layer_data[3] & 0x8000) ? (layer_data[3] & 0x1ff) : -(layer_data[3] & 0x1ff); - layer_scroll_y[3] = (layer_data[3] & 0x8000) ? (layer_data[3] & 0x1ff) : -(layer_data[3] & 0x1ff); -*/ - screen_clip = (rectangle*)cliprect; + layer_data[0] = BYTE_REVERSE32((UINT32)(state->layer_scroll[0] >> 32)); + layer_data[1] = BYTE_REVERSE32((UINT32)(state->layer_scroll[0] >> 0)); + layer_data[2] = BYTE_REVERSE32((UINT32)(state->layer_scroll[1] >> 32)); + layer_data[3] = BYTE_REVERSE32((UINT32)(state->layer_scroll[1] >> 0)); + layer_scroll_x[0] = (layer_data[0] & 0x8000) ? (layer_data[0] & 0x1ff) : -(layer_data[0] & 0x1ff); + layer_scroll_y[0] = (layer_data[0] & 0x8000) ? (layer_data[0] & 0x1ff) : -(layer_data[0] & 0x1ff); + layer_scroll_x[1] = (layer_data[1] & 0x8000) ? (layer_data[1] & 0x1ff) : -(layer_data[1] & 0x1ff); + layer_scroll_y[1] = (layer_data[1] & 0x8000) ? (layer_data[1] & 0x1ff) : -(layer_data[1] & 0x1ff); + layer_scroll_x[2] = (layer_data[2] & 0x8000) ? (layer_data[2] & 0x1ff) : -(layer_data[2] & 0x1ff); + layer_scroll_y[2] = (layer_data[2] & 0x8000) ? (layer_data[2] & 0x1ff) : -(layer_data[2] & 0x1ff); + layer_scroll_x[3] = (layer_data[3] & 0x8000) ? (layer_data[3] & 0x1ff) : -(layer_data[3] & 0x1ff); + layer_scroll_y[3] = (layer_data[3] & 0x8000) ? (layer_data[3] & 0x1ff) : -(layer_data[3] & 0x1ff); +#endif + state->screen_clip = (rectangle*)cliprect; - clip3d.min_x = cliprect->min_x; - clip3d.max_x = cliprect->max_x; - clip3d.min_y = cliprect->min_y; - clip3d.max_y = cliprect->max_y; + state->clip3d.min_x = cliprect->min_x; + state->clip3d.max_x = cliprect->max_x; + state->clip3d.min_y = cliprect->min_y; + state->clip3d.max_y = cliprect->max_y; /* layer disable debug keys */ - tick++; - if( tick >= 5 ) { - tick = 0; + state->tick++; + if( state->tick >= 5 ) { + state->tick = 0; if( input_code_pressed(screen->machine, KEYCODE_Y) ) - debug_layer_disable ^= 0x1; + state->debug_layer_disable ^= 0x1; if( input_code_pressed(screen->machine, KEYCODE_U) ) - debug_layer_disable ^= 0x2; + state->debug_layer_disable ^= 0x2; if( input_code_pressed(screen->machine, KEYCODE_I) ) - debug_layer_disable ^= 0x4; + state->debug_layer_disable ^= 0x4; if( input_code_pressed(screen->machine, KEYCODE_O) ) - debug_layer_disable ^= 0x8; + state->debug_layer_disable ^= 0x8; if( input_code_pressed(screen->machine, KEYCODE_T) ) - debug_layer_disable ^= 0x10; + state->debug_layer_disable ^= 0x10; } bitmap_fill(bitmap, cliprect, 0); - if (!(debug_layer_disable & 0x8)) - draw_layer(bitmap, cliprect, 3, (model3_layer_enable >> 3) & 0x1); + if (!(state->debug_layer_disable & 0x8)) + draw_layer(screen->machine, bitmap, cliprect, 3, (state->layer_enable >> 3) & 0x1); - if (!(debug_layer_disable & 0x4)) - draw_layer(bitmap, cliprect, 2, (model3_layer_enable >> 2) & 0x1); + if (!(state->debug_layer_disable & 0x4)) + draw_layer(screen->machine, bitmap, cliprect, 2, (state->layer_enable >> 2) & 0x1); - if( !(debug_layer_disable & 0x10) ) + if( !(state->debug_layer_disable & 0x10) ) { -// if(real3d_display_list) { -// bitmap_fill(zbuffer, cliprect, 0); -// bitmap_fill(bitmap3d, cliprect, 0x8000); -// real3d_traverse_display_list(screen->machine); -// } - copybitmap_trans(bitmap, bitmap3d, 0, 0, 0, 0, cliprect, 0x8000); +#if 0 + if(state->real3d_display_list) { + bitmap_fill(state->zbuffer, cliprect, 0); + bitmap_fill(state->bitmap3d, cliprect, 0x8000); + real3d_traverse_display_list(screen->machine); + } +#endif + copybitmap_trans(bitmap, state->bitmap3d, 0, 0, 0, 0, cliprect, 0x8000); } - if (!(debug_layer_disable & 0x2)) - draw_layer(bitmap, cliprect, 1, (model3_layer_enable >> 1) & 0x1); + if (!(state->debug_layer_disable & 0x2)) + draw_layer(screen->machine, bitmap, cliprect, 1, (state->layer_enable >> 1) & 0x1); - if (!(debug_layer_disable & 0x1)) - draw_layer(bitmap, cliprect, 0, (model3_layer_enable >> 0) & 0x1); + if (!(state->debug_layer_disable & 0x1)) + draw_layer(screen->machine, bitmap, cliprect, 0, (state->layer_enable >> 0) & 0x1); //copy_screen(bitmap, cliprect); //draw_texture_sheet(bitmap, cliprect); - real3d_display_list = 0; + state->real3d_display_list = 0; return 0; } @@ -457,32 +420,37 @@ VIDEO_UPDATE( model3 ) READ64_HANDLER(model3_char_r) { - return m3_char_ram[offset]; + model3_state *state = space->machine->driver_data(); + return state->m3_char_ram[offset]; } WRITE64_HANDLER(model3_char_w) { - COMBINE_DATA(&m3_char_ram[offset]); + model3_state *state = space->machine->driver_data(); + COMBINE_DATA(&state->m3_char_ram[offset]); } READ64_HANDLER(model3_tile_r) { - return m3_tile_ram[offset]; + model3_state *state = space->machine->driver_data(); + return state->m3_tile_ram[offset]; } WRITE64_HANDLER(model3_tile_w) { - COMBINE_DATA(&m3_tile_ram[offset]); + model3_state *state = space->machine->driver_data(); + COMBINE_DATA(&state->m3_tile_ram[offset]); } READ64_HANDLER(model3_vid_reg_r) { + model3_state *state = space->machine->driver_data(); switch(offset) { - case 0x00/8: return vid_reg0; + case 0x00/8: return state->vid_reg0; case 0x08/8: return U64(0xffffffffffffffff); /* ??? */ - case 0x20/8: return (UINT64)model3_layer_enable << 52; - case 0x40/8: return ((UINT64)model3_layer_modulate1 << 32) | (UINT64)model3_layer_modulate2; + case 0x20/8: return (UINT64)state->layer_enable << 52; + case 0x40/8: return ((UINT64)state->layer_modulate1 << 32) | (UINT64)state->layer_modulate2; default: logerror("read reg %02X\n", offset);break; } return 0; @@ -490,31 +458,33 @@ READ64_HANDLER(model3_vid_reg_r) WRITE64_HANDLER(model3_vid_reg_w) { + model3_state *state = space->machine->driver_data(); switch(offset) { - case 0x00/8: logerror("vid_reg0: %08X%08X\n", (UINT32)(data>>32),(UINT32)(data)); vid_reg0 = data; break; + case 0x00/8: logerror("vid_reg0: %08X%08X\n", (UINT32)(data>>32),(UINT32)(data)); state->vid_reg0 = data; break; case 0x08/8: break; /* ??? */ case 0x10/8: model3_set_irq_line(space->machine, (data >> 56) & 0x0f, CLEAR_LINE); break; /* VBL IRQ Ack */ - case 0x20/8: model3_layer_enable = (data >> 52); break; + case 0x20/8: state->layer_enable = (data >> 52); break; - case 0x40/8: model3_layer_modulate1 = (UINT32)(data >> 32); - model3_layer_modulate2 = (UINT32)(data); + case 0x40/8: state->layer_modulate1 = (UINT32)(data >> 32); + state->layer_modulate2 = (UINT32)(data); break; - case 0x60/8: COMBINE_DATA(&layer_scroll[0]); break; - case 0x68/8: COMBINE_DATA(&layer_scroll[1]); break; + case 0x60/8: COMBINE_DATA(&state->layer_scroll[0]); break; + case 0x68/8: COMBINE_DATA(&state->layer_scroll[1]); break; default: logerror("model3_vid_reg_w: %02X, %08X%08X\n", offset, (UINT32)(data >> 32), (UINT32)(data)); break; } } WRITE64_HANDLER( model3_palette_w ) { + model3_state *state = space->machine->driver_data(); int r1,g1,b1,r2,g2,b2; UINT32 data1,data2; - COMBINE_DATA(&paletteram64[offset]); - data1 = BYTE_REVERSE32((UINT32)(paletteram64[offset] >> 32)); - data2 = BYTE_REVERSE32((UINT32)(paletteram64[offset] >> 0)); + COMBINE_DATA(&state->paletteram64[offset]); + data1 = BYTE_REVERSE32((UINT32)(state->paletteram64[offset] >> 32)); + data2 = BYTE_REVERSE32((UINT32)(state->paletteram64[offset] >> 0)); r1 = ((data1 >> 0) & 0x1f); g1 = ((data1 >> 5) & 0x1f); @@ -523,13 +493,14 @@ WRITE64_HANDLER( model3_palette_w ) g2 = ((data2 >> 5) & 0x1f); b2 = ((data2 >> 10) & 0x1f); - pal_lookup[(offset*2)+0] = (data1 & 0x8000) | (r1 << 10) | (g1 << 5) | b1; - pal_lookup[(offset*2)+1] = (data2 & 0x8000) | (r2 << 10) | (g2 << 5) | b2; + state->pal_lookup[(offset*2)+0] = (data1 & 0x8000) | (r1 << 10) | (g1 << 5) | b1; + state->pal_lookup[(offset*2)+1] = (data2 & 0x8000) | (r2 << 10) | (g2 << 5) | b2; } READ64_HANDLER( model3_palette_r ) { - return paletteram64[offset]; + model3_state *state = space->machine->driver_data(); + return state->paletteram64[offset]; } @@ -545,30 +516,32 @@ READ64_HANDLER( model3_palette_r ) */ static void invalidate_texture(running_machine *machine, int page, int texx, int texy, int texwidth, int texheight) { + model3_state *state = machine->driver_data(); int wtiles = 1 << texwidth; int htiles = 1 << texheight; int x, y; for (y = 0; y < htiles; y++) for (x = 0; x < wtiles; x++) - while (texcache[page][texy + y][texx + x] != NULL) + while (state->texcache[page][texy + y][texx + x] != NULL) { - cached_texture *freeme = texcache[page][texy + y][texx + x]; - texcache[page][texy + y][texx + x] = freeme->next; + cached_texture *freeme = state->texcache[page][texy + y][texx + x]; + state->texcache[page][texy + y][texx + x] = freeme->next; auto_free(machine, freeme); } } static cached_texture *get_texture(running_machine *machine, int page, int texx, int texy, int texwidth, int texheight, int format) { - cached_texture *tex = texcache[page][texy][texx]; + model3_state *state = machine->driver_data(); + cached_texture *tex = state->texcache[page][texy][texx]; int pixheight = 32 << texheight; int pixwidth = 32 << texwidth; UINT32 alpha = ~0; int x, y; /* if we have one already, validate it */ - for (tex = texcache[page][texy][texx]; tex != NULL; tex = tex->next) + for (tex = state->texcache[page][texy][texx]; tex != NULL; tex = tex->next) if (tex->width == texwidth && tex->height == texheight && tex->format == format) return tex; @@ -579,13 +552,13 @@ static cached_texture *get_texture(running_machine *machine, int page, int texx, tex->format = format; /* set the new texture */ - tex->next = texcache[page][texy][texx]; - texcache[page][texy][texx] = tex; + tex->next = state->texcache[page][texy][texx]; + state->texcache[page][texy][texx] = tex; /* decode it */ for (y = 0; y < pixheight; y++) { - const UINT16 *texsrc = &texture_ram[page][(texy * 32 + y) * 2048 + texx * 32]; + const UINT16 *texsrc = &state->texture_ram[page][(texy * 32 + y) * 2048 + texx * 32]; rgb_t *dest = tex->data + 2 * pixwidth * y; switch (format) @@ -677,21 +650,23 @@ static cached_texture *get_texture(running_machine *machine, int page, int texx, WRITE64_HANDLER( real3d_display_list_w ) { + model3_state *state = space->machine->driver_data(); if(ACCESSING_BITS_32_63) { - display_list_ram[offset*2] = BYTE_REVERSE32((UINT32)(data >> 32)); + state->display_list_ram[offset*2] = BYTE_REVERSE32((UINT32)(data >> 32)); } if(ACCESSING_BITS_0_31) { - display_list_ram[(offset*2)+1] = BYTE_REVERSE32((UINT32)(data)); + state->display_list_ram[(offset*2)+1] = BYTE_REVERSE32((UINT32)(data)); } } WRITE64_HANDLER( real3d_polygon_ram_w ) { + model3_state *state = space->machine->driver_data(); if(ACCESSING_BITS_32_63) { - polygon_ram[offset*2] = BYTE_REVERSE32((UINT32)(data >> 32)); + state->polygon_ram[offset*2] = BYTE_REVERSE32((UINT32)(data >> 32)); } if(ACCESSING_BITS_0_31) { - polygon_ram[(offset*2)+1] = BYTE_REVERSE32((UINT32)(data)); + state->polygon_ram[(offset*2)+1] = BYTE_REVERSE32((UINT32)(data)); } } @@ -707,7 +682,7 @@ static const UINT8 texture_decode[64] = 50, 51, 54, 55, 58, 59, 62, 63 }; -INLINE void write_texture16(int xpos, int ypos, int width, int height, int page, UINT16 *data) +INLINE void write_texture16(model3_state *state, int xpos, int ypos, int width, int height, int page, UINT16 *data) { int x,y,i,j; @@ -715,7 +690,7 @@ INLINE void write_texture16(int xpos, int ypos, int width, int height, int page, { for(x=xpos; x < xpos+width; x+=8) { - UINT16 *texture = &texture_ram[page][y*2048+x]; + UINT16 *texture = &state->texture_ram[page][y*2048+x]; int b = 0; for(j=y; j < y+8; j++) { for(i=x; i < x+8; i++) { @@ -730,7 +705,7 @@ INLINE void write_texture16(int xpos, int ypos, int width, int height, int page, } #ifdef UNUSED_FUNCTION -INLINE void write_texture8(int xpos, int ypos, int width, int height, int page, UINT16 *data) +INLINE void write_texture8(model3_state *state, int xpos, int ypos, int width, int height, int page, UINT16 *data) { int x,y,i,j; UINT16 color = 0x7c00; @@ -739,7 +714,7 @@ INLINE void write_texture8(int xpos, int ypos, int width, int height, int page, { for(x=xpos; x < xpos+width; x+=8) { - UINT16 *texture = &texture_ram[page][y*2048+x]; + UINT16 *texture = &state->texture_ram[page][y*2048+x]; for(j=y; j < y+4; j++) { for(i=x; i < x+8; i++) { *texture = color; @@ -754,34 +729,35 @@ INLINE void write_texture8(int xpos, int ypos, int width, int height, int page, static void real3d_upload_texture(running_machine *machine, UINT32 header, UINT32 *data) { + model3_state *state = machine->driver_data(); int width = 32 << ((header >> 14) & 0x7); int height = 32 << ((header >> 17) & 0x7); int xpos = (header & 0x3f) * 32; int ypos = ((header >> 7) & 0x1f) * 32; int page = (header >> 20) & 0x1; -// int bitdepth = (header >> 23) & 0x1; + //int bitdepth = (header >> 23) & 0x1; switch(header >> 24) { case 0x00: /* Texture with mipmaps */ -// if(bitdepth) { - write_texture16(xpos, ypos, width, height, page, (UINT16*)data); + //if(bitdepth) { + write_texture16(state, xpos, ypos, width, height, page, (UINT16*)data); invalidate_texture(machine, page, header & 0x3f, (header >> 7) & 0x1f, (header >> 14) & 0x7, (header >> 17) & 0x7); -// } else { + //} else { /* TODO: 8-bit textures are weird. need to figure out some additional bits */ //logerror("W: %d, H: %d, X: %d, Y: %d, P: %d, Bit: %d, : %08X, %08X\n", width, height, xpos, ypos, page, bitdepth, header & 0x00681040, header); //write_texture8(xpos, ypos, width, height, page, (UINT16*)data); -// } + //} break; case 0x01: /* Texture without mipmaps */ -// if(bitdepth) { - write_texture16(xpos, ypos, width, height, page, (UINT16*)data); + //if(bitdepth) { + write_texture16(state, xpos, ypos, width, height, page, (UINT16*)data); invalidate_texture(machine, page, header & 0x3f, (header >> 7) & 0x1f, (header >> 14) & 0x7, (header >> 17) & 0x7); -// } else { + //} else { /* TODO: 8-bit textures are weird. need to figure out some additional bits */ //logerror("W: %d, H: %d, X: %d, Y: %d, P: %d, Bit: %d, : %08X, %08X\n", width, height, xpos, ypos, page, bitdepth, header & 0x00681040, header); //write_texture8(xpos, ypos, width, height, page, (UINT16*)data); -// } + //} break; case 0x02: /* Only mipmaps */ break; @@ -795,27 +771,29 @@ static void real3d_upload_texture(running_machine *machine, UINT32 header, UINT3 void real3d_display_list_end(running_machine *machine) { + model3_state *state = machine->driver_data(); /* upload textures if there are any in the FIFO */ - if (texture_fifo_pos > 0) + if (state->texture_fifo_pos > 0) { int i = 0; - while(i < texture_fifo_pos) + while(i < state->texture_fifo_pos) { - int length = (texture_fifo[i] / 2) + 2; - UINT32 header = texture_fifo[i+1]; - real3d_upload_texture(machine, header, &texture_fifo[i+2]); + int length = (state->texture_fifo[i] / 2) + 2; + UINT32 header = state->texture_fifo[i+1]; + real3d_upload_texture(machine, header, &state->texture_fifo[i+2]); i += length; }; } - texture_fifo_pos = 0; - bitmap_fill(zbuffer, NULL, 0); - bitmap_fill(bitmap3d, NULL, 0x8000); + state->texture_fifo_pos = 0; + bitmap_fill(state->zbuffer, NULL, 0); + bitmap_fill(state->bitmap3d, NULL, 0x8000); real3d_traverse_display_list(machine); -// real3d_display_list = 1; + //state->real3d_display_list = 1; } void real3d_display_list1_dma(address_space *space, UINT32 src, UINT32 dst, int length, int byteswap) { + model3_state *state = space->machine->driver_data(); int i; int d = (dst & 0xffffff) / 4; for(i=0; i < length; i+=4) { @@ -825,13 +803,14 @@ void real3d_display_list1_dma(address_space *space, UINT32 src, UINT32 dst, int } else { w = space->read_dword(src); } - display_list_ram[d++] = w; + state->display_list_ram[d++] = w; src += 4; } } void real3d_display_list2_dma(address_space *space, UINT32 src, UINT32 dst, int length, int byteswap) { + model3_state *state = space->machine->driver_data(); int i; int d = (dst & 0xffffff) / 4; for(i=0; i < length; i+=4) { @@ -841,13 +820,14 @@ void real3d_display_list2_dma(address_space *space, UINT32 src, UINT32 dst, int } else { w = space->read_dword(src); } - culling_ram[d++] = w; + state->culling_ram[d++] = w; src += 4; } } void real3d_vrom_texture_dma(address_space *space, UINT32 src, UINT32 dst, int length, int byteswap) { + model3_state *state = space->machine->driver_data(); if((dst & 0xff) == 0) { UINT32 address, header; @@ -859,12 +839,13 @@ void real3d_vrom_texture_dma(address_space *space, UINT32 src, UINT32 dst, int l address = space->read_dword((src+0)); header = space->read_dword((src+4)); } - real3d_upload_texture(space->machine, header, (UINT32*)&model3_vrom[address]); + real3d_upload_texture(space->machine, header, (UINT32*)&state->vrom[address]); } } void real3d_texture_fifo_dma(address_space *space, UINT32 src, int length, int byteswap) { + model3_state *state = space->machine->driver_data(); int i; for(i=0; i < length; i+=4) { UINT32 w; @@ -873,14 +854,15 @@ void real3d_texture_fifo_dma(address_space *space, UINT32 src, int length, int b } else { w = space->read_dword(src); } - texture_fifo[texture_fifo_pos] = w; - texture_fifo_pos++; + state->texture_fifo[state->texture_fifo_pos] = w; + state->texture_fifo_pos++; src += 4; } } void real3d_polygon_ram_dma(address_space *space, UINT32 src, UINT32 dst, int length, int byteswap) { + model3_state *state = space->machine->driver_data(); int i; int d = (dst & 0xffffff) / 4; for(i=0; i < length; i+=4) { @@ -890,7 +872,7 @@ void real3d_polygon_ram_dma(address_space *space, UINT32 src, UINT32 dst, int le } else { w = space->read_dword(src); } - polygon_ram[d++] = w; + state->polygon_ram[d++] = w; src += 4; } } @@ -939,8 +921,12 @@ static void matrix_multiply(MATRIX a, MATRIX b, MATRIX *out) memcpy(out, &tmp, sizeof(MATRIX)); } -static void init_matrix_stack(void) +static void init_matrix_stack(running_machine *machine) { + model3_state *state = machine->driver_data(); + MATRIX *matrix_stack; + matrix_stack = state->matrix_stack = auto_alloc_array_clear(machine, MATRIX, MATRIX_STACK_SIZE); + /* initialize the first matrix as identity */ matrix_stack[0][0][0] = 1.0f; matrix_stack[0][0][1] = 0.0f; @@ -959,36 +945,36 @@ static void init_matrix_stack(void) matrix_stack[0][3][2] = 0.0f; matrix_stack[0][3][3] = 1.0f; - matrix_stack_ptr = 0; + state->matrix_stack_ptr = 0; } -static void get_top_matrix(MATRIX *out) +static void get_top_matrix(model3_state *state, MATRIX *out) { - memcpy( out, &matrix_stack[matrix_stack_ptr], sizeof(MATRIX)); + memcpy( out, &state->matrix_stack[state->matrix_stack_ptr], sizeof(MATRIX)); } -static void push_matrix_stack(void) +static void push_matrix_stack(model3_state *state) { - matrix_stack_ptr++; - if (matrix_stack_ptr >= MATRIX_STACK_SIZE) + state->matrix_stack_ptr++; + if (state->matrix_stack_ptr >= MATRIX_STACK_SIZE) fatalerror("push_matrix_stack: matrix stack overflow"); - memcpy( &matrix_stack[matrix_stack_ptr], &matrix_stack[matrix_stack_ptr-1], sizeof(MATRIX)); + memcpy( &state->matrix_stack[state->matrix_stack_ptr], &state->matrix_stack[state->matrix_stack_ptr-1], sizeof(MATRIX)); } -static void pop_matrix_stack(void) +static void pop_matrix_stack(model3_state *state) { - matrix_stack_ptr--; - if (matrix_stack_ptr < 0) + state->matrix_stack_ptr--; + if (state->matrix_stack_ptr < 0) fatalerror("pop_matrix_stack: matrix stack underflow"); } -static void multiply_matrix_stack(MATRIX matrix) +static void multiply_matrix_stack(model3_state *state, MATRIX matrix) { - matrix_multiply(matrix, matrix_stack[matrix_stack_ptr], &matrix_stack[matrix_stack_ptr]); + matrix_multiply(matrix, state->matrix_stack[state->matrix_stack_ptr], &state->matrix_stack[state->matrix_stack_ptr]); } -static void translate_matrix_stack(float x, float y, float z) +static void translate_matrix_stack(model3_state *state, float x, float y, float z) { MATRIX tm; @@ -997,7 +983,7 @@ static void translate_matrix_stack(float x, float y, float z) tm[2][0] = 0.0f; tm[2][1] = 0.0f; tm[2][2] = 1.0f; tm[2][3] = 0.0f; tm[3][0] = x; tm[3][1] = y; tm[3][2] = z; tm[3][3] = 1.0f; - matrix_multiply(tm, matrix_stack[matrix_stack_ptr], &matrix_stack[matrix_stack_ptr]); + matrix_multiply(tm, state->matrix_stack[state->matrix_stack_ptr], &state->matrix_stack[state->matrix_stack_ptr]); } /*****************************************************************************/ @@ -1077,13 +1063,15 @@ static int clip_polygon(const poly_vertex *v, int num_vertices, PLANE cp, poly_v static void render_one(running_machine *machine, TRIANGLE *tri) { - poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(poly); + model3_state *state = machine->driver_data(); + poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(state->poly); poly_draw_scanline_func callback = NULL; tri->v[0].pz = 1.0f / tri->v[0].pz; tri->v[1].pz = 1.0f / tri->v[1].pz; tri->v[2].pz = 1.0f / tri->v[2].pz; + extra->zbuffer = state->zbuffer; if (tri->param & TRI_PARAM_TEXTURE_ENABLE) { tri->v[0].pu = tri->v[0].pu * tri->v[0].pz * 256.0f; @@ -1104,7 +1092,7 @@ static void render_one(running_machine *machine, TRIANGLE *tri) callback = (tri->transparency >= 32) ? draw_scanline_normal : draw_scanline_trans; else callback = draw_scanline_alpha; - poly_render_triangle(poly, bitmap3d, &clip3d, callback, 3, &tri->v[0], &tri->v[1], &tri->v[2]); + poly_render_triangle(state->poly, state->bitmap3d, &state->clip3d, callback, 3, &tri->v[0], &tri->v[1], &tri->v[2]); } else { @@ -1112,13 +1100,14 @@ static void render_one(running_machine *machine, TRIANGLE *tri) extra->polygon_intensity = tri->intensity; extra->color = tri->color; - poly_render_triangle(poly, bitmap3d, &clip3d, draw_scanline_color, 1, &tri->v[0], &tri->v[1], &tri->v[2]); + poly_render_triangle(state->poly, state->bitmap3d, &state->clip3d, draw_scanline_color, 1, &tri->v[0], &tri->v[1], &tri->v[2]); } } static void draw_model(running_machine *machine, UINT32 addr) { - UINT32 *model = (addr >= 0x100000) ? &model3_vrom[addr] : &polygon_ram[addr]; + model3_state *state = machine->driver_data(); + UINT32 *model = (addr >= 0x100000) ? &state->vrom[addr] : &state->polygon_ram[addr]; UINT32 header[7]; int index = 0; int last_polygon = FALSE, back_face = FALSE; @@ -1132,17 +1121,17 @@ static void draw_model(running_machine *machine, UINT32 addr) MATRIX transform_matrix; float center_x, center_y; - if(model3_step < 0x15) { /* position coordinates are 17.15 fixed-point in Step 1.0 */ + if(state->step < 0x15) { /* position coordinates are 17.15 fixed-point in Step 1.0 */ fixed_point_fraction = 1.0f / 32768.0f; } else { /* 13.19 fixed-point in other Steps */ fixed_point_fraction = 1.0f / 524288.0f; } - get_top_matrix(&transform_matrix); + get_top_matrix(state, &transform_matrix); /* current viewport center coordinates on screen */ - center_x = (float)(viewport_region_x + (viewport_region_width / 2)); - center_y = (float)(viewport_region_y + (viewport_region_height / 2)); + center_x = (float)(state->viewport_region_x + (state->viewport_region_width / 2)); + center_y = (float)(state->viewport_region_y + (state->viewport_region_height / 2)); memset(prev_vertex, 0, sizeof(prev_vertex)); @@ -1210,9 +1199,9 @@ static void draw_model(running_machine *machine, UINT32 addr) (normal[1] * transform_matrix[1][2]) + (normal[2] * transform_matrix[2][2]); - sn[0] *= coordinate_system[0][1]; - sn[1] *= coordinate_system[1][2]; - sn[2] *= coordinate_system[2][0]; + sn[0] *= state->coordinate_system[0][1]; + sn[1] *= state->coordinate_system[1][2]; + sn[2] *= state->coordinate_system[2][0]; /* TODO: depth bias */ /* transform vertices */ @@ -1229,19 +1218,19 @@ static void draw_model(running_machine *machine, UINT32 addr) matrix_multiply_vector(transform_matrix, vect, &p[i]); /* apply coordinate system */ - clip_vert[i].x = p[i][0] * coordinate_system[0][1]; - clip_vert[i].y = p[i][1] * coordinate_system[1][2]; - clip_vert[i].pz = p[i][2] * coordinate_system[2][0]; + clip_vert[i].x = p[i][0] * state->coordinate_system[0][1]; + clip_vert[i].y = p[i][1] * state->coordinate_system[1][2]; + clip_vert[i].pz = p[i][2] * state->coordinate_system[2][0]; clip_vert[i].pu = vertex[i].pu * texture_coord_scale; clip_vert[i].pv = vertex[i].pv * texture_coord_scale; } /* clip against view frustum */ - num_vertices = clip_polygon(clip_vert, num_vertices, clip_plane[0], clip_vert); - num_vertices = clip_polygon(clip_vert, num_vertices, clip_plane[1], clip_vert); - num_vertices = clip_polygon(clip_vert, num_vertices, clip_plane[2], clip_vert); - num_vertices = clip_polygon(clip_vert, num_vertices, clip_plane[3], clip_vert); - num_vertices = clip_polygon(clip_vert, num_vertices, clip_plane[4], clip_vert); + num_vertices = clip_polygon(clip_vert, num_vertices, state->clip_plane[0], clip_vert); + num_vertices = clip_polygon(clip_vert, num_vertices, state->clip_plane[1], clip_vert); + num_vertices = clip_polygon(clip_vert, num_vertices, state->clip_plane[2], clip_vert); + num_vertices = clip_polygon(clip_vert, num_vertices, state->clip_plane[3], clip_vert); + num_vertices = clip_polygon(clip_vert, num_vertices, state->clip_plane[4], clip_vert); /* backface culling */ if( (header[6] & 0x800000) && (!(header[1] & 0x0010)) ) { @@ -1257,15 +1246,15 @@ static void draw_model(running_machine *machine, UINT32 addr) /* homogeneous Z-divide, screen-space transformation */ for(i=0; i < num_vertices; i++) { float ooz = 1.0f / clip_vert[i].pz; - clip_vert[i].x = ((clip_vert[i].x * ooz) * viewport_focal_length) + center_x; - clip_vert[i].y = ((clip_vert[i].y * ooz) * viewport_focal_length) + center_y; + clip_vert[i].x = ((clip_vert[i].x * ooz) * state->viewport_focal_length) + center_x; + clip_vert[i].y = ((clip_vert[i].y * ooz) * state->viewport_focal_length) + center_y; } // lighting if ((header[6] & 0x10000) == 0) { - dot = dot_product3(sn, parallel_light); - intensity = ((dot * parallel_light_intensity) + ambient_light_intensity) * 256.0f; + dot = dot_product3(sn, state->parallel_light); + intensity = ((dot * state->parallel_light_intensity) + state->ambient_light_intensity) * 256.0f; if (intensity > 256) { intensity = 256; @@ -1312,27 +1301,27 @@ static void draw_model(running_machine *machine, UINT32 addr) /*****************************************************************************/ /* display list parser */ -static UINT32 *get_memory_pointer(UINT32 address) +static UINT32 *get_memory_pointer(model3_state *state, UINT32 address) { if (address & 0x800000) { if (address >= 0x840000) { fatalerror("get_memory_pointer: invalid display list memory address %08X", address); } - return &display_list_ram[address & 0x7fffff]; + return &state->display_list_ram[address & 0x7fffff]; } else { if (address >= 0x100000) { fatalerror("get_memory_pointer: invalid node ram address %08X", address); } - return &culling_ram[address]; + return &state->culling_ram[address]; } } -static void load_matrix(int matrix_num, MATRIX *out) +static void load_matrix(model3_state *state, int matrix_num, MATRIX *out) { - float *matrix = (float *)get_memory_pointer(matrix_base_address + matrix_num * 12); + float *matrix = (float *)get_memory_pointer(state, state->matrix_base_address + matrix_num * 12); (*out)[0][0] = matrix[3]; (*out)[0][1] = matrix[6]; (*out)[0][2] = matrix[9]; (*out)[0][3] = 0.0f; (*out)[1][0] = matrix[4]; (*out)[1][1] = matrix[7]; (*out)[1][2] = matrix[10]; (*out)[1][3] = 0.0f; @@ -1342,8 +1331,10 @@ static void load_matrix(int matrix_num, MATRIX *out) static void traverse_list4(running_machine *machine, int lod_num, UINT32 address) { + model3_state *state = machine->driver_data(); + /* does something with the LOD selection */ - UINT32 *list = get_memory_pointer(address); + UINT32 *list = get_memory_pointer(state, address); UINT32 link = list[0]; draw_model(machine, link & 0xffffff); @@ -1351,13 +1342,14 @@ static void traverse_list4(running_machine *machine, int lod_num, UINT32 address static void traverse_list(running_machine *machine, UINT32 address) { - UINT32 *list = get_memory_pointer(address); + model3_state *state = machine->driver_data(); + UINT32 *list = get_memory_pointer(state, address); int list_ptr = 0; - if (list_depth > 2) + if (state->list_depth > 2) return; - list_depth++; + state->list_depth++; /* find the end of the list */ while (1) @@ -1377,11 +1369,11 @@ static void traverse_list(running_machine *machine, UINT32 address) { address = list[--list_ptr] & 0xffffff; if (address != 0 && address != 0x800800) -// if (address != 0) + //if (address != 0) draw_block(machine, address); } - list_depth--; + state->list_depth--; } INLINE void process_link(running_machine *machine, UINT32 address, UINT32 link) @@ -1412,31 +1404,32 @@ INLINE void process_link(running_machine *machine, UINT32 address, UINT32 link) static void draw_block(running_machine *machine, UINT32 address) { - const UINT32 *node = get_memory_pointer(address); + model3_state *state = machine->driver_data(); + const UINT32 *node = get_memory_pointer(state, address); UINT32 link; int node_matrix; float x, y, z; MATRIX matrix; int offset; - offset = (model3_step < 0x15) ? 2 : 0; + offset = (state->step < 0x15) ? 2 : 0; link = node[7 - offset]; /* apply matrix and translation */ node_matrix = node[3 - offset] & 0xfff; - load_matrix(node_matrix, &matrix); + load_matrix(state, node_matrix, &matrix); - push_matrix_stack(); + push_matrix_stack(state); if (node[0] & 0x10) { x = *(float *)&node[4 - offset]; y = *(float *)&node[5 - offset]; z = *(float *)&node[6 - offset]; - translate_matrix_stack(x, y, z); + translate_matrix_stack(state, x, y, z); } else if (node_matrix != 0) - multiply_matrix_stack(matrix); + multiply_matrix_stack(state, matrix); /* bit 0x08 of word 0 indicates a pointer list */ if (node[0] & 0x08) @@ -1444,7 +1437,7 @@ static void draw_block(running_machine *machine, UINT32 address) else process_link(machine, address, link); - pop_matrix_stack(); + pop_matrix_stack(state); /* handle the second link */ link = node[8 - offset]; @@ -1453,7 +1446,8 @@ static void draw_block(running_machine *machine, UINT32 address) static void draw_viewport(running_machine *machine, int pri, UINT32 address) { - const UINT32 *node = get_memory_pointer(address); + model3_state *state = machine->driver_data(); + const UINT32 *node = get_memory_pointer(state, address); UINT32 link_address; float /*viewport_left, viewport_right, */viewport_top, viewport_bottom; float /*fov_x,*/ fov_y; @@ -1472,10 +1466,10 @@ static void draw_viewport(running_machine *machine, int pri, UINT32 address) return; /* set viewport parameters */ - viewport_region_x = (node[26] & 0xffff) >> 4; /* 12.4 fixed point */ - viewport_region_y = ((node[26] >> 16) & 0xffff) >> 4; - viewport_region_width = (node[20] & 0xffff) >> 2; /* 14.2 fixed point */ - viewport_region_height = ((node[20] >> 16) & 0xffff) >> 2; + state->viewport_region_x = (node[26] & 0xffff) >> 4; /* 12.4 fixed point */ + state->viewport_region_y = ((node[26] >> 16) & 0xffff) >> 4; + state->viewport_region_width = (node[20] & 0xffff) >> 2; /* 14.2 fixed point */ + state->viewport_region_height = ((node[20] >> 16) & 0xffff) >> 2; /* frustum plane angles */ //viewport_left = RADIAN_TO_DEGREE(asin(*(float *)&node[12])); @@ -1484,29 +1478,29 @@ static void draw_viewport(running_machine *machine, int pri, UINT32 address) viewport_bottom = RADIAN_TO_DEGREE(asin(*(float *)&node[18])); /* build clipping planes */ - clip_plane[0].x = *(float *)&node[13]; clip_plane[0].y = 0.0f; clip_plane[0].z = *(float *)&node[12]; clip_plane[0].d = 0.0f; - clip_plane[1].x = *(float *)&node[17]; clip_plane[1].y = 0.0f; clip_plane[1].z = *(float *)&node[16]; clip_plane[1].d = 0.0f; - clip_plane[2].x = 0.0f; clip_plane[2].y = *(float *)&node[15]; clip_plane[2].z = *(float *)&node[14]; clip_plane[2].d = 0.0f; - clip_plane[3].x = 0.0f; clip_plane[3].y = *(float *)&node[19]; clip_plane[3].z = *(float *)&node[18]; clip_plane[3].d = 0.0f; - clip_plane[4].x = 0.0f; clip_plane[4].y = 0.0f; clip_plane[4].z = 1.0f; clip_plane[4].d = 1.0f; + state->clip_plane[0].x = *(float *)&node[13]; state->clip_plane[0].y = 0.0f; state->clip_plane[0].z = *(float *)&node[12]; state->clip_plane[0].d = 0.0f; + state->clip_plane[1].x = *(float *)&node[17]; state->clip_plane[1].y = 0.0f; state->clip_plane[1].z = *(float *)&node[16]; state->clip_plane[1].d = 0.0f; + state->clip_plane[2].x = 0.0f; state->clip_plane[2].y = *(float *)&node[15]; state->clip_plane[2].z = *(float *)&node[14]; state->clip_plane[2].d = 0.0f; + state->clip_plane[3].x = 0.0f; state->clip_plane[3].y = *(float *)&node[19]; state->clip_plane[3].z = *(float *)&node[18]; state->clip_plane[3].d = 0.0f; + state->clip_plane[4].x = 0.0f; state->clip_plane[4].y = 0.0f; state->clip_plane[4].z = 1.0f; state->clip_plane[4].d = 1.0f; /* compute field of view */ //fov_x = viewport_left + viewport_right; fov_y = viewport_top + viewport_bottom; - viewport_focal_length = (viewport_region_height / 2) / tan( (fov_y * M_PI / 180.0f) / 2.0f ); + state->viewport_focal_length = (state->viewport_region_height / 2) / tan( (fov_y * M_PI / 180.0f) / 2.0f ); - matrix_base_address = node[22]; + state->matrix_base_address = node[22]; /* TODO: where does node[23] point to ? LOD table ? */ /* set lighting parameters */ - parallel_light[0] = -*(float *)&node[5]; - parallel_light[1] = *(float *)&node[6]; - parallel_light[2] = *(float *)&node[4]; - parallel_light_intensity = *(float *)&node[7]; - ambient_light_intensity = (UINT8)(node[36] >> 8) / 256.0f; + state->parallel_light[0] = -*(float *)&node[5]; + state->parallel_light[1] = *(float *)&node[6]; + state->parallel_light[2] = *(float *)&node[4]; + state->parallel_light_intensity = *(float *)&node[7]; + state->ambient_light_intensity = (UINT8)(node[36] >> 8) / 256.0f; /* set coordinate system matrix */ - load_matrix(0, &coordinate_system); + load_matrix(state, 0, &state->coordinate_system); /* process a link */ process_link(machine, link_address, node[2]); @@ -1515,13 +1509,14 @@ static void draw_viewport(running_machine *machine, int pri, UINT32 address) static void real3d_traverse_display_list(running_machine *machine) { + model3_state *state = machine->driver_data(); int pri; - init_matrix_stack(); + init_matrix_stack(machine); for (pri = 0; pri < 4; pri++) draw_viewport(machine, pri, 0x800000); - poly_wait(poly, "real3d_traverse_display_list"); + poly_wait(state->poly, "real3d_traverse_display_list"); } diff --git a/src/mame/video/mystwarr.c b/src/mame/video/mystwarr.c index b27b0da0eed..92de52fea53 100644 --- a/src/mame/video/mystwarr.c +++ b/src/mame/video/mystwarr.c @@ -10,11 +10,6 @@ #include "includes/konamigx.h" #include "includes/mystwarr.h" -static int layer_colorbase[6]; -static int oinprion, cbparam; -static int sprite_colorbase, sub1_colorbase, last_psac_colorbase, gametype; -static int roz_enable, roz_rombank; -static tilemap_t *ult_936_tilemap; // create a decoding buffer to hold decodable tiles so that the ROM test will pass by // reading the original raw data @@ -65,39 +60,44 @@ static void mystwarr_decode_tiles(running_machine *machine) // Mystic Warriors requires tile based blending. -static void mystwarr_tile_callback(int layer, int *code, int *color, int *flags) +static void mystwarr_tile_callback(running_machine *machine, int layer, int *code, int *color, int *flags) { - if (layer==1) {if ((*code&0xff00)+(*color)==0x4101) cbparam++; else cbparam--;} //* water hack (TEMPORARY) + mystwarr_state *state = machine->driver_data(); + if (layer==1) {if ((*code&0xff00)+(*color)==0x4101) state->cbparam++; else state->cbparam--;} //* water hack (TEMPORARY) - *color = layer_colorbase[layer] | (*color>>1 & 0x1f); + *color = state->layer_colorbase[layer] | (*color>>1 & 0x1f); } // for games with 5bpp tile data -static void game5bpp_tile_callback(int layer, int *code, int *color, int *flags) +static void game5bpp_tile_callback(running_machine *machine, int layer, int *code, int *color, int *flags) { - *color = layer_colorbase[layer] | (*color>>1 & 0x1f); + mystwarr_state *state = machine->driver_data(); + *color = state->layer_colorbase[layer] | (*color>>1 & 0x1f); } // for games with 4bpp tile data -static void game4bpp_tile_callback(int layer, int *code, int *color, int *flags) +static void game4bpp_tile_callback(running_machine *machine, int layer, int *code, int *color, int *flags) { - *color = layer_colorbase[layer] | (*color>>2 & 0x0f); + mystwarr_state *state = machine->driver_data(); + *color = state->layer_colorbase[layer] | (*color>>2 & 0x0f); } -static void mystwarr_sprite_callback(int *code, int *color, int *priority) +static void mystwarr_sprite_callback(running_machine *machine, int *code, int *color, int *priority) { + mystwarr_state *state = machine->driver_data(); int c = *color; - *color = sprite_colorbase | (c & 0x001f); + *color = state->sprite_colorbase | (c & 0x001f); *priority = c & 0x00f0; } -static void metamrph_sprite_callback(int *code, int *color, int *priority) +static void metamrph_sprite_callback(running_machine *machine, int *code, int *color, int *priority) { + mystwarr_state *state = machine->driver_data(); int c = *color; int attr = c; - c = (c & 0x1f) | sprite_colorbase; + c = (c & 0x1f) | state->sprite_colorbase; // Bit8 & 9 are effect attributes. It is not known whether the effects are generated by external logic. if ((attr & 0x300) != 0x300) @@ -112,26 +112,28 @@ static void metamrph_sprite_callback(int *code, int *color, int *priority) } } -static void gaiapols_sprite_callback(int *code, int *color, int *priority) +static void gaiapols_sprite_callback(running_machine *machine, int *code, int *color, int *priority) { + mystwarr_state *state = machine->driver_data(); int c = *color; - *color = sprite_colorbase | (c>>4 & 0x20) | (c & 0x001f); + *color = state->sprite_colorbase | (c>>4 & 0x20) | (c & 0x001f); *priority = c & 0x00e0; } -static void martchmp_sprite_callback(int *code, int *color, int *priority) +static void martchmp_sprite_callback(running_machine *machine, int *code, int *color, int *priority) { + mystwarr_state *state = machine->driver_data(); int c = *color; // Bit8 & 9 are effect attributes. It is not known whether the effects are generated by external logic. if ((c & 0x3ff) == 0x11f) *color = K055555_FULLSHADOW; else - *color = sprite_colorbase | (c & 0x1f); + *color = state->sprite_colorbase | (c & 0x1f); - if (oinprion & 0xf0) - *priority = cbparam; // use PCU2 internal priority + if (state->oinprion & 0xf0) + *priority = state->cbparam; // use PCU2 internal priority else *priority = c & 0xf0; // use color implied priority } @@ -140,6 +142,7 @@ static void martchmp_sprite_callback(int *code, int *color, int *priority) static TILE_GET_INFO( get_gai_936_tile_info ) { + mystwarr_state *state = machine->driver_data(); int tileno, colour; UINT8 *ROM = machine->region("gfx4")->base(); UINT8 *dat1 = ROM, *dat2 = ROM + 0x20000, *dat3 = ROM + 0x60000; @@ -153,17 +156,18 @@ static TILE_GET_INFO( get_gai_936_tile_info ) if (dat2[tile_index] & 0x80) colour |= 0x10; - colour |= sub1_colorbase << 4; + colour |= state->sub1_colorbase << 4; SET_TILE_INFO(0, tileno, colour, 0); } VIDEO_START(gaiapols) { + mystwarr_state *state = machine->driver_data(); K055555_vh_start(machine); K054338_vh_start(machine); - gametype = 0; + state->gametype = 0; K056832_vh_start(machine, "gfx1", K056832_BPP_5, 0, NULL, game4bpp_tile_callback, 0); @@ -181,29 +185,31 @@ VIDEO_START(gaiapols) K053936_wraparound_enable(0, 1); K053936GP_set_offset(0, -10, 0); // floor tiles in demo loop2 (Elaine vs. boss) - ult_936_tilemap = tilemap_create(machine, get_gai_936_tile_info, tilemap_scan_rows, 16, 16, 512, 512); - tilemap_set_transparent_pen(ult_936_tilemap, 0); + state->ult_936_tilemap = tilemap_create(machine, get_gai_936_tile_info, tilemap_scan_rows, 16, 16, 512, 512); + tilemap_set_transparent_pen(state->ult_936_tilemap, 0); } static TILE_GET_INFO( get_ult_936_tile_info ) { + mystwarr_state *state = machine->driver_data(); int tileno, colour; UINT8 *ROM = machine->region("gfx4")->base(); UINT8 *dat1 = ROM, *dat2 = ROM + 0x40000; tileno = dat2[tile_index] | ((dat1[tile_index]&0x1f)<<8); - colour = sub1_colorbase; + colour = state->sub1_colorbase; SET_TILE_INFO(0, tileno, colour, (dat1[tile_index]&0x40) ? TILE_FLIPX : 0); } VIDEO_START(dadandrn) { + mystwarr_state *state = machine->driver_data(); K055555_vh_start(machine); K054338_vh_start(machine); - gametype = 1; + state->gametype = 1; K056832_vh_start(machine, "gfx1", K056832_BPP_5, 0, NULL, game5bpp_tile_callback, 0); @@ -223,16 +229,17 @@ VIDEO_START(dadandrn) K053936_wraparound_enable(0, 1); K053936GP_set_offset(0, -8, 0); // Brainy's laser - ult_936_tilemap = tilemap_create(machine, get_ult_936_tile_info, tilemap_scan_rows, 16, 16, 512, 512); - tilemap_set_transparent_pen(ult_936_tilemap, 0); + state->ult_936_tilemap = tilemap_create(machine, get_ult_936_tile_info, tilemap_scan_rows, 16, 16, 512, 512); + tilemap_set_transparent_pen(state->ult_936_tilemap, 0); } VIDEO_START(mystwarr) { + mystwarr_state *state = machine->driver_data(); K055555_vh_start(machine); K054338_vh_start(machine); - gametype = 0; + state->gametype = 0; K056832_vh_start(machine, "gfx1", K056832_BPP_5, 0, NULL, mystwarr_tile_callback, 0); @@ -247,14 +254,15 @@ VIDEO_START(mystwarr) K056832_set_LayerOffset(2, 2-3, 0); K056832_set_LayerOffset(3, 3-3, 0); - cbparam = 0; + state->cbparam = 0; } VIDEO_START(metamrph) { + mystwarr_state *state = machine->driver_data(); const char * rgn_250 = "gfx3"; - gametype = 0; + state->gametype = 0; K055555_vh_start(machine); K054338_vh_start(machine); @@ -279,7 +287,8 @@ VIDEO_START(metamrph) VIDEO_START(viostorm) { - gametype = 0; + mystwarr_state *state = machine->driver_data(); + state->gametype = 0; K055555_vh_start(machine); K054338_vh_start(machine); @@ -300,7 +309,8 @@ VIDEO_START(viostorm) VIDEO_START(martchmp) { - gametype = 0; + mystwarr_state *state = machine->driver_data(); + state->gametype = 0; K055555_vh_start(machine); K054338_vh_start(machine); @@ -325,18 +335,19 @@ VIDEO_START(martchmp) VIDEO_UPDATE(mystwarr) { + mystwarr_state *state = screen->machine->driver_data(); int i, old, blendmode=0; - if (cbparam<0) cbparam=0; else if (cbparam>=32) blendmode=(1<<16|GXMIX_BLEND_FORCE)<<2; //* water hack (TEMPORARY) + if (state->cbparam<0) state->cbparam=0; else if (state->cbparam>=32) blendmode=(1<<16|GXMIX_BLEND_FORCE)<<2; //* water hack (TEMPORARY) for (i = 0; i < 4; i++) { - old = layer_colorbase[i]; - layer_colorbase[i] = K055555_get_palette_index(i)<<4; - if( old != layer_colorbase[i] ) K056832_mark_plane_dirty(i); + old = state->layer_colorbase[i]; + state->layer_colorbase[i] = K055555_get_palette_index(i)<<4; + if( old != state->layer_colorbase[i] ) K056832_mark_plane_dirty(i); } - sprite_colorbase = K055555_get_palette_index(4)<<5; + state->sprite_colorbase = K055555_get_palette_index(4)<<5; konamigx_mixer(screen->machine, bitmap, cliprect, 0, 0, 0, 0, blendmode, 0, 0); return 0; @@ -344,16 +355,17 @@ VIDEO_UPDATE(mystwarr) VIDEO_UPDATE(metamrph) { + mystwarr_state *state = screen->machine->driver_data(); int i, old; for (i = 0; i < 4; i++) { - old = layer_colorbase[i]; - layer_colorbase[i] = K055555_get_palette_index(i)<<4; - if (old != layer_colorbase[i]) K056832_mark_plane_dirty(i); + old = state->layer_colorbase[i]; + state->layer_colorbase[i] = K055555_get_palette_index(i)<<4; + if (old != state->layer_colorbase[i]) K056832_mark_plane_dirty(i); } - sprite_colorbase = K055555_get_palette_index(4)<<4; + state->sprite_colorbase = K055555_get_palette_index(4)<<4; konamigx_mixer(screen->machine, bitmap, cliprect, 0, GXSUB_K053250 | GXSUB_4BPP, 0, 0, 0, 0, 0); return 0; @@ -361,22 +373,23 @@ VIDEO_UPDATE(metamrph) VIDEO_UPDATE(martchmp) { + mystwarr_state *state = screen->machine->driver_data(); int i, old, blendmode; for (i = 0; i < 4; i++) { - old = layer_colorbase[i]; - layer_colorbase[i] = K055555_get_palette_index(i)<<4; - if (old != layer_colorbase[i]) K056832_mark_plane_dirty(i); + old = state->layer_colorbase[i]; + state->layer_colorbase[i] = K055555_get_palette_index(i)<<4; + if (old != state->layer_colorbase[i]) K056832_mark_plane_dirty(i); } - sprite_colorbase = K055555_get_palette_index(4)<<5; + state->sprite_colorbase = K055555_get_palette_index(4)<<5; - cbparam = K055555_read_register(K55_PRIINP_8); - oinprion = K055555_read_register(K55_OINPRI_ON); + state->cbparam = K055555_read_register(K55_PRIINP_8); + state->oinprion = K055555_read_register(K55_OINPRI_ON); // not quite right - blendmode = (oinprion==0xef && K054338_read_register(K338_REG_PBLEND)) ? ((1<<16|GXMIX_BLEND_FORCE)<<2) : 0; + blendmode = (state->oinprion==0xef && K054338_read_register(K338_REG_PBLEND)) ? ((1<<16|GXMIX_BLEND_FORCE)<<2) : 0; konamigx_mixer(screen->machine, bitmap, cliprect, 0, 0, 0, 0, blendmode, 0, 0); return 0; @@ -386,16 +399,17 @@ VIDEO_UPDATE(martchmp) WRITE16_HANDLER(ddd_053936_enable_w) { + mystwarr_state *state = space->machine->driver_data(); if (ACCESSING_BITS_8_15) { - roz_enable = data & 0x0100; - roz_rombank = (data & 0xc000)>>14; + state->roz_enable = data & 0x0100; + state->roz_rombank = (data & 0xc000)>>14; } } WRITE16_HANDLER(ddd_053936_clip_w) { - static UINT16 clip; + mystwarr_state *state = space->machine->driver_data(); int old, clip_x, clip_y, size_x, size_y; int minx, maxx, miny, maxy; @@ -405,14 +419,14 @@ WRITE16_HANDLER(ddd_053936_clip_w) } else { - old = clip; - COMBINE_DATA(&clip); - if (clip != old) + old = state->clip; + COMBINE_DATA(&state->clip); + if (state->clip != old) { - clip_x = (clip & 0x003f) >> 0; - clip_y = (clip & 0x0fc0) >> 6; - size_x = (clip & 0x3000) >> 12; - size_y = (clip & 0xc000) >> 14; + clip_x = (state->clip & 0x003f) >> 0; + clip_y = (state->clip & 0x0fc0) >> 6; + size_x = (state->clip & 0x3000) >> 12; + size_y = (state->clip & 0xc000) >> 14; switch (size_x) { @@ -471,34 +485,37 @@ READ16_HANDLER(ddd_053936_tilerom_1_r) // reference: 223db0 in gaiapolis (ROMs 32n, 29n, 26n) READ16_HANDLER(gai_053936_tilerom_2_r) { + mystwarr_state *state = space->machine->driver_data(); UINT8 *ROM = (UINT8 *)space->machine->region("gfx3")->base(); - offset += (roz_rombank * 0x100000); + offset += (state->roz_rombank * 0x100000); return ROM[offset/2]<<8; } READ16_HANDLER(ddd_053936_tilerom_2_r) { + mystwarr_state *state = space->machine->driver_data(); UINT8 *ROM = (UINT8 *)space->machine->region("gfx3")->base(); - offset += (roz_rombank * 0x100000); + offset += (state->roz_rombank * 0x100000); return ROM[offset]<<8; } VIDEO_UPDATE(dadandrn) /* and gaiapols */ { + mystwarr_state *state = screen->machine->driver_data(); int i, newbase, dirty, rozmode; - if (gametype == 0) + if (state->gametype == 0) { - sprite_colorbase = (K055555_get_palette_index(4)<<4)&0x7f; + state->sprite_colorbase = (K055555_get_palette_index(4)<<4)&0x7f; rozmode = GXSUB_4BPP; } else { - sprite_colorbase = (K055555_get_palette_index(4)<<3)&0x7f; + state->sprite_colorbase = (K055555_get_palette_index(4)<<3)&0x7f; rozmode = GXSUB_8BPP; } @@ -507,9 +524,9 @@ VIDEO_UPDATE(dadandrn) /* and gaiapols */ for (i=0; i<4; i++) { newbase = K055555_get_palette_index(i)<<4; - if (layer_colorbase[i] != newbase) + if (state->layer_colorbase[i] != newbase) { - layer_colorbase[i] = newbase; + state->layer_colorbase[i] = newbase; K056832_mark_plane_dirty(i); } } @@ -519,9 +536,9 @@ VIDEO_UPDATE(dadandrn) /* and gaiapols */ for (dirty=0, i=0; i<4; i++) { newbase = K055555_get_palette_index(i)<<4; - if (layer_colorbase[i] != newbase) + if (state->layer_colorbase[i] != newbase) { - layer_colorbase[i] = newbase; + state->layer_colorbase[i] = newbase; dirty = 1; } } @@ -529,17 +546,17 @@ VIDEO_UPDATE(dadandrn) /* and gaiapols */ } - last_psac_colorbase = sub1_colorbase; - sub1_colorbase = K055555_get_palette_index(5); + state->last_psac_colorbase = state->sub1_colorbase; + state->sub1_colorbase = K055555_get_palette_index(5); - if (last_psac_colorbase != sub1_colorbase) + if (state->last_psac_colorbase != state->sub1_colorbase) { - tilemap_mark_all_tiles_dirty(ult_936_tilemap); + tilemap_mark_all_tiles_dirty(state->ult_936_tilemap); if (MW_VERBOSE) popmessage("K053936: PSAC colorbase changed"); } - konamigx_mixer(screen->machine, bitmap, cliprect, (roz_enable) ? ult_936_tilemap : 0, rozmode, 0, 0, 0, 0, 0); + konamigx_mixer(screen->machine, bitmap, cliprect, (state->roz_enable) ? state->ult_936_tilemap : 0, rozmode, 0, 0, 0, 0, 0); return 0; } diff --git a/src/mame/video/qdrmfgp.c b/src/mame/video/qdrmfgp.c index b996ca4a6ae..835c28c88ff 100644 --- a/src/mame/video/qdrmfgp.c +++ b/src/mame/video/qdrmfgp.c @@ -12,7 +12,8 @@ void qdrmfgp_tile_callback(running_machine *machine, int layer, int *code, int *color, int *flags) { - *color = ((*color>>2) & 0x0f) | qdrmfgp_get_palette(); + qdrmfgp_state *state = machine->driver_data(); + *color = ((*color>>2) & 0x0f) | state->pal; } void qdrmfgp2_tile_callback(running_machine *machine, int layer, int *code, int *color, int *flags) diff --git a/src/mame/video/segag80v.c b/src/mame/video/segag80v.c index 379bc86c0a9..22d5d9990e7 100644 --- a/src/mame/video/segag80v.c +++ b/src/mame/video/segag80v.c @@ -15,9 +15,6 @@ #define IRQ_CLOCK (U34_CLOCK/0x1f788) /* 40Hz interrupt */ -UINT8 *segag80v_vectorram; -size_t segag80v_vectorram_size; -static int min_x, min_y; /* @@ -79,7 +76,7 @@ static int min_x, min_y; */ -INLINE int adjust_xy(int rawx, int rawy, int *outx, int *outy) +INLINE int adjust_xy(segag80v_state *state, int rawx, int rawy, int *outx, int *outy) { int clipped = FALSE; @@ -104,18 +101,19 @@ INLINE int adjust_xy(int rawx, int rawy, int *outx, int *outy) *outy &= 0x3ff; /* convert into .16 values */ - *outx = (*outx - (min_x - 512)) << 16; - *outy = (*outy - (min_y - 512)) << 16; + *outx = (*outx - (state->min_x - 512)) << 16; + *outy = (*outy - (state->min_y - 512)) << 16; return clipped; } static void sega_generate_vector_list(running_machine *machine) { + segag80v_state *state = machine->driver_data(); UINT8 *sintable = machine->region("proms")->base(); double total_time = 1.0 / (double)IRQ_CLOCK; UINT16 symaddr = 0; - UINT8 *vectorram = segag80v_vectorram; + UINT8 *vectorram = state->vectorram; vector_clear_list(); @@ -178,7 +176,7 @@ static void sega_generate_vector_list(running_machine *machine) int adjx, adjy, clipped; /* Add a starting point to the vector list. */ - clipped = adjust_xy(curx, cury, &adjx, &adjy); + clipped = adjust_xy(state, curx, cury, &adjx, &adjy); if (!clipped) vector_add_point(machine, adjx, adjy, 0, 0); @@ -244,7 +242,7 @@ static void sega_generate_vector_list(running_machine *machine) intensity = 0; /* Loop over the length of the vector. */ - clipped = adjust_xy(curx, cury, &adjx, &adjy); + clipped = adjust_xy(state, curx, cury, &adjx, &adjy); xaccum = yaccum = 0; while (length-- != 0 && total_time > 0) { @@ -283,7 +281,7 @@ static void sega_generate_vector_list(running_machine *machine) /* Apply the clipping from the DAC circuit. If the values clip */ /* the beam is turned off, but the computations continue right */ /* on going. */ - newclip = adjust_xy(curx, cury, &adjx, &adjy); + newclip = adjust_xy(state, curx, cury, &adjx, &adjy); if (newclip != clipped) { /* if we're just becoming unclipped, add an empty point */ @@ -327,10 +325,11 @@ static void sega_generate_vector_list(running_machine *machine) VIDEO_START( segag80v ) { - assert_always(segag80v_vectorram_size != 0, "segag80v_vectorram==0"); + segag80v_state *state = machine->driver_data(); + assert_always(state->vectorram_size != 0, "vectorram==0"); - min_x =machine->primary_screen->visible_area().min_x; - min_y =machine->primary_screen->visible_area().min_y; + state->min_x =machine->primary_screen->visible_area().min_x; + state->min_y =machine->primary_screen->visible_area().min_y; VIDEO_START_CALL(vector); } diff --git a/src/mame/video/segas32.c b/src/mame/video/segas32.c index d05a6d94a9e..3d77a25c7c2 100644 --- a/src/mame/video/segas32.c +++ b/src/mame/video/segas32.c @@ -199,13 +199,6 @@ * *************************************/ -struct layer_info -{ - bitmap_t * bitmap; - UINT8 * transparent; -}; - - struct extents_list { UINT8 scan_extent[256]; @@ -223,45 +216,6 @@ struct cache_entry -/************************************* - * - * Globals - * - *************************************/ - -UINT16 *system32_videoram; -UINT16 *system32_spriteram; -UINT16 *system32_paletteram[2]; -UINT16 system32_displayenable[2]; -UINT16 system32_tilebank_external; - - - -/************************************* - * - * Statics - * - *************************************/ - -static UINT8 is_multi32; - -/* tilemap cache */ -static struct cache_entry *cache_head; - -/* mixer data */ -static struct layer_info layer_data[11]; -static UINT16 mixer_control[2][0x40]; -static UINT16 *solid_0000; -static UINT16 *solid_ffff; - -/* sprite data */ -static UINT8 sprite_render_count; -static UINT8 sprite_control_latched[8]; -static UINT8 sprite_control[8]; -static UINT32 *spriteram_32bit; - - - /************************************* * * Prototypes @@ -269,8 +223,8 @@ static UINT32 *spriteram_32bit; *************************************/ static TILE_GET_INFO( get_tile_info ); -static void sprite_erase_buffer(void); -static void sprite_swap_buffers(void); +static void sprite_erase_buffer(segas32_state *state); +static void sprite_swap_buffers(segas32_state *state); static void sprite_render_list(running_machine *machine); @@ -284,16 +238,17 @@ static void sprite_render_list(running_machine *machine); static void common_start(running_machine *machine, int multi32) { + segas32_state *state = machine->driver_data(); int tmap; /* remember whether or not we are multi32 */ - is_multi32 = multi32; + state->is_multi32 = multi32; /* allocate a copy of spriteram in 32-bit format */ - spriteram_32bit = auto_alloc_array(machine, UINT32, 0x20000/4); + state->spriteram_32bit = auto_alloc_array(machine, UINT32, 0x20000/4); /* allocate the tilemap cache */ - cache_head = NULL; + state->cache_head = NULL; for (tmap = 0; tmap < TILEMAP_CACHE_SIZE; tmap++) { struct cache_entry *entry = auto_alloc(machine, struct cache_entry); @@ -301,27 +256,27 @@ static void common_start(running_machine *machine, int multi32) entry->tmap = tilemap_create(machine, get_tile_info, tilemap_scan_rows, 16,16, 32,16); entry->page = 0xff; entry->bank = 0; - entry->next = cache_head; + entry->next = state->cache_head; tilemap_set_user_data(entry->tmap, entry); - cache_head = entry; + state->cache_head = entry; } /* allocate the bitmaps (a few extra for multi32) */ for (tmap = 0; tmap < 9 + 2 * multi32; tmap++) { - layer_data[tmap].bitmap = auto_bitmap_alloc(machine, 416, 224, BITMAP_FORMAT_INDEXED16); - layer_data[tmap].transparent = auto_alloc_array_clear(machine, UINT8, 256); + state->layer_data[tmap].bitmap = auto_bitmap_alloc(machine, 416, 224, BITMAP_FORMAT_INDEXED16); + state->layer_data[tmap].transparent = auto_alloc_array_clear(machine, UINT8, 256); } /* allocate pre-rendered solid lines of 0's and ffff's */ - solid_0000 = auto_alloc_array(machine, UINT16, 512); - memset(solid_0000, 0x00, sizeof(solid_0000[0]) * 512); - solid_ffff = auto_alloc_array(machine, UINT16, 512); - memset(solid_ffff, 0xff, sizeof(solid_ffff[0]) * 512); + state->solid_0000 = auto_alloc_array(machine, UINT16, 512); + memset(state->solid_0000, 0x00, sizeof(state->solid_0000[0]) * 512); + state->solid_ffff = auto_alloc_array(machine, UINT16, 512); + memset(state->solid_ffff, 0xff, sizeof(state->solid_ffff[0]) * 512); /* initialize videoram */ - system32_videoram[0x1ff00/2] = 0x8000; + state->system32_videoram[0x1ff00/2] = 0x8000; } @@ -346,26 +301,27 @@ VIDEO_START( multi32 ) static TIMER_CALLBACK( update_sprites ) { + segas32_state *state = machine->driver_data(); /* if automatic mode is selected, do it every frame (0) or every other frame (1) */ - if (!(sprite_control[3] & 2)) + if (!(state->sprite_control[3] & 2)) { /* if we count down to the start, process the automatic swapping, but only after a short delay */ - if (sprite_render_count-- == 0) + if (state->sprite_render_count-- == 0) { - sprite_control[0] = 3; - sprite_render_count = sprite_control[3] & 1; + state->sprite_control[0] = 3; + state->sprite_render_count = state->sprite_control[3] & 1; } } /* look for pending commands */ - if (sprite_control[0] & 2) - sprite_erase_buffer(); - if (sprite_control[0] & 1) + if (state->sprite_control[0] & 2) + sprite_erase_buffer(state); + if (state->sprite_control[0] & 1) { - sprite_swap_buffers(); + sprite_swap_buffers(state); sprite_render_list(machine); } - sprite_control[0] = 0; + state->sprite_control[0] = 0; } @@ -415,8 +371,9 @@ INLINE void update_color(running_machine *machine, int offset, UINT16 data) } -INLINE UINT16 common_paletteram_r(int which, offs_t offset) +INLINE UINT16 common_paletteram_r(address_space *space, int which, offs_t offset) { + segas32_state *state = space->machine->driver_data(); int convert; /* the lower half of palette RAM is formatted xBBBBBGGGGGRRRRR */ @@ -427,14 +384,15 @@ INLINE UINT16 common_paletteram_r(int which, offs_t offset) offset &= 0x3fff; if (!convert) - return system32_paletteram[which][offset]; + return state->system32_paletteram[which][offset]; else - return xBBBBBGGGGGRRRRR_to_xBGRBBBBGGGGRRRR(system32_paletteram[which][offset]); + return xBBBBBGGGGGRRRRR_to_xBGRBBBBGGGGRRRR(state->system32_paletteram[which][offset]); } static void common_paletteram_w(address_space *space, int which, offs_t offset, UINT16 data, UINT16 mem_mask) { + segas32_state *state = space->machine->driver_data(); UINT16 value; int convert; @@ -446,24 +404,24 @@ static void common_paletteram_w(address_space *space, int which, offs_t offset, offset &= 0x3fff; /* read, modify, and write the new value, updating the palette */ - value = system32_paletteram[which][offset]; + value = state->system32_paletteram[which][offset]; if (convert) value = xBBBBBGGGGGRRRRR_to_xBGRBBBBGGGGRRRR(value); COMBINE_DATA(&value); if (convert) value = xBGRBBBBGGGGRRRR_to_xBBBBBGGGGGRRRRR(value); - system32_paletteram[which][offset] = value; + state->system32_paletteram[which][offset] = value; update_color(space->machine, 0x4000*which + offset, value); /* if blending is enabled, writes go to both halves of palette RAM */ - if (mixer_control[which][0x4e/2] & 0x0880) + if (state->mixer_control[which][0x4e/2] & 0x0880) { offset ^= 0x2000; /* read, modify, and write the new value, updating the palette */ - value = system32_paletteram[which][offset]; + value = state->system32_paletteram[which][offset]; if (convert) value = xBBBBBGGGGGRRRRR_to_xBGRBBBBGGGGRRRR(value); COMBINE_DATA(&value); if (convert) value = xBGRBBBBGGGGRRRR_to_xBBBBBGGGGGRRRRR(value); - system32_paletteram[which][offset] = value; + state->system32_paletteram[which][offset] = value; update_color(space->machine, 0x4000*which + offset, value); } } @@ -478,7 +436,7 @@ static void common_paletteram_w(address_space *space, int which, offs_t offset, READ16_HANDLER( system32_paletteram_r ) { - return common_paletteram_r(0, offset); + return common_paletteram_r(space, 0, offset); } @@ -490,8 +448,8 @@ WRITE16_HANDLER( system32_paletteram_w ) READ32_HANDLER( multi32_paletteram_0_r ) { - return common_paletteram_r(0, offset*2+0) | - (common_paletteram_r(0, offset*2+1) << 16); + return common_paletteram_r(space, 0, offset*2+0) | + (common_paletteram_r(space, 0, offset*2+1) << 16); } @@ -506,8 +464,8 @@ WRITE32_HANDLER( multi32_paletteram_0_w ) READ32_HANDLER( multi32_paletteram_1_r ) { - return common_paletteram_r(1, offset*2+0) | - (common_paletteram_r(1, offset*2+1) << 16); + return common_paletteram_r(space, 1, offset*2+0) | + (common_paletteram_r(space, 1, offset*2+1) << 16); } @@ -529,13 +487,15 @@ WRITE32_HANDLER( multi32_paletteram_1_w ) READ16_HANDLER( system32_videoram_r ) { - return system32_videoram[offset]; + segas32_state *state = space->machine->driver_data(); + return state->system32_videoram[offset]; } WRITE16_HANDLER( system32_videoram_w ) { - COMBINE_DATA(&system32_videoram[offset]); + segas32_state *state = space->machine->driver_data(); + COMBINE_DATA(&state->system32_videoram[offset]); /* if we are not in the control area, just update any affected tilemaps */ if (offset < 0x1ff00/2) @@ -545,7 +505,7 @@ WRITE16_HANDLER( system32_videoram_w ) offset %= 0x200; /* scan the cache for a matching pages */ - for (entry = cache_head; entry != NULL; entry = entry->next) + for (entry = state->cache_head; entry != NULL; entry = entry->next) if (entry->page == page) tilemap_mark_tile_dirty(entry->tmap, offset); } @@ -554,8 +514,9 @@ WRITE16_HANDLER( system32_videoram_w ) READ32_HANDLER( multi32_videoram_r ) { - return system32_videoram[offset*2+0] | - (system32_videoram[offset*2+1] << 16); + segas32_state *state = space->machine->driver_data(); + return state->system32_videoram[offset*2+0] | + (state->system32_videoram[offset*2+1] << 16); } @@ -577,13 +538,14 @@ WRITE32_HANDLER( multi32_videoram_w ) READ16_HANDLER( system32_sprite_control_r ) { + segas32_state *state = space->machine->driver_data(); switch (offset) { case 0: /* D1 : Seems to be '1' only during an erase in progress, this occurs very briefly though. D0 : Selected frame buffer (0= A, 1= B) */ - return 0xfffc | (int)(layer_data[MIXER_LAYER_SPRITES].bitmap < layer_data[MIXER_LAYER_SPRITES_2].bitmap); + return 0xfffc | (int)(state->layer_data[MIXER_LAYER_SPRITES].bitmap < state->layer_data[MIXER_LAYER_SPRITES_2].bitmap); case 1: /* D1 : ? @@ -602,27 +564,27 @@ READ16_HANDLER( system32_sprite_control_r ) case 2: /* D1 : 1= Vertical flip, 0= Normal orientation D0 : 1= Horizontal flip, 0= Normal orientation */ - return 0xfffc | sprite_control_latched[2]; + return 0xfffc | state->sprite_control_latched[2]; case 3: /* D1 : 1= Manual mode, 0= Automatic mode D0 : 1= 30 Hz update, 0= 60 Hz update (automatic mode only) */ - return 0xfffc | sprite_control_latched[3]; + return 0xfffc | state->sprite_control_latched[3]; case 4: /* D1 : ? D0 : ? */ - return 0xfffc | sprite_control_latched[4]; + return 0xfffc | state->sprite_control_latched[4]; case 5: /* D1 : ? D0 : ? */ - return 0xfffc | sprite_control_latched[5]; + return 0xfffc | state->sprite_control_latched[5]; case 6: /* D0 : 1= 416 pixels 0= 320 pixels */ - return 0xfffc | (sprite_control_latched[6] & 1); + return 0xfffc | (state->sprite_control_latched[6] & 1); case 7: /* D1 : ? @@ -635,8 +597,9 @@ READ16_HANDLER( system32_sprite_control_r ) WRITE16_HANDLER( system32_sprite_control_w ) { + segas32_state *state = space->machine->driver_data(); if (ACCESSING_BITS_0_7) - sprite_control[offset & 7] = data; + state->sprite_control[offset & 7] = data; } @@ -665,38 +628,42 @@ WRITE32_HANDLER( multi32_sprite_control_w ) READ16_HANDLER( system32_spriteram_r ) { - return system32_spriteram[offset]; + segas32_state *state = space->machine->driver_data(); + return state->system32_spriteram[offset]; } WRITE16_HANDLER( system32_spriteram_w ) { - COMBINE_DATA(&system32_spriteram[offset]); - spriteram_32bit[offset/2] = - ((system32_spriteram[offset | 1] >> 8 ) & 0x000000ff) | - ((system32_spriteram[offset | 1] << 8 ) & 0x0000ff00) | - ((system32_spriteram[offset & ~1] << 8 ) & 0x00ff0000) | - ((system32_spriteram[offset & ~1] << 24) & 0xff000000); + segas32_state *state = space->machine->driver_data(); + COMBINE_DATA(&state->system32_spriteram[offset]); + state->spriteram_32bit[offset/2] = + ((state->system32_spriteram[offset | 1] >> 8 ) & 0x000000ff) | + ((state->system32_spriteram[offset | 1] << 8 ) & 0x0000ff00) | + ((state->system32_spriteram[offset & ~1] << 8 ) & 0x00ff0000) | + ((state->system32_spriteram[offset & ~1] << 24) & 0xff000000); } READ32_HANDLER( multi32_spriteram_r ) { - return system32_spriteram[offset*2+0] | - (system32_spriteram[offset*2+1] << 16); + segas32_state *state = space->machine->driver_data(); + return state->system32_spriteram[offset*2+0] | + (state->system32_spriteram[offset*2+1] << 16); } WRITE32_HANDLER( multi32_spriteram_w ) { + segas32_state *state = space->machine->driver_data(); data = SWAP_HALVES(data); mem_mask = SWAP_HALVES(mem_mask); - COMBINE_DATA((UINT32 *)&system32_spriteram[offset*2]); - spriteram_32bit[offset/2] = - ((system32_spriteram[offset | 1] >> 8 ) & 0x000000ff) | - ((system32_spriteram[offset | 1] << 8 ) & 0x0000ff00) | - ((system32_spriteram[offset & ~1] << 8 ) & 0x00ff0000) | - ((system32_spriteram[offset & ~1] << 24) & 0xff000000); + COMBINE_DATA((UINT32 *)&state->system32_spriteram[offset*2]); + state->spriteram_32bit[offset/2] = + ((state->system32_spriteram[offset | 1] >> 8 ) & 0x000000ff) | + ((state->system32_spriteram[offset | 1] << 8 ) & 0x0000ff00) | + ((state->system32_spriteram[offset & ~1] << 8 ) & 0x00ff0000) | + ((state->system32_spriteram[offset & ~1] << 24) & 0xff000000); } @@ -709,28 +676,32 @@ WRITE32_HANDLER( multi32_spriteram_w ) READ16_HANDLER( system32_mixer_r ) { - return mixer_control[0][offset]; + segas32_state *state = space->machine->driver_data(); + return state->mixer_control[0][offset]; } WRITE16_HANDLER( system32_mixer_w ) { - COMBINE_DATA(&mixer_control[0][offset]); + segas32_state *state = space->machine->driver_data(); + COMBINE_DATA(&state->mixer_control[0][offset]); } WRITE32_HANDLER( multi32_mixer_0_w ) { + segas32_state *state = space->machine->driver_data(); data = SWAP_HALVES(data); mem_mask = SWAP_HALVES(mem_mask); - COMBINE_DATA((UINT32 *)&mixer_control[0][offset*2]); + COMBINE_DATA((UINT32 *)&state->mixer_control[0][offset*2]); } WRITE32_HANDLER( multi32_mixer_1_w ) { + segas32_state *state = space->machine->driver_data(); data = SWAP_HALVES(data); mem_mask = SWAP_HALVES(mem_mask); - COMBINE_DATA((UINT32 *)&mixer_control[1][offset*2]); + COMBINE_DATA((UINT32 *)&state->mixer_control[1][offset*2]); } @@ -741,13 +712,13 @@ WRITE32_HANDLER( multi32_mixer_1_w ) * *************************************/ -static tilemap_t *find_cache_entry(int page, int bank) +static tilemap_t *find_cache_entry(segas32_state *state, int page, int bank) { struct cache_entry *entry, *prev; /* scan the list for a matching entry */ prev = NULL; - entry = cache_head; + entry = state->cache_head; while (1) { if (entry->page == page && entry->bank == bank) @@ -756,8 +727,8 @@ static tilemap_t *find_cache_entry(int page, int bank) if (prev) { prev->next = entry->next; - entry->next = cache_head; - cache_head = entry; + entry->next = state->cache_head; + state->cache_head = entry; } return entry->tmap; } @@ -776,8 +747,8 @@ static tilemap_t *find_cache_entry(int page, int bank) /* move it to the head */ prev->next = entry->next; - entry->next = cache_head; - cache_head = entry; + entry->next = state->cache_head; + state->cache_head = entry; return entry->tmap; } @@ -792,8 +763,9 @@ static tilemap_t *find_cache_entry(int page, int bank) static TILE_GET_INFO( get_tile_info ) { + segas32_state *state = machine->driver_data(); struct cache_entry *entry = (struct cache_entry *)param; - UINT16 data = system32_videoram[(entry->page & 0x7f) * 0x200 + tile_index]; + UINT16 data = state->system32_videoram[(entry->page & 0x7f) * 0x200 + tile_index]; SET_TILE_INFO(0, (entry->bank << 13) + (data & 0x1fff), (data >> 4) & 0x1ff, (data >> 14) & 3); } @@ -807,7 +779,8 @@ static TILE_GET_INFO( get_tile_info ) static int compute_clipping_extents(screen_device &screen, int enable, int clipout, int clipmask, const rectangle *cliprect, struct extents_list *list) { - int flip = (system32_videoram[0x1ff00/2] >> 9) & 1; + segas32_state *state = screen.machine->driver_data(); + int flip = (state->system32_videoram[0x1ff00/2] >> 9) & 1; rectangle tempclip; rectangle clips[5]; int sorted[5]; @@ -834,19 +807,19 @@ static int compute_clipping_extents(screen_device &screen, int enable, int clipo { if (!flip) { - clips[i].min_x = system32_videoram[0x1ff60/2 + i * 4] & 0x1ff; - clips[i].min_y = system32_videoram[0x1ff62/2 + i * 4] & 0x0ff; - clips[i].max_x = (system32_videoram[0x1ff64/2 + i * 4] & 0x1ff) + 1; - clips[i].max_y = (system32_videoram[0x1ff66/2 + i * 4] & 0x0ff) + 1; + clips[i].min_x = state->system32_videoram[0x1ff60/2 + i * 4] & 0x1ff; + clips[i].min_y = state->system32_videoram[0x1ff62/2 + i * 4] & 0x0ff; + clips[i].max_x = (state->system32_videoram[0x1ff64/2 + i * 4] & 0x1ff) + 1; + clips[i].max_y = (state->system32_videoram[0x1ff66/2 + i * 4] & 0x0ff) + 1; } else { const rectangle &visarea = screen.visible_area(); - clips[i].max_x = (visarea.max_x + 1) - (system32_videoram[0x1ff60/2 + i * 4] & 0x1ff); - clips[i].max_y = (visarea.max_y + 1) - (system32_videoram[0x1ff62/2 + i * 4] & 0x0ff); - clips[i].min_x = (visarea.max_x + 1) - ((system32_videoram[0x1ff64/2 + i * 4] & 0x1ff) + 1); - clips[i].min_y = (visarea.max_y + 1) - ((system32_videoram[0x1ff66/2 + i * 4] & 0x0ff) + 1); + clips[i].max_x = (visarea.max_x + 1) - (state->system32_videoram[0x1ff60/2 + i * 4] & 0x1ff); + clips[i].max_y = (visarea.max_y + 1) - (state->system32_videoram[0x1ff62/2 + i * 4] & 0x0ff); + clips[i].min_x = (visarea.max_x + 1) - ((state->system32_videoram[0x1ff64/2 + i * 4] & 0x1ff) + 1); + clips[i].min_y = (visarea.max_y + 1) - ((state->system32_videoram[0x1ff66/2 + i * 4] & 0x0ff) + 1); } sect_rect(&clips[i], &tempclip); sorted[i] = i; @@ -914,30 +887,31 @@ static int compute_clipping_extents(screen_device &screen, int enable, int clipo * *************************************/ -INLINE void get_tilemaps(int bgnum, tilemap_t **tilemaps) +INLINE void get_tilemaps(segas32_state *state, int bgnum, tilemap_t **tilemaps) { int tilebank, page; /* determine the current tilebank */ - if (is_multi32) - tilebank = (system32_tilebank_external >> (2*bgnum)) & 3; + if (state->is_multi32) + tilebank = (state->system32_tilebank_external >> (2*bgnum)) & 3; else - tilebank = ((system32_tilebank_external & 1) << 1) | ((system32_videoram[0x1ff00/2] & 0x400) >> 10); + tilebank = ((state->system32_tilebank_external & 1) << 1) | ((state->system32_videoram[0x1ff00/2] & 0x400) >> 10); /* find the cache entries */ - page = (system32_videoram[0x1ff40/2 + 2 * bgnum + 0] >> 0) & 0x7f; - tilemaps[0] = find_cache_entry(page, tilebank); - page = (system32_videoram[0x1ff40/2 + 2 * bgnum + 0] >> 8) & 0x7f; - tilemaps[1] = find_cache_entry(page, tilebank); - page = (system32_videoram[0x1ff40/2 + 2 * bgnum + 1] >> 0) & 0x7f; - tilemaps[2] = find_cache_entry(page, tilebank); - page = (system32_videoram[0x1ff40/2 + 2 * bgnum + 1] >> 8) & 0x7f; - tilemaps[3] = find_cache_entry(page, tilebank); + page = (state->system32_videoram[0x1ff40/2 + 2 * bgnum + 0] >> 0) & 0x7f; + tilemaps[0] = find_cache_entry(state, page, tilebank); + page = (state->system32_videoram[0x1ff40/2 + 2 * bgnum + 0] >> 8) & 0x7f; + tilemaps[1] = find_cache_entry(state, page, tilebank); + page = (state->system32_videoram[0x1ff40/2 + 2 * bgnum + 1] >> 0) & 0x7f; + tilemaps[2] = find_cache_entry(state, page, tilebank); + page = (state->system32_videoram[0x1ff40/2 + 2 * bgnum + 1] >> 8) & 0x7f; + tilemaps[3] = find_cache_entry(state, page, tilebank); } static void update_tilemap_zoom(screen_device &screen, struct layer_info *layer, const rectangle *cliprect, int bgnum) { + segas32_state *state = screen.machine->driver_data(); int clipenable, clipout, clips, clipdraw_start; bitmap_t *bitmap = layer->bitmap; struct extents_list clip_extents; @@ -949,27 +923,27 @@ static void update_tilemap_zoom(screen_device &screen, struct layer_info *layer, int x, y; /* get the tilemaps */ - get_tilemaps(bgnum, tilemaps); + get_tilemaps(state, bgnum, tilemaps); /* configure the layer */ opaque = 0; -//opaque = (system32_videoram[0x1ff8e/2] >> (8 + bgnum)) & 1; +//opaque = (state->system32_videoram[0x1ff8e/2] >> (8 + bgnum)) & 1; //if (input_code_pressed(screen.machine, KEYCODE_Z) && bgnum == 0) opaque = 1; //if (input_code_pressed(screen.machine, KEYCODE_X) && bgnum == 1) opaque = 1; /* determine if we're flipped */ - flip = ((system32_videoram[0x1ff00/2] >> 9) ^ (system32_videoram[0x1ff00/2] >> bgnum)) & 1; + flip = ((state->system32_videoram[0x1ff00/2] >> 9) ^ (state->system32_videoram[0x1ff00/2] >> bgnum)) & 1; /* determine the clipping */ - clipenable = (system32_videoram[0x1ff02/2] >> (11 + bgnum)) & 1; - clipout = (system32_videoram[0x1ff02/2] >> (6 + bgnum)) & 1; - clips = (system32_videoram[0x1ff06/2] >> (4 * bgnum)) & 0x0f; + clipenable = (state->system32_videoram[0x1ff02/2] >> (11 + bgnum)) & 1; + clipout = (state->system32_videoram[0x1ff02/2] >> (6 + bgnum)) & 1; + clips = (state->system32_videoram[0x1ff06/2] >> (4 * bgnum)) & 0x0f; clipdraw_start = compute_clipping_extents(screen, clipenable, clipout, clips, cliprect, &clip_extents); /* extract the X/Y step values (these are in destination space!) */ - dstxstep = system32_videoram[0x1ff50/2 + 2 * bgnum] & 0xfff; - if (system32_videoram[0x1ff00/2] & 0x4000) - dstystep = system32_videoram[0x1ff52/2 + 2 * bgnum] & 0xfff; + dstxstep = state->system32_videoram[0x1ff50/2 + 2 * bgnum] & 0xfff; + if (state->system32_videoram[0x1ff00/2] & 0x4000) + dstystep = state->system32_videoram[0x1ff52/2 + 2 * bgnum] & 0xfff; else dstystep = dstxstep; @@ -984,14 +958,14 @@ static void update_tilemap_zoom(screen_device &screen, struct layer_info *layer, srcystep = (0x200 << 20) / dstystep; /* start with the fractional scroll offsets, in source coordinates */ - srcx_start = (system32_videoram[0x1ff12/2 + 4 * bgnum] & 0x3ff) << 20; - srcx_start += (system32_videoram[0x1ff10/2 + 4 * bgnum] & 0xff00) << 4; - srcy = (system32_videoram[0x1ff16/2 + 4 * bgnum] & 0x1ff) << 20; - srcy += (system32_videoram[0x1ff14/2 + 4 * bgnum] & 0xfe00) << 4; + srcx_start = (state->system32_videoram[0x1ff12/2 + 4 * bgnum] & 0x3ff) << 20; + srcx_start += (state->system32_videoram[0x1ff10/2 + 4 * bgnum] & 0xff00) << 4; + srcy = (state->system32_videoram[0x1ff16/2 + 4 * bgnum] & 0x1ff) << 20; + srcy += (state->system32_videoram[0x1ff14/2 + 4 * bgnum] & 0xfe00) << 4; /* then account for the destination center coordinates */ - srcx_start -= ((INT16)(system32_videoram[0x1ff30/2 + 2 * bgnum] << 6) >> 6) * srcxstep; - srcy -= ((INT16)(system32_videoram[0x1ff32/2 + 2 * bgnum] << 7) >> 7) * srcystep; + srcx_start -= ((INT16)(state->system32_videoram[0x1ff30/2 + 2 * bgnum] << 6) >> 6) * srcxstep; + srcy -= ((INT16)(state->system32_videoram[0x1ff32/2 + 2 * bgnum] << 7) >> 7) * srcystep; /* finally, account for destination top,left coordinates */ srcx_start += cliprect->min_x * srcxstep; @@ -1076,8 +1050,8 @@ static void update_tilemap_zoom(screen_device &screen, struct layer_info *layer, #if 0 if (dstxstep != 0x200 || dstystep != 0x200) popmessage("Zoom=%03X,%03X Cent=%03X,%03X", dstxstep, dstystep, - system32_videoram[0x1ff30/2 + 2 * bgnum], - system32_videoram[0x1ff32/2 + 2 * bgnum]); + state->system32_videoram[0x1ff30/2 + 2 * bgnum], + state->system32_videoram[0x1ff32/2 + 2 * bgnum]); #endif } @@ -1091,6 +1065,7 @@ static void update_tilemap_zoom(screen_device &screen, struct layer_info *layer, static void update_tilemap_rowscroll(screen_device &screen, struct layer_info *layer, const rectangle *cliprect, int bgnum) { + segas32_state *state = screen.machine->driver_data(); int clipenable, clipout, clips, clipdraw_start; bitmap_t *bitmap = layer->bitmap; struct extents_list clip_extents; @@ -1103,35 +1078,35 @@ static void update_tilemap_rowscroll(screen_device &screen, struct layer_info *l int x, y; /* get the tilemaps */ - get_tilemaps(bgnum, tilemaps); + get_tilemaps(state, bgnum, tilemaps); /* configure the layer */ opaque = 0; -//opaque = (system32_videoram[0x1ff8e/2] >> (8 + bgnum)) & 1; +//opaque = (state->system32_videoram[0x1ff8e/2] >> (8 + bgnum)) & 1; //if (input_code_pressed(screen.machine, KEYCODE_C) && bgnum == 2) opaque = 1; //if (input_code_pressed(screen.machine, KEYCODE_V) && bgnum == 3) opaque = 1; /* determine if we're flipped */ - flip = ((system32_videoram[0x1ff00/2] >> 9) ^ (system32_videoram[0x1ff00/2] >> bgnum)) & 1; + flip = ((state->system32_videoram[0x1ff00/2] >> 9) ^ (state->system32_videoram[0x1ff00/2] >> bgnum)) & 1; /* determine the clipping */ - clipenable = (system32_videoram[0x1ff02/2] >> (11 + bgnum)) & 1; - clipout = (system32_videoram[0x1ff02/2] >> (6 + bgnum)) & 1; - clips = (system32_videoram[0x1ff06/2] >> (4 * bgnum)) & 0x0f; + clipenable = (state->system32_videoram[0x1ff02/2] >> (11 + bgnum)) & 1; + clipout = (state->system32_videoram[0x1ff02/2] >> (6 + bgnum)) & 1; + clips = (state->system32_videoram[0x1ff06/2] >> (4 * bgnum)) & 0x0f; clipdraw_start = compute_clipping_extents(screen, clipenable, clipout, clips, cliprect, &clip_extents); /* determine if row scroll and/or row select is enabled */ - rowscroll = (system32_videoram[0x1ff04/2] >> (bgnum - 2)) & 1; - rowselect = (system32_videoram[0x1ff04/2] >> bgnum) & 1; - if ((system32_videoram[0x1ff04/2] >> (bgnum + 2)) & 1) + rowscroll = (state->system32_videoram[0x1ff04/2] >> (bgnum - 2)) & 1; + rowselect = (state->system32_videoram[0x1ff04/2] >> bgnum) & 1; + if ((state->system32_videoram[0x1ff04/2] >> (bgnum + 2)) & 1) rowscroll = rowselect = 0; /* get a pointer to the table */ - table = &system32_videoram[(system32_videoram[0x1ff04/2] >> 10) * 0x400]; + table = &state->system32_videoram[(state->system32_videoram[0x1ff04/2] >> 10) * 0x400]; /* start with screen-wide X and Y scrolls */ - xscroll = (system32_videoram[0x1ff12/2 + 4 * bgnum] & 0x3ff) - (system32_videoram[0x1ff30/2 + 2 * bgnum] & 0x1ff); - yscroll = (system32_videoram[0x1ff16/2 + 4 * bgnum] & 0x1ff); + xscroll = (state->system32_videoram[0x1ff12/2 + 4 * bgnum] & 0x3ff) - (state->system32_videoram[0x1ff30/2 + 2 * bgnum] & 0x1ff); + yscroll = (state->system32_videoram[0x1ff16/2 + 4 * bgnum] & 0x1ff); /* render the tilemap into its bitmap */ for (y = cliprect->min_y; y <= cliprect->max_y; y++) @@ -1229,7 +1204,7 @@ static void update_tilemap_rowscroll(screen_device &screen, struct layer_info *l #if 0 if (rowscroll || rowselect) popmessage("Scroll=%d Select=%d Table@%06X", - rowscroll, rowselect, (system32_videoram[0x1ff04/2] >> 10) * 0x800); + rowscroll, rowselect, (state->system32_videoram[0x1ff04/2] >> 10) * 0x800); #endif } @@ -1243,6 +1218,7 @@ static void update_tilemap_rowscroll(screen_device &screen, struct layer_info *l static void update_tilemap_text(screen_device &screen, struct layer_info *layer, const rectangle *cliprect) { + segas32_state *state = screen.machine->driver_data(); bitmap_t *bitmap = layer->bitmap; UINT16 *tilebase; UINT16 *gfxbase; @@ -1252,11 +1228,11 @@ static void update_tilemap_text(screen_device &screen, struct layer_info *layer, int flip; /* determine if we're flipped */ - flip = (system32_videoram[0x1ff00/2] >> 9) & 1; + flip = (state->system32_videoram[0x1ff00/2] >> 9) & 1; /* determine the base of the tilemap and graphics data */ - tilebase = &system32_videoram[((system32_videoram[0x1ff5c/2] >> 4) & 0x1f) * 0x800]; - gfxbase = &system32_videoram[(system32_videoram[0x1ff5c/2] & 7) * 0x2000]; + tilebase = &state->system32_videoram[((state->system32_videoram[0x1ff5c/2] >> 4) & 0x1f) * 0x800]; + gfxbase = &state->system32_videoram[(state->system32_videoram[0x1ff5c/2] & 7) * 0x2000]; /* compute start/end tile numbers */ startx = cliprect->min_x / 8; @@ -1402,6 +1378,7 @@ static void update_tilemap_text(screen_device &screen, struct layer_info *layer, static void update_bitmap(screen_device &screen, struct layer_info *layer, const rectangle *cliprect) { + segas32_state *state = screen.machine->driver_data(); int clipenable, clipout, clips, clipdraw_start; bitmap_t *bitmap = layer->bitmap; struct extents_list clip_extents; @@ -1411,18 +1388,18 @@ static void update_bitmap(screen_device &screen, struct layer_info *layer, const int bpp; /* configure the layer */ - bpp = (system32_videoram[0x1ff00/2] & 0x0800) ? 8 : 4; + bpp = (state->system32_videoram[0x1ff00/2] & 0x0800) ? 8 : 4; /* determine the clipping */ - clipenable = (system32_videoram[0x1ff02/2] >> 15) & 1; - clipout = (system32_videoram[0x1ff02/2] >> 10) & 1; + clipenable = (state->system32_videoram[0x1ff02/2] >> 15) & 1; + clipout = (state->system32_videoram[0x1ff02/2] >> 10) & 1; clips = 0x10; clipdraw_start = compute_clipping_extents(screen, clipenable, clipout, clips, cliprect, &clip_extents); /* determine x/y scroll */ - xscroll = system32_videoram[0x1ff88/2] & 0x1ff; - yscroll = system32_videoram[0x1ff8a/2] & 0x1ff; - color = (system32_videoram[0x1ff8c/2] << 4) & 0x1fff0 & ~((1 << bpp) - 1); + xscroll = state->system32_videoram[0x1ff88/2] & 0x1ff; + yscroll = state->system32_videoram[0x1ff8a/2] & 0x1ff; + color = (state->system32_videoram[0x1ff8c/2] << 4) & 0x1fff0 & ~((1 << bpp) - 1); /* loop over target rows */ for (y = cliprect->min_y; y <= cliprect->max_y; y++) @@ -1445,7 +1422,7 @@ static void update_bitmap(screen_device &screen, struct layer_info *layer, const /* 8bpp mode case */ if (bpp == 8) { - UINT8 *src = (UINT8 *)&system32_videoram[512/2 * ((y + yscroll) & 0xff)]; + UINT8 *src = (UINT8 *)&state->system32_videoram[512/2 * ((y + yscroll) & 0xff)]; for (x = extents[0]; x < extents[1]; x++) { int effx = (x + xscroll) & 0x1ff; @@ -1459,7 +1436,7 @@ static void update_bitmap(screen_device &screen, struct layer_info *layer, const /* 4bpp mode case */ else { - UINT16 *src = &system32_videoram[512/4 * ((y + yscroll) & 0x1ff)]; + UINT16 *src = &state->system32_videoram[512/4 * ((y + yscroll) & 0x1ff)]; for (x = extents[0]; x < extents[1]; x++) { int effx = (x + xscroll) & 0x1ff; @@ -1503,7 +1480,7 @@ static void update_bitmap(screen_device &screen, struct layer_info *layer, const * *************************************/ -static void update_background(struct layer_info *layer, const rectangle *cliprect) +static void update_background(segas32_state *state, struct layer_info *layer, const rectangle *cliprect) { bitmap_t *bitmap = layer->bitmap; int x, y; @@ -1514,10 +1491,10 @@ static void update_background(struct layer_info *layer, const rectangle *cliprec int color; /* determine the color */ - if (system32_videoram[0x1ff5e/2] & 0x8000) - color = (system32_videoram[0x1ff5e/2] & 0x1fff) + y; + if (state->system32_videoram[0x1ff5e/2] & 0x8000) + color = (state->system32_videoram[0x1ff5e/2] & 0x1fff) + y; else - color = system32_videoram[0x1ff5e/2] & 0x1e00; + color = state->system32_videoram[0x1ff5e/2] & 0x1e00; /* if the color doesn't match, fill */ if (dst[cliprect->min_x] != color) @@ -1529,27 +1506,28 @@ static void update_background(struct layer_info *layer, const rectangle *cliprec static UINT8 update_tilemaps(screen_device &screen, const rectangle *cliprect) { - int enable0 = !(system32_videoram[0x1ff02/2] & 0x0001) && !(system32_videoram[0x1ff8e/2] & 0x0002); - int enable1 = !(system32_videoram[0x1ff02/2] & 0x0002) && !(system32_videoram[0x1ff8e/2] & 0x0004); - int enable2 = !(system32_videoram[0x1ff02/2] & 0x0004) && !(system32_videoram[0x1ff8e/2] & 0x0008) && !(system32_videoram[0x1ff00/2] & 0x1000); - int enable3 = !(system32_videoram[0x1ff02/2] & 0x0008) && !(system32_videoram[0x1ff8e/2] & 0x0010) && !(system32_videoram[0x1ff00/2] & 0x2000); - int enablet = !(system32_videoram[0x1ff02/2] & 0x0010) && !(system32_videoram[0x1ff8e/2] & 0x0001); - int enableb = !(system32_videoram[0x1ff02/2] & 0x0020) && !(system32_videoram[0x1ff8e/2] & 0x0020); + segas32_state *state = screen.machine->driver_data(); + int enable0 = !(state->system32_videoram[0x1ff02/2] & 0x0001) && !(state->system32_videoram[0x1ff8e/2] & 0x0002); + int enable1 = !(state->system32_videoram[0x1ff02/2] & 0x0002) && !(state->system32_videoram[0x1ff8e/2] & 0x0004); + int enable2 = !(state->system32_videoram[0x1ff02/2] & 0x0004) && !(state->system32_videoram[0x1ff8e/2] & 0x0008) && !(state->system32_videoram[0x1ff00/2] & 0x1000); + int enable3 = !(state->system32_videoram[0x1ff02/2] & 0x0008) && !(state->system32_videoram[0x1ff8e/2] & 0x0010) && !(state->system32_videoram[0x1ff00/2] & 0x2000); + int enablet = !(state->system32_videoram[0x1ff02/2] & 0x0010) && !(state->system32_videoram[0x1ff8e/2] & 0x0001); + int enableb = !(state->system32_videoram[0x1ff02/2] & 0x0020) && !(state->system32_videoram[0x1ff8e/2] & 0x0020); /* update any tilemaps */ if (enable0) - update_tilemap_zoom(screen, &layer_data[MIXER_LAYER_NBG0], cliprect, 0); + update_tilemap_zoom(screen, &state->layer_data[MIXER_LAYER_NBG0], cliprect, 0); if (enable1) - update_tilemap_zoom(screen, &layer_data[MIXER_LAYER_NBG1], cliprect, 1); + update_tilemap_zoom(screen, &state->layer_data[MIXER_LAYER_NBG1], cliprect, 1); if (enable2) - update_tilemap_rowscroll(screen, &layer_data[MIXER_LAYER_NBG2], cliprect, 2); + update_tilemap_rowscroll(screen, &state->layer_data[MIXER_LAYER_NBG2], cliprect, 2); if (enable3) - update_tilemap_rowscroll(screen, &layer_data[MIXER_LAYER_NBG3], cliprect, 3); + update_tilemap_rowscroll(screen, &state->layer_data[MIXER_LAYER_NBG3], cliprect, 3); if (enablet) - update_tilemap_text(screen, &layer_data[MIXER_LAYER_TEXT], cliprect); + update_tilemap_text(screen, &state->layer_data[MIXER_LAYER_TEXT], cliprect); if (enableb) - update_bitmap(screen, &layer_data[MIXER_LAYER_BITMAP], cliprect); - update_background(&layer_data[MIXER_LAYER_BACKGROUND], cliprect); + update_bitmap(screen, &state->layer_data[MIXER_LAYER_BITMAP], cliprect); + update_background(state, &state->layer_data[MIXER_LAYER_BACKGROUND], cliprect); return (enablet << 0) | (enable0 << 1) | (enable1 << 2) | (enable2 << 3) | (enable3 << 4) | (enableb << 5); } @@ -1562,35 +1540,35 @@ static UINT8 update_tilemaps(screen_device &screen, const rectangle *cliprect) * *************************************/ -static void sprite_erase_buffer(void) +static void sprite_erase_buffer(segas32_state *state) { /* erase the visible sprite buffer and clear the checksums */ - bitmap_fill(layer_data[MIXER_LAYER_SPRITES].bitmap, NULL, 0xffff); + bitmap_fill(state->layer_data[MIXER_LAYER_SPRITES].bitmap, NULL, 0xffff); /* for multi32, erase the other buffer as well */ - if (is_multi32) - bitmap_fill(layer_data[MIXER_LAYER_MULTISPR].bitmap, NULL, 0xffff); + if (state->is_multi32) + bitmap_fill(state->layer_data[MIXER_LAYER_MULTISPR].bitmap, NULL, 0xffff); } -static void sprite_swap_buffers(void) +static void sprite_swap_buffers(segas32_state *state) { /* swap between the two sprite buffers */ struct layer_info temp; - temp = layer_data[MIXER_LAYER_SPRITES]; - layer_data[MIXER_LAYER_SPRITES] = layer_data[MIXER_LAYER_SPRITES_2]; - layer_data[MIXER_LAYER_SPRITES_2] = temp; + temp = state->layer_data[MIXER_LAYER_SPRITES]; + state->layer_data[MIXER_LAYER_SPRITES] = state->layer_data[MIXER_LAYER_SPRITES_2]; + state->layer_data[MIXER_LAYER_SPRITES_2] = temp; /* for multi32, swap the other buffer as well */ - if (is_multi32) + if (state->is_multi32) { - temp = layer_data[MIXER_LAYER_MULTISPR]; - layer_data[MIXER_LAYER_MULTISPR] = layer_data[MIXER_LAYER_MULTISPR_2]; - layer_data[MIXER_LAYER_MULTISPR_2] = temp; + temp = state->layer_data[MIXER_LAYER_MULTISPR]; + state->layer_data[MIXER_LAYER_MULTISPR] = state->layer_data[MIXER_LAYER_MULTISPR_2]; + state->layer_data[MIXER_LAYER_MULTISPR_2] = temp; } /* latch any pending info */ - memcpy(sprite_control_latched, sprite_control, sizeof(sprite_control_latched)); + memcpy(state->sprite_control_latched, state->sprite_control, sizeof(state->sprite_control_latched)); } @@ -1693,6 +1671,7 @@ static void sprite_swap_buffers(void) static int draw_one_sprite(running_machine *machine, UINT16 *data, int xoffs, int yoffs, const rectangle *clipin, const rectangle *clipout) { + segas32_state *state = machine->driver_data(); static const int transparency_masks[4][4] = { { 0x7fff, 0x3fff, 0x1fff, 0x0fff }, @@ -1701,13 +1680,13 @@ static int draw_one_sprite(running_machine *machine, UINT16 *data, int xoffs, in { 0x1fff, 0x0fff, 0x07ff, 0x03ff } }; - bitmap_t *bitmap = layer_data[(!is_multi32 || !(data[3] & 0x0800)) ? MIXER_LAYER_SPRITES_2 : MIXER_LAYER_MULTISPR_2].bitmap; + bitmap_t *bitmap = state->layer_data[(!state->is_multi32 || !(data[3] & 0x0800)) ? MIXER_LAYER_SPRITES_2 : MIXER_LAYER_MULTISPR_2].bitmap; UINT8 numbanks = machine->region("gfx2")->bytes() / 0x400000; const UINT32 *spritebase = (const UINT32 *)machine->region("gfx2")->base(); int indirect = data[0] & 0x2000; int indlocal = data[0] & 0x1000; - int shadow = (data[0] & 0x0800) && (sprite_control_latched[0x0a/2] & 1); + int shadow = (data[0] & 0x0800) && (state->sprite_control_latched[0x0a/2] & 1); int fromram = data[0] & 0x0400; int bpp8 = data[0] & 0x0200; int transp = (data[0] & 0x0100) ? 0 : (bpp8 ? 0xff : 0x0f); @@ -1719,7 +1698,7 @@ static int draw_one_sprite(running_machine *machine, UINT16 *data, int xoffs, in int adjustx = (data[0] >> 0) & 3; int srch = (data[1] >> 8); int srcw = bpp8 ? (data[1] & 0x3f) : ((data[1] >> 1) & 0x3f); - int bank = is_multi32 ? + int bank = state->is_multi32 ? ((data[3] & 0x2000) >> 13) | ((data[3] & 0x8000) >> 14) : ((data[3] & 0x0800) >> 11) | ((data[3] & 0x4000) >> 13); int dsth = data[2] & 0x3ff; @@ -1740,22 +1719,22 @@ static int draw_one_sprite(running_machine *machine, UINT16 *data, int xoffs, in goto bail; /* determine the transparency mask for pixels */ - transmask = transparency_masks[sprite_control_latched[0x08/2] & 3][sprite_control_latched[0x0a/2] & 3]; + transmask = transparency_masks[state->sprite_control_latched[0x08/2] & 3][state->sprite_control_latched[0x0a/2] & 3]; if (bpp8) transmask &= 0xfff0; /* create the local palette for the indirect case */ if (indirect) { - UINT16 *src = indlocal ? &data[8] : &system32_spriteram[8 * (data[7] & 0x1fff)]; + UINT16 *src = indlocal ? &data[8] : &state->system32_spriteram[8 * (data[7] & 0x1fff)]; for (x = 0; x < 16; x++) - indtable[x] = (src[x] & (bpp8 ? 0xfff0 : 0xffff)) | ((sprite_control_latched[0x0a/2] & 1) ? 0x8000 : 0x0000); + indtable[x] = (src[x] & (bpp8 ? 0xfff0 : 0xffff)) | ((state->sprite_control_latched[0x0a/2] & 1) ? 0x8000 : 0x0000); } /* clamp to within the memory region size */ if (fromram) { - spritedata = spriteram_32bit; + spritedata = state->spriteram_32bit; addrmask = (0x20000 / 4) - 1; } else @@ -1894,6 +1873,7 @@ bail: static void sprite_render_list(running_machine *machine) { + segas32_state *state = machine->driver_data(); rectangle outerclip, clipin, clipout; int xoffs = 0, yoffs = 0; int numentries = 0; @@ -1906,7 +1886,7 @@ static void sprite_render_list(running_machine *machine) /* compute the outer clip */ outerclip.min_x = outerclip.min_y = 0; - outerclip.max_x = (sprite_control_latched[0x0c/2] & 1) ? 415 : 319; + outerclip.max_x = (state->sprite_control_latched[0x0c/2] & 1) ? 415 : 319; outerclip.max_y = 223; /* initialize the cliprects */ @@ -1918,7 +1898,7 @@ static void sprite_render_list(running_machine *machine) while (numentries++ < 0x20000/16) { /* top two bits are a command */ - sprite = &system32_spriteram[8 * (spritenum & 0x1fff)]; + sprite = &state->system32_spriteram[8 * (spritenum & 0x1fff)]; switch (sprite[0] >> 14) { /* command 0 = draw sprite */ @@ -1982,9 +1962,9 @@ static void sprite_render_list(running_machine *machine) * *************************************/ -INLINE UINT8 compute_color_offsets(int which, int layerbit, int layerflag) +INLINE UINT8 compute_color_offsets(segas32_state *state,int which, int layerbit, int layerflag) { - int mode = ((mixer_control[which][0x3e/2] & 0x8000) >> 14) | (layerbit & 1); + int mode = ((state->mixer_control[which][0x3e/2] & 0x8000) >> 14) | (layerbit & 1); switch (mode) { @@ -2023,17 +2003,17 @@ INLINE UINT16 compute_sprite_blend(UINT8 encoding) } } -INLINE UINT16 *get_layer_scanline(int layer, int scanline) +INLINE UINT16 *get_layer_scanline(segas32_state *state, int layer, int scanline) { - if (layer_data[layer].transparent[scanline]) - return (layer == MIXER_LAYER_SPRITES) ? solid_ffff : solid_0000; - return BITMAP_ADDR16(layer_data[layer].bitmap, scanline, 0); + if (state->layer_data[layer].transparent[scanline]) + return (layer == MIXER_LAYER_SPRITES) ? state->solid_ffff : state->solid_0000; + return BITMAP_ADDR16(state->layer_data[layer].bitmap, scanline, 0); } -static void mix_all_layers(int which, int xoffs, bitmap_t *bitmap, const rectangle *cliprect, UINT8 enablemask) +static void mix_all_layers(segas32_state *state, int which, int xoffs, bitmap_t *bitmap, const rectangle *cliprect, UINT8 enablemask) { - int blendenable = mixer_control[which][0x4e/2] & 0x0800; - int blendfactor = (mixer_control[which][0x4e/2] >> 8) & 7; + int blendenable = state->mixer_control[which][0x4e/2] & 0x0800; + int blendfactor = (state->mixer_control[which][0x4e/2] >> 8) & 7; struct mixer_layer_info { UINT16 palbase; /* palette base from control reg */ @@ -2057,23 +2037,23 @@ static void mix_all_layers(int which, int xoffs, bitmap_t *bitmap, const rectang /* if we are the second monitor on multi32, swap in the proper sprite bank */ if (which == 1) { - temp_sprite_save = layer_data[MIXER_LAYER_SPRITES]; - layer_data[MIXER_LAYER_SPRITES] = layer_data[MIXER_LAYER_MULTISPR]; + temp_sprite_save = state->layer_data[MIXER_LAYER_SPRITES]; + state->layer_data[MIXER_LAYER_SPRITES] = state->layer_data[MIXER_LAYER_MULTISPR]; } /* extract the RGB offsets */ - rgboffs[0][0] = (INT8)(mixer_control[which][0x40/2] << 2) >> 2; - rgboffs[0][1] = (INT8)(mixer_control[which][0x42/2] << 2) >> 2; - rgboffs[0][2] = (INT8)(mixer_control[which][0x44/2] << 2) >> 2; - rgboffs[1][0] = (INT8)(mixer_control[which][0x46/2] << 2) >> 2; - rgboffs[1][1] = (INT8)(mixer_control[which][0x48/2] << 2) >> 2; - rgboffs[1][2] = (INT8)(mixer_control[which][0x4a/2] << 2) >> 2; + rgboffs[0][0] = (INT8)(state->mixer_control[which][0x40/2] << 2) >> 2; + rgboffs[0][1] = (INT8)(state->mixer_control[which][0x42/2] << 2) >> 2; + rgboffs[0][2] = (INT8)(state->mixer_control[which][0x44/2] << 2) >> 2; + rgboffs[1][0] = (INT8)(state->mixer_control[which][0x46/2] << 2) >> 2; + rgboffs[1][1] = (INT8)(state->mixer_control[which][0x48/2] << 2) >> 2; + rgboffs[1][2] = (INT8)(state->mixer_control[which][0x4a/2] << 2) >> 2; rgboffs[2][0] = 0; rgboffs[2][1] = 0; rgboffs[2][2] = 0; /* determine the sprite grouping parameters first */ - switch (mixer_control[which][0x4c/2] & 0x0f) + switch (state->mixer_control[which][0x4c/2] & 0x0f) { default: case 0x0: sprgroup_shift = 14; sprgroup_mask = 0x00; sprgroup_or = 0x01; break; @@ -2096,7 +2076,7 @@ static void mix_all_layers(int which, int xoffs, bitmap_t *bitmap, const rectang case 0xe: sprgroup_shift = 11; sprgroup_mask = 0x07; sprgroup_or = 0x00; break; case 0xf: sprgroup_shift = 10; sprgroup_mask = 0x0f; sprgroup_or = 0x00; break; } - sprshadowmask = (mixer_control[which][0x4c/2] & 0x04) ? 0x8000 : 0x0000; + sprshadowmask = (state->mixer_control[which][0x4c/2] & 0x04) ? 0x8000 : 0x0000; sprpixmask = ((1 << sprgroup_shift) - 1) & 0x3fff; sprshadow = 0x7ffe & sprpixmask; @@ -2104,16 +2084,16 @@ static void mix_all_layers(int which, int xoffs, bitmap_t *bitmap, const rectang numlayers = 0; for (laynum = MIXER_LAYER_TEXT; laynum <= MIXER_LAYER_BITMAP; laynum++) { - int priority = mixer_control[which][0x20/2 + laynum] & 0x0f; + int priority = state->mixer_control[which][0x20/2 + laynum] & 0x0f; if ((enablemask & (1 << laynum)) && priority != 0) { layersort[numlayers].index = laynum; layersort[numlayers].effpri = (priority << 3) | (6 - laynum); - layersort[numlayers].palbase = (mixer_control[which][0x20/2 + laynum] & 0x00f0) << 6; - layersort[numlayers].mixshift = (mixer_control[which][0x20/2 + laynum] >> 8) & 3; - layersort[numlayers].blendmask = blendenable ? ((mixer_control[which][0x30/2 + laynum] >> 6) & 0xff) : 0; - layersort[numlayers].sprblendmask = compute_sprite_blend(mixer_control[which][0x30/2 + laynum] & 0x3f); - layersort[numlayers].coloroffs = compute_color_offsets(which, (mixer_control[which][0x3e/2] >> laynum) & 1, (mixer_control[which][0x30/2 + laynum] >> 14) & 1); + layersort[numlayers].palbase = (state->mixer_control[which][0x20/2 + laynum] & 0x00f0) << 6; + layersort[numlayers].mixshift = (state->mixer_control[which][0x20/2 + laynum] >> 8) & 3; + layersort[numlayers].blendmask = blendenable ? ((state->mixer_control[which][0x30/2 + laynum] >> 6) & 0xff) : 0; + layersort[numlayers].sprblendmask = compute_sprite_blend(state->mixer_control[which][0x30/2 + laynum] & 0x3f); + layersort[numlayers].coloroffs = compute_color_offsets(state, which, (state->mixer_control[which][0x3e/2] >> laynum) & 1, (state->mixer_control[which][0x30/2 + laynum] >> 14) & 1); numlayers++; } } @@ -2121,11 +2101,11 @@ static void mix_all_layers(int which, int xoffs, bitmap_t *bitmap, const rectang /* extract info about the BACKGROUND layer */ layersort[numlayers].index = MIXER_LAYER_BACKGROUND; layersort[numlayers].effpri = (1 << 3) | 0; - layersort[numlayers].palbase = (mixer_control[which][0x2c/2] & 0x00f0) << 6; - layersort[numlayers].mixshift = (mixer_control[which][0x2c/2] >> 8) & 3; + layersort[numlayers].palbase = (state->mixer_control[which][0x2c/2] & 0x00f0) << 6; + layersort[numlayers].mixshift = (state->mixer_control[which][0x2c/2] >> 8) & 3; layersort[numlayers].blendmask = 0; layersort[numlayers].sprblendmask = 0; - layersort[numlayers].coloroffs = compute_color_offsets(which, (mixer_control[which][0x3e/2] >> 8) & 1, (mixer_control[which][0x3e/2] >> 14) & 1); + layersort[numlayers].coloroffs = compute_color_offsets(state, which, (state->mixer_control[which][0x3e/2] >> 8) & 1, (state->mixer_control[which][0x3e/2] >> 14) & 1); numlayers++; /* now bubble sort the list by effective priority */ @@ -2142,7 +2122,7 @@ static void mix_all_layers(int which, int xoffs, bitmap_t *bitmap, const rectang for (groupnum = 0; groupnum <= sprgroup_mask; groupnum++) { int effgroup = sprgroup_or | groupnum; - int priority = mixer_control[which][0x00/2 + effgroup] & 0x0f; + int priority = state->mixer_control[which][0x00/2 + effgroup] & 0x0f; int effpri = (priority << 3) | 7; int sprindex = numlayers; int dstnum = 0; @@ -2158,14 +2138,14 @@ static void mix_all_layers(int which, int xoffs, bitmap_t *bitmap, const rectang /* build the sprite entry */ layerorder[groupnum][sprindex].index = MIXER_LAYER_SPRITES; layerorder[groupnum][sprindex].effpri = effpri; - if ((mixer_control[which][0x4c/2] & 3) != 3) - layerorder[groupnum][sprindex].palbase = (mixer_control[which][0x00/2 + effgroup] & 0x00f0) << 6; + if ((state->mixer_control[which][0x4c/2] & 3) != 3) + layerorder[groupnum][sprindex].palbase = (state->mixer_control[which][0x00/2 + effgroup] & 0x00f0) << 6; else - layerorder[groupnum][sprindex].palbase = (mixer_control[which][0x4c/2] & 0x00f0) << 6; - layerorder[groupnum][sprindex].mixshift = (mixer_control[which][0x00/2 + effgroup] >> 8) & 3; + layerorder[groupnum][sprindex].palbase = (state->mixer_control[which][0x4c/2] & 0x00f0) << 6; + layerorder[groupnum][sprindex].mixshift = (state->mixer_control[which][0x00/2 + effgroup] >> 8) & 3; layerorder[groupnum][sprindex].blendmask = 0; layerorder[groupnum][sprindex].sprblendmask = 0; - layerorder[groupnum][sprindex].coloroffs = compute_color_offsets(which, (mixer_control[which][0x3e/2] >> 6) & 1, (mixer_control[which][0x4c/2] >> 15) & 1); + layerorder[groupnum][sprindex].coloroffs = compute_color_offsets(state, which, (state->mixer_control[which][0x3e/2] >> 6) & 1, (state->mixer_control[which][0x4c/2] >> 15) & 1); } /* { @@ -2181,7 +2161,7 @@ static void mix_all_layers(int which, int xoffs, bitmap_t *bitmap, const rectang /* based on the sprite controller flip bits, the data is scanned to us in different */ /* directions; account for this */ - if (sprite_control_latched[0x04/2] & 1) + if (state->sprite_control_latched[0x04/2] & 1) { sprx_start = cliprect->max_x; sprdx = -1; @@ -2192,7 +2172,7 @@ static void mix_all_layers(int which, int xoffs, bitmap_t *bitmap, const rectang sprdx = 1; } - if (sprite_control_latched[0x04/2] & 2) + if (state->sprite_control_latched[0x04/2] & 2) { spry = cliprect->max_y; sprdy = -1; @@ -2210,14 +2190,14 @@ static void mix_all_layers(int which, int xoffs, bitmap_t *bitmap, const rectang UINT16 *layerbase[8]; /* get the starting address for each layer */ - layerbase[MIXER_LAYER_TEXT] = get_layer_scanline(MIXER_LAYER_TEXT, y); - layerbase[MIXER_LAYER_NBG0] = get_layer_scanline(MIXER_LAYER_NBG0, y); - layerbase[MIXER_LAYER_NBG1] = get_layer_scanline(MIXER_LAYER_NBG1, y); - layerbase[MIXER_LAYER_NBG2] = get_layer_scanline(MIXER_LAYER_NBG2, y); - layerbase[MIXER_LAYER_NBG3] = get_layer_scanline(MIXER_LAYER_NBG3, y); - layerbase[MIXER_LAYER_BITMAP] = get_layer_scanline(MIXER_LAYER_BITMAP, y); - layerbase[MIXER_LAYER_SPRITES] = get_layer_scanline(MIXER_LAYER_SPRITES, spry); - layerbase[MIXER_LAYER_BACKGROUND] = get_layer_scanline(MIXER_LAYER_BACKGROUND, y); + layerbase[MIXER_LAYER_TEXT] = get_layer_scanline(state, MIXER_LAYER_TEXT, y); + layerbase[MIXER_LAYER_NBG0] = get_layer_scanline(state, MIXER_LAYER_NBG0, y); + layerbase[MIXER_LAYER_NBG1] = get_layer_scanline(state, MIXER_LAYER_NBG1, y); + layerbase[MIXER_LAYER_NBG2] = get_layer_scanline(state, MIXER_LAYER_NBG2, y); + layerbase[MIXER_LAYER_NBG3] = get_layer_scanline(state, MIXER_LAYER_NBG3, y); + layerbase[MIXER_LAYER_BITMAP] = get_layer_scanline(state, MIXER_LAYER_BITMAP, y); + layerbase[MIXER_LAYER_SPRITES] = get_layer_scanline(state, MIXER_LAYER_SPRITES, spry); + layerbase[MIXER_LAYER_BACKGROUND] = get_layer_scanline(state, MIXER_LAYER_BACKGROUND, y); /* loop over columns */ for (x = cliprect->min_x, sprx = sprx_start; x <= cliprect->max_x; x++, sprx += sprdx) @@ -2262,7 +2242,7 @@ static void mix_all_layers(int which, int xoffs, bitmap_t *bitmap, const rectang } /* adjust the first pixel */ - firstpix = system32_paletteram[which][(first->palbase + ((firstpix >> first->mixshift) & 0xfff0) + (firstpix & 0x0f)) & 0x3fff]; + firstpix = state->system32_paletteram[which][(first->palbase + ((firstpix >> first->mixshift) & 0xfff0) + (firstpix & 0x0f)) & 0x3fff]; /* compute R, G, B */ rgbdelta = &rgboffs[first->coloroffs][0]; @@ -2309,7 +2289,7 @@ static void mix_all_layers(int which, int xoffs, bitmap_t *bitmap, const rectang (laynum != MIXER_LAYER_SPRITES || (first->sprblendmask & (1 << sprgroup)))) { /* adjust the second pixel */ - secondpix = system32_paletteram[which][(second->palbase + ((secondpix >> second->mixshift) & 0xfff0) + (secondpix & 0x0f)) & 0x3fff]; + secondpix = state->system32_paletteram[which][(second->palbase + ((secondpix >> second->mixshift) & 0xfff0) + (secondpix & 0x0f)) & 0x3fff]; /* compute first RGB */ r *= 7 - blendfactor; @@ -2360,7 +2340,7 @@ static void mix_all_layers(int which, int xoffs, bitmap_t *bitmap, const rectang /* if we are the second monitor on multi32, swap back the sprite layer */ if (which == 1) - layer_data[MIXER_LAYER_SPRITES] = temp_sprite_save; + state->layer_data[MIXER_LAYER_SPRITES] = temp_sprite_save; } @@ -2371,89 +2351,90 @@ static void mix_all_layers(int which, int xoffs, bitmap_t *bitmap, const rectang * *************************************/ -static void print_mixer_data(int which) +static void print_mixer_data(segas32_state *state, int which) { static int count = 0; if (++count > 60 * 5) { mame_printf_debug("\n"); - mame_printf_debug("OP: %04X\n", system32_videoram[0x1ff8e/2]); + mame_printf_debug("OP: %04X\n", state->system32_videoram[0x1ff8e/2]); mame_printf_debug("SC: %04X %04X %04X %04X - %04X %04X %04X %04X\n", - sprite_control_latched[0x00], - sprite_control_latched[0x01], - sprite_control_latched[0x02], - sprite_control_latched[0x03], - sprite_control_latched[0x04], - sprite_control_latched[0x05], - sprite_control_latched[0x06], - sprite_control_latched[0x07]); + state->sprite_control_latched[0x00], + state->sprite_control_latched[0x01], + state->sprite_control_latched[0x02], + state->sprite_control_latched[0x03], + state->sprite_control_latched[0x04], + state->sprite_control_latched[0x05], + state->sprite_control_latched[0x06], + state->sprite_control_latched[0x07]); mame_printf_debug("00: %04X %04X %04X %04X - %04X %04X %04X %04X - %04X %04X %04X %04X - %04X %04X %04X %04X\n", - mixer_control[which][0x00], - mixer_control[which][0x01], - mixer_control[which][0x02], - mixer_control[which][0x03], - mixer_control[which][0x04], - mixer_control[which][0x05], - mixer_control[which][0x06], - mixer_control[which][0x07], - mixer_control[which][0x08], - mixer_control[which][0x09], - mixer_control[which][0x0a], - mixer_control[which][0x0b], - mixer_control[which][0x0c], - mixer_control[which][0x0d], - mixer_control[which][0x0e], - mixer_control[which][0x0f]); + state->mixer_control[which][0x00], + state->mixer_control[which][0x01], + state->mixer_control[which][0x02], + state->mixer_control[which][0x03], + state->mixer_control[which][0x04], + state->mixer_control[which][0x05], + state->mixer_control[which][0x06], + state->mixer_control[which][0x07], + state->mixer_control[which][0x08], + state->mixer_control[which][0x09], + state->mixer_control[which][0x0a], + state->mixer_control[which][0x0b], + state->mixer_control[which][0x0c], + state->mixer_control[which][0x0d], + state->mixer_control[which][0x0e], + state->mixer_control[which][0x0f]); mame_printf_debug("20: %04X %04X %04X %04X - %04X %04X %04X %04X - %04X %04X %04X %04X - %04X %04X %04X %04X\n", - mixer_control[which][0x10], - mixer_control[which][0x11], - mixer_control[which][0x12], - mixer_control[which][0x13], - mixer_control[which][0x14], - mixer_control[which][0x15], - mixer_control[which][0x16], - mixer_control[which][0x17], - mixer_control[which][0x18], - mixer_control[which][0x19], - mixer_control[which][0x1a], - mixer_control[which][0x1b], - mixer_control[which][0x1c], - mixer_control[which][0x1d], - mixer_control[which][0x1e], - mixer_control[which][0x1f]); + state->mixer_control[which][0x10], + state->mixer_control[which][0x11], + state->mixer_control[which][0x12], + state->mixer_control[which][0x13], + state->mixer_control[which][0x14], + state->mixer_control[which][0x15], + state->mixer_control[which][0x16], + state->mixer_control[which][0x17], + state->mixer_control[which][0x18], + state->mixer_control[which][0x19], + state->mixer_control[which][0x1a], + state->mixer_control[which][0x1b], + state->mixer_control[which][0x1c], + state->mixer_control[which][0x1d], + state->mixer_control[which][0x1e], + state->mixer_control[which][0x1f]); mame_printf_debug("40: %04X %04X %04X %04X - %04X %04X %04X %04X - %04X %04X %04X %04X - %04X %04X %04X %04X\n", - mixer_control[which][0x20], - mixer_control[which][0x21], - mixer_control[which][0x22], - mixer_control[which][0x23], - mixer_control[which][0x24], - mixer_control[which][0x25], - mixer_control[which][0x26], - mixer_control[which][0x27], - mixer_control[which][0x28], - mixer_control[which][0x29], - mixer_control[which][0x2a], - mixer_control[which][0x2b], - mixer_control[which][0x2c], - mixer_control[which][0x2d], - mixer_control[which][0x2e], - mixer_control[which][0x2f]); + state->mixer_control[which][0x20], + state->mixer_control[which][0x21], + state->mixer_control[which][0x22], + state->mixer_control[which][0x23], + state->mixer_control[which][0x24], + state->mixer_control[which][0x25], + state->mixer_control[which][0x26], + state->mixer_control[which][0x27], + state->mixer_control[which][0x28], + state->mixer_control[which][0x29], + state->mixer_control[which][0x2a], + state->mixer_control[which][0x2b], + state->mixer_control[which][0x2c], + state->mixer_control[which][0x2d], + state->mixer_control[which][0x2e], + state->mixer_control[which][0x2f]); count = 0; } } VIDEO_UPDATE( system32 ) { + segas32_state *state = screen->machine->driver_data(); UINT8 enablemask; /* update the visible area */ - if (system32_videoram[0x1ff00/2] & 0x8000) + if (state->system32_videoram[0x1ff00/2] & 0x8000) screen->set_visible_area(0, 52*8-1, 0, 28*8-1); else screen->set_visible_area(0, 40*8-1, 0, 28*8-1); /* if the display is off, punt */ - if (!system32_displayenable[0]) + if (!state->system32_displayenable[0]) { bitmap_fill(bitmap, cliprect, get_black_pen(screen->machine)); return 0; @@ -2476,7 +2457,7 @@ VIDEO_UPDATE( system32 ) /* do the mixing */ g_profiler.start(PROFILER_USER3); - mix_all_layers(0, 0, bitmap, cliprect, enablemask); + mix_all_layers(state, 0, 0, bitmap, cliprect, enablemask); g_profiler.stop(); if (LOG_SPRITES && input_code_pressed(screen->machine, KEYCODE_L)) @@ -2487,7 +2468,7 @@ VIDEO_UPDATE( system32 ) for (y = visarea.min_y; y <= visarea.max_y; y++) { - UINT16 *src = get_layer_scanline(MIXER_LAYER_SPRITES, y); + UINT16 *src = get_layer_scanline(state, MIXER_LAYER_SPRITES, y); for (x = visarea.min_x; x <= visarea.max_x; x++) fprintf(f, "%04X ", *src++); fprintf(f, "\n"); @@ -2497,7 +2478,7 @@ VIDEO_UPDATE( system32 ) f = fopen("nbg0.txt", "w"); for (y = visarea.min_y; y <= visarea.max_y; y++) { - UINT16 *src = get_layer_scanline(MIXER_LAYER_NBG0, y); + UINT16 *src = get_layer_scanline(state, MIXER_LAYER_NBG0, y); for (x = visarea.min_x; x <= visarea.max_x; x++) fprintf(f, "%04X ", *src++); fprintf(f, "\n"); @@ -2507,7 +2488,7 @@ VIDEO_UPDATE( system32 ) f = fopen("nbg1.txt", "w"); for (y = visarea.min_y; y <= visarea.max_y; y++) { - UINT16 *src = get_layer_scanline(MIXER_LAYER_NBG1, y); + UINT16 *src = get_layer_scanline(state, MIXER_LAYER_NBG1, y); for (x = visarea.min_x; x <= visarea.max_x; x++) fprintf(f, "%04X ", *src++); fprintf(f, "\n"); @@ -2517,7 +2498,7 @@ VIDEO_UPDATE( system32 ) f = fopen("nbg2.txt", "w"); for (y = visarea.min_y; y <= visarea.max_y; y++) { - UINT16 *src = get_layer_scanline(MIXER_LAYER_NBG2, y); + UINT16 *src = get_layer_scanline(state, MIXER_LAYER_NBG2, y); for (x = visarea.min_x; x <= visarea.max_x; x++) fprintf(f, "%04X ", *src++); fprintf(f, "\n"); @@ -2527,7 +2508,7 @@ VIDEO_UPDATE( system32 ) f = fopen("nbg3.txt", "w"); for (y = visarea.min_y; y <= visarea.max_y; y++) { - UINT16 *src = get_layer_scanline(MIXER_LAYER_NBG3, y); + UINT16 *src = get_layer_scanline(state, MIXER_LAYER_NBG3, y); for (x = visarea.min_x; x <= visarea.max_x; x++) fprintf(f, "%04X ", *src++); fprintf(f, "\n"); @@ -2540,10 +2521,10 @@ VIDEO_UPDATE( system32 ) static const char *const layername[] = { "TEXT ", "NBG0 ", "NBG1 ", "NBG2 ", "NBG3 ", "BITMAP " }; char temp[100]; int count = 0, i; - sprintf(temp, "ALPHA(%d):", (mixer_control[which][0x4e/2] >> 8) & 7); + sprintf(temp, "ALPHA(%d):", (state->mixer_control[which][0x4e/2] >> 8) & 7); for (i = 0; i < 6; i++) if (enablemask & (1 << i)) - if ((mixer_control[which][0x30/2 + i] & 0x1010) == 0x1010) + if ((state->mixer_control[which][0x30/2 + i] & 0x1010) == 0x1010) { count++; strcat(temp, layername[i]); @@ -2568,9 +2549,9 @@ VIDEO_UPDATE( system32 ) // if (showclip != -1) for (showclip = 0; showclip < 4; showclip++) { - int flip = (system32_videoram[0x1ff00/2] >> 9) & 1; - int clips = (system32_videoram[0x1ff06/2] >> (4 * showclip)) & 0x0f; - if (((system32_videoram[0x1ff02/2] >> (11 + showclip)) & 1) && clips) + int flip = (state->system32_videoram[0x1ff00/2] >> 9) & 1; + int clips = (state->system32_videoram[0x1ff06/2] >> (4 * showclip)) & 0x0f; + if (((state->system32_videoram[0x1ff02/2] >> (11 + showclip)) & 1) && clips) { int i, x, y; for (i = 0; i < 4; i++) @@ -2582,17 +2563,17 @@ for (showclip = 0; showclip < 4; showclip++) pen_t white = get_white_pen(screen->machine); if (!flip) { - rect.min_x = system32_videoram[0x1ff60/2 + i * 4] & 0x1ff; - rect.min_y = system32_videoram[0x1ff62/2 + i * 4] & 0x0ff; - rect.max_x = (system32_videoram[0x1ff64/2 + i * 4] & 0x1ff) + 1; - rect.max_y = (system32_videoram[0x1ff66/2 + i * 4] & 0x0ff) + 1; + rect.min_x = state->system32_videoram[0x1ff60/2 + i * 4] & 0x1ff; + rect.min_y = state->system32_videoram[0x1ff62/2 + i * 4] & 0x0ff; + rect.max_x = (state->system32_videoram[0x1ff64/2 + i * 4] & 0x1ff) + 1; + rect.max_y = (state->system32_videoram[0x1ff66/2 + i * 4] & 0x0ff) + 1; } else { - rect.max_x = (visarea.max_x + 1) - (system32_videoram[0x1ff60/2 + i * 4] & 0x1ff); - rect.max_y = (visarea.max_y + 1) - (system32_videoram[0x1ff62/2 + i * 4] & 0x0ff); - rect.min_x = (visarea.max_x + 1) - ((system32_videoram[0x1ff64/2 + i * 4] & 0x1ff) + 1); - rect.min_y = (visarea.max_y + 1) - ((system32_videoram[0x1ff66/2 + i * 4] & 0x0ff) + 1); + rect.max_x = (visarea.max_x + 1) - (state->system32_videoram[0x1ff60/2 + i * 4] & 0x1ff); + rect.max_y = (visarea.max_y + 1) - (state->system32_videoram[0x1ff62/2 + i * 4] & 0x0ff); + rect.min_x = (visarea.max_x + 1) - ((state->system32_videoram[0x1ff64/2 + i * 4] & 0x1ff) + 1); + rect.min_y = (visarea.max_y + 1) - ((state->system32_videoram[0x1ff66/2 + i * 4] & 0x0ff) + 1); } sect_rect(&rect, &screen->visible_area()); @@ -2615,25 +2596,26 @@ for (showclip = 0; showclip < 4; showclip++) } #endif - if (PRINTF_MIXER_DATA) print_mixer_data(0); + if (PRINTF_MIXER_DATA) print_mixer_data(state, 0); return 0; } VIDEO_UPDATE( multi32 ) { + segas32_state *state = screen->machine->driver_data(); UINT8 enablemask; device_t *left_screen = screen->machine->device("lscreen"); /* update the visible area */ - if (system32_videoram[0x1ff00/2] & 0x8000) + if (state->system32_videoram[0x1ff00/2] & 0x8000) screen->set_visible_area(0, 52*8-1, 0, 28*8-1); else screen->set_visible_area(0, 40*8-1, 0, 28*8-1); /* if the display is off, punt */ - if (!system32_displayenable[(screen == left_screen) ? 0 : 1]) + if (!state->system32_displayenable[(screen == left_screen) ? 0 : 1]) { bitmap_fill(bitmap, cliprect, get_black_pen(screen->machine)); return 0; @@ -2656,13 +2638,13 @@ VIDEO_UPDATE( multi32 ) /* do the mixing */ g_profiler.start(PROFILER_USER3); - mix_all_layers(((screen == left_screen) ? 0 : 1), 0, bitmap, cliprect, enablemask); + mix_all_layers(state, ((screen == left_screen) ? 0 : 1), 0, bitmap, cliprect, enablemask); g_profiler.stop(); if (PRINTF_MIXER_DATA) { - if (!input_code_pressed(screen->machine, KEYCODE_M)) print_mixer_data(0); - else print_mixer_data(1); + if (!input_code_pressed(screen->machine, KEYCODE_M)) print_mixer_data(state, 0); + else print_mixer_data(state, 1); } if (LOG_SPRITES && input_code_pressed(screen->machine, KEYCODE_L)) { @@ -2672,7 +2654,7 @@ if (PRINTF_MIXER_DATA) for (y = visarea.min_y; y <= visarea.max_y; y++) { - UINT16 *src = get_layer_scanline(MIXER_LAYER_SPRITES, y); + UINT16 *src = get_layer_scanline(state, MIXER_LAYER_SPRITES, y); for (x = visarea.min_x; x <= visarea.max_x; x++) fprintf(f, "%04X ", *src++); fprintf(f, "\n"); diff --git a/src/mame/video/suprloco.c b/src/mame/video/suprloco.c index eec930440c7..9a765c35513 100644 --- a/src/mame/video/suprloco.c +++ b/src/mame/video/suprloco.c @@ -9,11 +9,7 @@ #include "emu.h" #include "includes/suprloco.h" -UINT8 *suprloco_videoram; -UINT8 *suprloco_scrollram; -static tilemap_t *bg_tilemap; -static int control; #define SPR_Y_TOP 0 #define SPR_Y_BOTTOM 1 @@ -80,10 +76,11 @@ PALETTE_INIT( suprloco ) static TILE_GET_INFO( get_tile_info ) { - UINT8 attr = suprloco_videoram[2*tile_index+1]; + suprloco_state *state = machine->driver_data(); + UINT8 attr = state->videoram[2*tile_index+1]; SET_TILE_INFO( 0, - suprloco_videoram[2*tile_index] | ((attr & 0x03) << 8), + state->videoram[2*tile_index] | ((attr & 0x03) << 8), (attr & 0x1c) >> 2, 0); tileinfo->category = (attr & 0x20) >> 5; @@ -99,9 +96,10 @@ static TILE_GET_INFO( get_tile_info ) VIDEO_START( suprloco ) { - bg_tilemap = tilemap_create(machine, get_tile_info,tilemap_scan_rows,8,8,32,32); + suprloco_state *state = machine->driver_data(); + state->bg_tilemap = tilemap_create(machine, get_tile_info,tilemap_scan_rows,8,8,32,32); - tilemap_set_scroll_rows(bg_tilemap,32); + tilemap_set_scroll_rows(state->bg_tilemap,32); } @@ -114,20 +112,23 @@ VIDEO_START( suprloco ) WRITE8_HANDLER( suprloco_videoram_w ) { - suprloco_videoram[offset] = data; - tilemap_mark_tile_dirty(bg_tilemap,offset/2); + suprloco_state *state = space->machine->driver_data(); + state->videoram[offset] = data; + tilemap_mark_tile_dirty(state->bg_tilemap,offset/2); } WRITE8_HANDLER( suprloco_scrollram_w ) { + suprloco_state *state = space->machine->driver_data(); int adj = flip_screen_get(space->machine) ? -8 : 8; - suprloco_scrollram[offset] = data; - tilemap_set_scrollx(bg_tilemap,offset, data - adj); + state->scrollram[offset] = data; + tilemap_set_scrollx(state->bg_tilemap,offset, data - adj); } WRITE8_HANDLER( suprloco_control_w ) { + suprloco_state *state = space->machine->driver_data(); /* There is probably a palette select in here */ /* Bit 0 - coin counter A */ @@ -138,7 +139,7 @@ WRITE8_HANDLER( suprloco_control_w ) /* Bit 6 - probably unused */ /* Bit 7 - flip screen */ - if ((control & 0x10) != (data & 0x10)) + if ((state->control & 0x10) != (data & 0x10)) { /*logerror("Bit 4 = %d\n", (data >> 4) & 1); */ } @@ -148,13 +149,14 @@ WRITE8_HANDLER( suprloco_control_w ) flip_screen_set(space->machine, data & 0x80); - control = data; + state->control = data; } READ8_HANDLER( suprloco_control_r ) { - return control; + suprloco_state *state = space->machine->driver_data(); + return state->control; } @@ -179,6 +181,7 @@ INLINE void draw_pixel(bitmap_t *bitmap,const rectangle *cliprect,int x,int y,in static void draw_sprite(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int spr_number) { + suprloco_state *state = machine->driver_data(); int flip = flip_screen_get(machine); int sx,sy,col,row,height,src,adjy,dy; UINT8 *spr_reg; @@ -193,7 +196,7 @@ static void draw_sprite(running_machine *machine, bitmap_t *bitmap,const rectang skip = spr_reg[SPR_SKIP_LO] + (spr_reg[SPR_SKIP_HI] << 8); height = spr_reg[SPR_Y_BOTTOM] - spr_reg[SPR_Y_TOP]; - pen_base = 0x100 + 0x10 * (spr_reg[SPR_COL]&0x03) + ((control & 0x20)?0x100:0); + pen_base = 0x100 + 0x10 * (spr_reg[SPR_COL]&0x03) + ((state->control & 0x20)?0x100:0); sx = spr_reg[SPR_X]; sy = spr_reg[SPR_Y_TOP] + 1; @@ -267,8 +270,9 @@ static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const recta VIDEO_UPDATE( suprloco ) { - tilemap_draw(bitmap,cliprect,bg_tilemap,0,0); + suprloco_state *state = screen->machine->driver_data(); + tilemap_draw(bitmap,cliprect,state->bg_tilemap,0,0); draw_sprites(screen->machine,bitmap,cliprect); - tilemap_draw(bitmap,cliprect,bg_tilemap,1,0); + tilemap_draw(bitmap,cliprect,state->bg_tilemap,1,0); return 0; } diff --git a/src/mame/video/system1.c b/src/mame/video/system1.c index 086cbd1a391..3cf49f6008c 100644 --- a/src/mame/video/system1.c +++ b/src/mame/video/system1.c @@ -81,21 +81,6 @@ #include "emu.h" #include "includes/system1.h" -static UINT8 *mix_collide; -static UINT8 mix_collide_summary; -static UINT8 *sprite_collide; -static UINT8 sprite_collide_summary; - -static bitmap_t *sprite_bitmap; - -static UINT8 system1_video_mode; - -static UINT8 videoram_bank; - -static tilemap_t *tilemap_page[8]; -static UINT8 tilemap_pages; - - /************************************* * @@ -127,31 +112,31 @@ static void video_start_common(running_machine *machine, int pagecount) int pagenum; /* allocate memory for the collision arrays */ - mix_collide = auto_alloc_array_clear(machine, UINT8, 64); - sprite_collide = auto_alloc_array_clear(machine, UINT8, 1024); + state->mix_collide = auto_alloc_array_clear(machine, UINT8, 64); + state->sprite_collide = auto_alloc_array_clear(machine, UINT8, 1024); /* allocate memory for videoram */ - tilemap_pages = pagecount; + state->tilemap_pages = pagecount; state->videoram = auto_alloc_array_clear(machine, UINT8, 0x800 * pagecount); /* create the tilemap pages */ for (pagenum = 0; pagenum < pagecount; pagenum++) { - tilemap_page[pagenum] = tilemap_create(machine, tile_get_info, tilemap_scan_rows, 8,8, 32,32); - tilemap_set_transparent_pen(tilemap_page[pagenum], 0); - tilemap_set_user_data(tilemap_page[pagenum], state->videoram + 0x800 * pagenum); + state->tilemap_page[pagenum] = tilemap_create(machine, tile_get_info, tilemap_scan_rows, 8,8, 32,32); + tilemap_set_transparent_pen(state->tilemap_page[pagenum], 0); + tilemap_set_user_data(state->tilemap_page[pagenum], state->videoram + 0x800 * pagenum); } /* allocate a temporary bitmap for sprite rendering */ - sprite_bitmap = auto_bitmap_alloc(machine, 256, 256, BITMAP_FORMAT_INDEXED16); + state->sprite_bitmap = auto_bitmap_alloc(machine, 256, 256, BITMAP_FORMAT_INDEXED16); /* register for save stats */ - state_save_register_global(machine, system1_video_mode); - state_save_register_global(machine, mix_collide_summary); - state_save_register_global(machine, sprite_collide_summary); + state_save_register_global(machine, state->video_mode); + state_save_register_global(machine, state->mix_collide_summary); + state_save_register_global(machine, state->sprite_collide_summary); state->save_pointer(NAME(state->videoram), 0x800 * pagecount); - state_save_register_global_pointer(machine, mix_collide, 64); - state_save_register_global_pointer(machine, sprite_collide, 1024); + state_save_register_global_pointer(machine, state->mix_collide, 64); + state_save_register_global_pointer(machine, state->sprite_collide, 1024); } @@ -176,10 +161,11 @@ VIDEO_START( system2 ) WRITE8_HANDLER( system1_videomode_w ) { + system1_state *state = space->machine->driver_data(); if (data & 0x6e) logerror("videomode = %02x\n",data); /* bit 4 is screen blank */ - system1_video_mode = data; + state->video_mode = data; /* bit 7 is flip screen */ flip_screen_set(space->machine, data & 0x80); @@ -195,20 +181,23 @@ if (data & 0x6e) logerror("videomode = %02x\n",data); READ8_HANDLER( system1_mixer_collision_r ) { + system1_state *state = space->machine->driver_data(); space->machine->primary_screen->update_now(); - return mix_collide[offset & 0x3f] | 0x7e | (mix_collide_summary << 7); + return state->mix_collide[offset & 0x3f] | 0x7e | (state->mix_collide_summary << 7); } WRITE8_HANDLER( system1_mixer_collision_w ) { + system1_state *state = space->machine->driver_data(); space->machine->primary_screen->update_now(); - mix_collide[offset & 0x3f] = 0; + state->mix_collide[offset & 0x3f] = 0; } WRITE8_HANDLER( system1_mixer_collision_reset_w ) { + system1_state *state = space->machine->driver_data(); space->machine->primary_screen->update_now(); - mix_collide_summary = 0; + state->mix_collide_summary = 0; } @@ -221,20 +210,23 @@ WRITE8_HANDLER( system1_mixer_collision_reset_w ) READ8_HANDLER( system1_sprite_collision_r ) { + system1_state *state = space->machine->driver_data(); space->machine->primary_screen->update_now(); - return sprite_collide[offset & 0x3ff] | 0x7e | (sprite_collide_summary << 7); + return state->sprite_collide[offset & 0x3ff] | 0x7e | (state->sprite_collide_summary << 7); } WRITE8_HANDLER( system1_sprite_collision_w ) { + system1_state *state = space->machine->driver_data(); space->machine->primary_screen->update_now(); - sprite_collide[offset & 0x3ff] = 0; + state->sprite_collide[offset & 0x3ff] = 0; } WRITE8_HANDLER( system1_sprite_collision_reset_w ) { + system1_state *state = space->machine->driver_data(); space->machine->primary_screen->update_now(); - sprite_collide_summary = 0; + state->sprite_collide_summary = 0; } @@ -265,7 +257,7 @@ READ8_HANDLER( system1_videoram_r ) system1_state *state = space->machine->driver_data(); UINT8 *videoram = state->videoram; videoram_wait_states(space->machine->firstcpu); - offset |= 0x1000 * ((videoram_bank >> 1) % (tilemap_pages / 2)); + offset |= 0x1000 * ((state->videoram_bank >> 1) % (state->tilemap_pages / 2)); return videoram[offset]; } @@ -274,19 +266,20 @@ WRITE8_HANDLER( system1_videoram_w ) system1_state *state = space->machine->driver_data(); UINT8 *videoram = state->videoram; videoram_wait_states(space->machine->firstcpu); - offset |= 0x1000 * ((videoram_bank >> 1) % (tilemap_pages / 2)); + offset |= 0x1000 * ((state->videoram_bank >> 1) % (state->tilemap_pages / 2)); videoram[offset] = data; - tilemap_mark_tile_dirty(tilemap_page[offset / 0x800], (offset % 0x800) / 2); + tilemap_mark_tile_dirty(state->tilemap_page[offset / 0x800], (offset % 0x800) / 2); /* force a partial update if the page is changing */ - if (tilemap_pages > 2 && offset >= 0x740 && offset < 0x748 && offset % 2 == 0) + if (state->tilemap_pages > 2 && offset >= 0x740 && offset < 0x748 && offset % 2 == 0) space->machine->primary_screen->update_now(); } WRITE8_DEVICE_HANDLER( system1_videoram_bank_w ) { - videoram_bank = data; + system1_state *state = device->machine->driver_data(); + state->videoram_bank = data; } @@ -370,6 +363,7 @@ WRITE8_HANDLER( system1_paletteram_w ) static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int xoffset) { + system1_state *state = machine->driver_data(); UINT32 gfxbanks = machine->region("sprites")->bytes() / 0x8000; const UINT8 *gfxbase = machine->region("sprites")->base(); UINT8 *spriteram = machine->generic.spriteram.u8; @@ -456,7 +450,7 @@ static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const recta int prevpix = destbase[effx]; if ((prevpix & 0x0f) != 0) - sprite_collide[((prevpix >> 4) & 0x1f) + 32 * spritenum] = sprite_collide_summary = 1; + state->sprite_collide[((prevpix >> 4) & 0x1f) + 32 * spritenum] = state->sprite_collide_summary = 1; destbase[effx] = color1 | palettebase; } } @@ -474,7 +468,7 @@ static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const recta int prevpix = destbase[effx]; if ((prevpix & 0x0f) != 0) - sprite_collide[((prevpix >> 4) & 0x1f) + 32 * spritenum] = sprite_collide_summary = 1; + state->sprite_collide[((prevpix >> 4) & 0x1f) + 32 * spritenum] = state->sprite_collide_summary = 1; destbase[effx] = color2 | palettebase; } } @@ -493,18 +487,19 @@ static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const recta static void video_update_common(device_t *screen, bitmap_t *bitmap, const rectangle *cliprect, bitmap_t *fgpixmap, bitmap_t **bgpixmaps, const int *bgrowscroll, int bgyscroll, int spritexoffs) { + system1_state *state = screen->machine->driver_data(); const UINT8 *lookup = screen->machine->region("proms")->base(); int x, y; /* first clear the sprite bitmap and draw sprites within this area */ - bitmap_fill(sprite_bitmap, cliprect, 0); - draw_sprites(screen->machine, sprite_bitmap, cliprect, spritexoffs); + bitmap_fill(state->sprite_bitmap, cliprect, 0); + draw_sprites(screen->machine, state->sprite_bitmap, cliprect, spritexoffs); /* iterate over rows */ for (y = cliprect->min_y; y <= cliprect->max_y; y++) { UINT16 *fgbase = BITMAP_ADDR16(fgpixmap, y & 0xff, 0); - UINT16 *sprbase = BITMAP_ADDR16(sprite_bitmap, y & 0xff, 0); + UINT16 *sprbase = BITMAP_ADDR16(state->sprite_bitmap, y & 0xff, 0); UINT16 *dstbase = BITMAP_ADDR16(bitmap, y, 0); int bgy = (y + bgyscroll) & 0x1ff; int bgxscroll = bgrowscroll[y / 8]; @@ -534,11 +529,11 @@ static void video_update_common(device_t *screen, bitmap_t *bitmap, const rectan /* compute collisions based on two of the PROM bits */ if (!(lookup_value & 4)) - mix_collide[((lookup_value & 8) << 2) | ((sprpix >> 4) & 0x1f)] = mix_collide_summary = 1; + state->mix_collide[((lookup_value & 8) << 2) | ((sprpix >> 4) & 0x1f)] = state->mix_collide_summary = 1; /* the lower 2 PROM bits select the palette and which pixels */ lookup_value &= 3; - if (system1_video_mode & 0x10) + if (state->video_mode & 0x10) dstbase[x] = 0; else if (lookup_value == 0) dstbase[x] = 0x000 | (sprpix & 0x1ff); @@ -568,10 +563,10 @@ VIDEO_UPDATE( system1 ) int y; /* all 4 background pages are the same, fixed to page 0 */ - bgpixmaps[0] = bgpixmaps[1] = bgpixmaps[2] = bgpixmaps[3] = tilemap_get_pixmap(tilemap_page[0]); + bgpixmaps[0] = bgpixmaps[1] = bgpixmaps[2] = bgpixmaps[3] = tilemap_get_pixmap(state->tilemap_page[0]); /* foreground is fixed to page 1 */ - fgpixmap = tilemap_get_pixmap(tilemap_page[1]); + fgpixmap = tilemap_get_pixmap(state->tilemap_page[1]); /* get fixed scroll offsets */ xscroll = (videoram[0xffc] | (videoram[0xffd] << 8)) / 2 + 14; @@ -605,13 +600,13 @@ VIDEO_UPDATE( system2 ) int y; /* 4 independent background pages */ - bgpixmaps[0] = tilemap_get_pixmap(tilemap_page[videoram[0x740] & 7]); - bgpixmaps[1] = tilemap_get_pixmap(tilemap_page[videoram[0x742] & 7]); - bgpixmaps[2] = tilemap_get_pixmap(tilemap_page[videoram[0x744] & 7]); - bgpixmaps[3] = tilemap_get_pixmap(tilemap_page[videoram[0x746] & 7]); + bgpixmaps[0] = tilemap_get_pixmap(state->tilemap_page[videoram[0x740] & 7]); + bgpixmaps[1] = tilemap_get_pixmap(state->tilemap_page[videoram[0x742] & 7]); + bgpixmaps[2] = tilemap_get_pixmap(state->tilemap_page[videoram[0x744] & 7]); + bgpixmaps[3] = tilemap_get_pixmap(state->tilemap_page[videoram[0x746] & 7]); /* foreground is fixed to page 0 */ - fgpixmap = tilemap_get_pixmap(tilemap_page[0]); + fgpixmap = tilemap_get_pixmap(state->tilemap_page[0]); /* get scroll offsets */ if (!flip_screen_get(screen->machine)) @@ -647,13 +642,13 @@ VIDEO_UPDATE( system2_rowscroll ) int y; /* 4 independent background pages */ - bgpixmaps[0] = tilemap_get_pixmap(tilemap_page[videoram[0x740] & 7]); - bgpixmaps[1] = tilemap_get_pixmap(tilemap_page[videoram[0x742] & 7]); - bgpixmaps[2] = tilemap_get_pixmap(tilemap_page[videoram[0x744] & 7]); - bgpixmaps[3] = tilemap_get_pixmap(tilemap_page[videoram[0x746] & 7]); + bgpixmaps[0] = tilemap_get_pixmap(state->tilemap_page[videoram[0x740] & 7]); + bgpixmaps[1] = tilemap_get_pixmap(state->tilemap_page[videoram[0x742] & 7]); + bgpixmaps[2] = tilemap_get_pixmap(state->tilemap_page[videoram[0x744] & 7]); + bgpixmaps[3] = tilemap_get_pixmap(state->tilemap_page[videoram[0x746] & 7]); /* foreground is fixed to page 0 */ - fgpixmap = tilemap_get_pixmap(tilemap_page[0]); + fgpixmap = tilemap_get_pixmap(state->tilemap_page[0]); /* get scroll offsets */ if (!flip_screen_get(screen->machine)) diff --git a/src/mame/video/tp84.c b/src/mame/video/tp84.c index d96bab29f1a..06c17c1ae97 100644 --- a/src/mame/video/tp84.c +++ b/src/mame/video/tp84.c @@ -11,18 +11,7 @@ #include "includes/tp84.h" -UINT8 *tp84_bg_videoram; -UINT8 *tp84_bg_colorram; -UINT8 *tp84_fg_videoram; -UINT8 *tp84_fg_colorram; -UINT8 *tp84_spriteram; -UINT8 *tp84_scroll_x; -UINT8 *tp84_scroll_y; -UINT8 *tp84_palette_bank; -UINT8 *tp84_flipscreen_x; -UINT8 *tp84_flipscreen_y; -static tilemap_t *bg_tilemap, *fg_tilemap; /* @@ -116,9 +105,10 @@ PALETTE_INIT( tp84 ) WRITE8_HANDLER( tp84_spriteram_w ) { + tp84_state *state = space->machine->driver_data(); /* the game multiplexes the sprites, so update now */ space->machine->primary_screen->update_now(); - tp84_spriteram[offset] = data; + state->spriteram[offset] = data; } @@ -131,22 +121,24 @@ READ8_HANDLER( tp84_scanline_r ) static TILE_GET_INFO( get_bg_tile_info ) { - int code = ((tp84_bg_colorram[tile_index] & 0x30) << 4) | tp84_bg_videoram[tile_index]; - int color = ((*tp84_palette_bank & 0x07) << 6) | - ((*tp84_palette_bank & 0x18) << 1) | - (tp84_bg_colorram[tile_index] & 0x0f); - int flags = TILE_FLIPYX(tp84_bg_colorram[tile_index] >> 6); + tp84_state *state = machine->driver_data(); + int code = ((state->bg_colorram[tile_index] & 0x30) << 4) | state->bg_videoram[tile_index]; + int color = ((*state->palette_bank & 0x07) << 6) | + ((*state->palette_bank & 0x18) << 1) | + (state->bg_colorram[tile_index] & 0x0f); + int flags = TILE_FLIPYX(state->bg_colorram[tile_index] >> 6); SET_TILE_INFO(0, code, color, flags); } static TILE_GET_INFO( get_fg_tile_info ) { - int code = ((tp84_fg_colorram[tile_index] & 0x30) << 4) | tp84_fg_videoram[tile_index]; - int color = ((*tp84_palette_bank & 0x07) << 6) | - ((*tp84_palette_bank & 0x18) << 1) | - (tp84_fg_colorram[tile_index] & 0x0f); - int flags = TILE_FLIPYX(tp84_fg_colorram[tile_index] >> 6); + tp84_state *state = machine->driver_data(); + int code = ((state->fg_colorram[tile_index] & 0x30) << 4) | state->fg_videoram[tile_index]; + int color = ((*state->palette_bank & 0x07) << 6) | + ((*state->palette_bank & 0x18) << 1) | + (state->fg_colorram[tile_index] & 0x0f); + int flags = TILE_FLIPYX(state->fg_colorram[tile_index] >> 6); SET_TILE_INFO(0, code, color, flags); } @@ -154,25 +146,27 @@ static TILE_GET_INFO( get_fg_tile_info ) VIDEO_START( tp84 ) { - bg_tilemap = tilemap_create(machine, get_bg_tile_info, tilemap_scan_rows, 8, 8, 32, 32); - fg_tilemap = tilemap_create(machine, get_fg_tile_info, tilemap_scan_rows, 8, 8, 32, 32); + tp84_state *state = machine->driver_data(); + state->bg_tilemap = tilemap_create(machine, get_bg_tile_info, tilemap_scan_rows, 8, 8, 32, 32); + state->fg_tilemap = tilemap_create(machine, get_fg_tile_info, tilemap_scan_rows, 8, 8, 32, 32); } static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect) { + tp84_state *state = machine->driver_data(); int offs; - int palette_base = ((*tp84_palette_bank & 0x07) << 4); + int palette_base = ((*state->palette_bank & 0x07) << 4); for (offs = 0x5c; offs >= 0; offs -= 4) { - int x = tp84_spriteram[offs]; - int y = 240 - tp84_spriteram[offs + 3]; + int x = state->spriteram[offs]; + int y = 240 - state->spriteram[offs + 3]; - int code = tp84_spriteram[offs + 1]; - int color = palette_base | (tp84_spriteram[offs + 2] & 0x0f); - int flip_x = ~tp84_spriteram[offs + 2] & 0x40; - int flip_y = tp84_spriteram[offs + 2] & 0x80; + int code = state->spriteram[offs + 1]; + int color = palette_base | (state->spriteram[offs + 2] & 0x0f); + int flip_x = ~state->spriteram[offs + 2] & 0x40; + int flip_y = state->spriteram[offs + 2] & 0x80; drawgfx_transmask(bitmap, cliprect, machine->gfx[1], code, color, flip_x, flip_y, x, y, colortable_get_transpen_mask(machine->colortable, machine->gfx[1], color, palette_base)); @@ -183,6 +177,7 @@ static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const recta VIDEO_UPDATE( tp84 ) { + tp84_state *state = screen->machine->driver_data(); rectangle clip = *cliprect; const rectangle &visarea = screen->visible_area(); @@ -190,25 +185,25 @@ VIDEO_UPDATE( tp84 ) { tilemap_mark_all_tiles_dirty_all(screen->machine); - tilemap_set_scrollx(bg_tilemap, 0, *tp84_scroll_x); - tilemap_set_scrolly(bg_tilemap, 0, *tp84_scroll_y); + tilemap_set_scrollx(state->bg_tilemap, 0, *state->scroll_x); + tilemap_set_scrolly(state->bg_tilemap, 0, *state->scroll_y); - tilemap_set_flip_all(screen->machine, ((*tp84_flipscreen_x & 0x01) ? TILEMAP_FLIPX : 0) | - ((*tp84_flipscreen_y & 0x01) ? TILEMAP_FLIPY : 0)); + tilemap_set_flip_all(screen->machine, ((*state->flipscreen_x & 0x01) ? TILEMAP_FLIPX : 0) | + ((*state->flipscreen_y & 0x01) ? TILEMAP_FLIPY : 0)); } - tilemap_draw(bitmap, cliprect, bg_tilemap, 0, 0); + tilemap_draw(bitmap, cliprect, state->bg_tilemap, 0, 0); draw_sprites(screen->machine, bitmap, cliprect); /* draw top status region */ clip.min_x = visarea.min_x; clip.max_x = visarea.min_x + 15; - tilemap_draw(bitmap, &clip, fg_tilemap, 0, 0); + tilemap_draw(bitmap, &clip, state->fg_tilemap, 0, 0); /* draw bottom status region */ clip.min_x = visarea.max_x - 15; clip.max_x = visarea.max_x; - tilemap_draw(bitmap, &clip, fg_tilemap, 0, 0); + tilemap_draw(bitmap, &clip, state->fg_tilemap, 0, 0); return 0; } diff --git a/src/mame/video/twin16.c b/src/mame/video/twin16.c index ffa4d97ab74..3e669b630b5 100644 --- a/src/mame/video/twin16.c +++ b/src/mame/video/twin16.c @@ -15,15 +15,8 @@ #include "emu.h" #include "includes/twin16.h" -static UINT16 twin16_sprite_buffer[0x800]; static TIMER_CALLBACK( twin16_sprite_tick ); -static emu_timer *twin16_sprite_timer; -static int twin16_sprite_busy; -static int need_process_spriteram; -static UINT16 gfx_bank; -static UINT16 scrollx[3], scrolly[3]; -static UINT16 video_register; enum { @@ -46,12 +39,12 @@ enum TWIN16_SPRITE_CAST_SHADOW = 0x20 }; -static tilemap_t *text_tilemap; WRITE16_HANDLER( twin16_text_ram_w ) { - COMBINE_DATA(&twin16_text_ram[offset]); - tilemap_mark_tile_dirty(text_tilemap, offset); + twin16_state *state = space->machine->driver_data(); + COMBINE_DATA(&state->text_ram[offset]); + tilemap_mark_tile_dirty(state->text_tilemap, offset); } WRITE16_HANDLER( twin16_paletteram_word_w ) @@ -65,30 +58,32 @@ WRITE16_HANDLER( twin16_paletteram_word_w ) WRITE16_HANDLER( fround_gfx_bank_w ) { - COMBINE_DATA(&gfx_bank); + twin16_state *state = space->machine->driver_data(); + COMBINE_DATA(&state->gfx_bank); } WRITE16_HANDLER( twin16_video_register_w ) { + twin16_state *state = space->machine->driver_data(); switch (offset) { case 0: - COMBINE_DATA( &video_register ); + COMBINE_DATA( &state->video_register ); - flip_screen_x_set(space->machine, video_register & TWIN16_SCREEN_FLIPX); - flip_screen_y_set(space->machine, video_register & TWIN16_SCREEN_FLIPY); + flip_screen_x_set(space->machine, state->video_register & TWIN16_SCREEN_FLIPX); + flip_screen_y_set(space->machine, state->video_register & TWIN16_SCREEN_FLIPY); break; - case 1: COMBINE_DATA( &scrollx[0] ); break; - case 2: COMBINE_DATA( &scrolly[0] ); break; - case 3: COMBINE_DATA( &scrollx[1] ); break; - case 4: COMBINE_DATA( &scrolly[1] ); break; - case 5: COMBINE_DATA( &scrollx[2] ); break; - case 6: COMBINE_DATA( &scrolly[2] ); break; + case 1: COMBINE_DATA( &state->scrollx[0] ); break; + case 2: COMBINE_DATA( &state->scrolly[0] ); break; + case 3: COMBINE_DATA( &state->scrollx[1] ); break; + case 4: COMBINE_DATA( &state->scrolly[1] ); break; + case 5: COMBINE_DATA( &state->scrollx[2] ); break; + case 6: COMBINE_DATA( &state->scrolly[2] ); break; default: - logerror("unknown video_register write:%d", data ); + logerror("unknown state->video_register write:%d", data ); break; } } @@ -141,31 +136,35 @@ WRITE16_HANDLER( twin16_video_register_w ) READ16_HANDLER( twin16_sprite_status_r ) { + twin16_state *state = space->machine->driver_data(); // bit 0: busy, other bits: dunno - return twin16_sprite_busy; + return state->sprite_busy; } static TIMER_CALLBACK( twin16_sprite_tick ) { - twin16_sprite_busy = 0; + twin16_state *state = machine->driver_data(); + state->sprite_busy = 0; } static int twin16_set_sprite_timer( running_machine *machine ) { - if (twin16_sprite_busy) return 1; + twin16_state *state = machine->driver_data(); + if (state->sprite_busy) return 1; // sprite system busy, maybe a dma? time is guessed, assume 4 scanlines - twin16_sprite_busy = 1; - twin16_sprite_timer->adjust(machine->primary_screen->frame_period() / machine->primary_screen->height() * 4); + state->sprite_busy = 1; + state->sprite_timer->adjust(machine->primary_screen->frame_period() / machine->primary_screen->height() * 4); return 0; } void twin16_spriteram_process( running_machine *machine ) { + twin16_state *state = machine->driver_data(); UINT16 *spriteram16 = machine->generic.spriteram.u16; - UINT16 dx = scrollx[0]; - UINT16 dy = scrolly[0]; + UINT16 dx = state->scrollx[0]; + UINT16 dy = state->scrolly[0]; const UINT16 *source = &spriteram16[0x0000]; const UINT16 *finish = &spriteram16[0x1800]; @@ -219,11 +218,12 @@ void twin16_spriteram_process( running_machine *machine ) } source += 0x50/2; } - need_process_spriteram = 0; + state->need_process_spriteram = 0; } static void draw_sprites( running_machine *machine, bitmap_t *bitmap ) { + twin16_state *state = machine->driver_data(); const UINT16 *source = 0x1800+machine->generic.buffered_spriteram.u16 + 0x800 - 4; const UINT16 *finish = 0x1800+machine->generic.buffered_spriteram.u16; @@ -246,9 +246,9 @@ static void draw_sprites( running_machine *machine, bitmap_t *bitmap ) int flipx = attributes&0x0100; int priority = (attributes&0x4000)?TWIN16_SPRITE_PRI_L1:TWIN16_SPRITE_PRI_L2; - if( twin16_custom_video ) { + if( state->custom_video ) { /* fround board */ - pen_data = twin16_gfx_rom + 0x80000; + pen_data = state->gfx_rom + 0x80000; } else { @@ -256,20 +256,20 @@ static void draw_sprites( running_machine *machine, bitmap_t *bitmap ) { /* bank select */ case 0: - pen_data = twin16_gfx_rom; + pen_data = state->gfx_rom; break; case 1: - pen_data = twin16_gfx_rom + 0x40000; + pen_data = state->gfx_rom + 0x40000; break; case 2: - pen_data = twin16_gfx_rom + 0x80000; + pen_data = state->gfx_rom + 0x80000; if( code&0x4000 ) pen_data += 0x40000; break; case 3: - pen_data = twin16_sprite_gfx_ram; + pen_data = state->sprite_gfx_ram; break; } code &= 0xfff; @@ -282,13 +282,13 @@ static void draw_sprites( running_machine *machine, bitmap_t *bitmap ) pen_data += code*0x40; - if( video_register&TWIN16_SCREEN_FLIPY ) + if( state->video_register&TWIN16_SCREEN_FLIPY ) { if (ypos>65000) ypos=ypos-65536; /* Bit hacky */ ypos = 256-ypos-height; flipy = !flipy; } - if( video_register&TWIN16_SCREEN_FLIPX ) + if( state->video_register&TWIN16_SCREEN_FLIPX ) { if (xpos>65000) xpos=xpos-65536; /* Bit hacky */ xpos = 320-xpos-width; @@ -353,45 +353,45 @@ static void draw_layer( running_machine *machine, bitmap_t *bitmap, int opaque ) int i, xxor, yxor; int bank_table[4]; int dx, dy, palette; - int tile_flipx = video_register&TWIN16_TILE_FLIPX; - int tile_flipy = video_register&TWIN16_TILE_FLIPY; + int tile_flipx = state->video_register&TWIN16_TILE_FLIPX; + int tile_flipy = state->video_register&TWIN16_TILE_FLIPY; - if( ((video_register&TWIN16_PLANE_ORDER)?1:0) != opaque ) { + if( ((state->video_register&TWIN16_PLANE_ORDER)?1:0) != opaque ) { source += 0x1000; - dx = scrollx[2]; - dy = scrolly[2]; + dx = state->scrollx[2]; + dy = state->scrolly[2]; palette = 1; } else { source += 0x0000; - dx = scrollx[1]; - dy = scrolly[1]; + dx = state->scrollx[1]; + dy = state->scrolly[1]; palette = 0; } - if( twin16_custom_video ) { + if( state->custom_video ) { /* fround board */ - gfx_base = twin16_gfx_rom; - bank_table[3] = (gfx_bank>>(4*3))&0xf; - bank_table[2] = (gfx_bank>>(4*2))&0xf; - bank_table[1] = (gfx_bank>>(4*1))&0xf; - bank_table[0] = (gfx_bank>>(4*0))&0xf; + gfx_base = state->gfx_rom; + bank_table[3] = (state->gfx_bank>>(4*3))&0xf; + bank_table[2] = (state->gfx_bank>>(4*2))&0xf; + bank_table[1] = (state->gfx_bank>>(4*1))&0xf; + bank_table[0] = (state->gfx_bank>>(4*0))&0xf; } else { - gfx_base = twin16_tile_gfx_ram; + gfx_base = state->tile_gfx_ram; bank_table[0] = 0; bank_table[1] = 1; bank_table[2] = 2; bank_table[3] = 3; } - if( video_register&TWIN16_SCREEN_FLIPX ) + if( state->video_register&TWIN16_SCREEN_FLIPX ) { dx = 256-dx-64; tile_flipx = !tile_flipx; } - if( video_register&TWIN16_SCREEN_FLIPY ) + if( state->video_register&TWIN16_SCREEN_FLIPY ) { dy = 256-dy; tile_flipy = !tile_flipy; @@ -407,8 +407,8 @@ static void draw_layer( running_machine *machine, bitmap_t *bitmap, int opaque ) int sy = (i/64)*8; int xpos,ypos; - if( video_register&TWIN16_SCREEN_FLIPX ) sx = 63*8 - sx; - if( video_register&TWIN16_SCREEN_FLIPY ) sy = 63*8 - sy; + if( state->video_register&TWIN16_SCREEN_FLIPX ) sx = 63*8 - sx; + if( state->video_register&TWIN16_SCREEN_FLIPY ) sy = 63*8 - sy; xpos = (sx-dx)&0x1ff; ypos = (sy-dy)&0x1ff; @@ -477,7 +477,8 @@ static void draw_layer( running_machine *machine, bitmap_t *bitmap, int opaque ) static TILE_GET_INFO( get_text_tile_info ) { - const UINT16 *source = twin16_text_ram; + twin16_state *state = machine->driver_data(); + const UINT16 *source = state->text_ram; int attr = source[tile_index]; /* fedcba9876543210 -x-------------- yflip @@ -497,56 +498,59 @@ static TILE_GET_INFO( get_text_tile_info ) VIDEO_START( twin16 ) { - text_tilemap = tilemap_create(machine, get_text_tile_info, tilemap_scan_rows, 8, 8, 64, 32); - tilemap_set_transparent_pen(text_tilemap, 0); + twin16_state *state = machine->driver_data(); + state->text_tilemap = tilemap_create(machine, get_text_tile_info, tilemap_scan_rows, 8, 8, 64, 32); + tilemap_set_transparent_pen(state->text_tilemap, 0); palette_set_shadow_factor(machine,0.4); // screenshots estimate - memset(twin16_sprite_buffer,0xff,0x800*sizeof(UINT16)); - twin16_sprite_busy = 0; - twin16_sprite_timer = machine->scheduler().timer_alloc(FUNC(twin16_sprite_tick)); - twin16_sprite_timer->adjust(attotime::never); + memset(state->sprite_buffer,0xff,0x800*sizeof(UINT16)); + state->sprite_busy = 0; + state->sprite_timer = machine->scheduler().timer_alloc(FUNC(twin16_sprite_tick)); + state->sprite_timer->adjust(attotime::never); /* register for savestates */ - state_save_register_global_array(machine, twin16_sprite_buffer); - state_save_register_global_array(machine, scrollx); - state_save_register_global_array(machine, scrolly); + state_save_register_global_array(machine, state->sprite_buffer); + state_save_register_global_array(machine, state->scrollx); + state_save_register_global_array(machine, state->scrolly); - state_save_register_global(machine, need_process_spriteram); - state_save_register_global(machine, gfx_bank); - state_save_register_global(machine, video_register); - state_save_register_global(machine, twin16_sprite_busy); + state_save_register_global(machine, state->need_process_spriteram); + state_save_register_global(machine, state->gfx_bank); + state_save_register_global(machine, state->video_register); + state_save_register_global(machine, state->sprite_busy); } VIDEO_UPDATE( twin16 ) { + twin16_state *state = screen->machine->driver_data(); int text_flip=0; - if (video_register&TWIN16_SCREEN_FLIPX) text_flip|=TILEMAP_FLIPX; - if (video_register&TWIN16_SCREEN_FLIPY) text_flip|=TILEMAP_FLIPY; + if (state->video_register&TWIN16_SCREEN_FLIPX) text_flip|=TILEMAP_FLIPX; + if (state->video_register&TWIN16_SCREEN_FLIPY) text_flip|=TILEMAP_FLIPY; bitmap_fill(screen->machine->priority_bitmap,cliprect,0); draw_layer( screen->machine, bitmap, 1 ); draw_layer( screen->machine, bitmap, 0 ); draw_sprites( screen->machine, bitmap ); - if (text_flip) tilemap_set_flip(text_tilemap, text_flip); - tilemap_draw(bitmap, cliprect, text_tilemap, 0, 0); + if (text_flip) tilemap_set_flip(state->text_tilemap, text_flip); + tilemap_draw(bitmap, cliprect, state->text_tilemap, 0, 0); return 0; } VIDEO_EOF( twin16 ) { + twin16_state *state = machine->driver_data(); twin16_set_sprite_timer(machine); - if (twin16_spriteram_process_enable()) { - if (need_process_spriteram) twin16_spriteram_process(machine); - need_process_spriteram = 1; + if (twin16_spriteram_process_enable(machine)) { + if (state->need_process_spriteram) twin16_spriteram_process(machine); + state->need_process_spriteram = 1; /* if the sprite preprocessor is used, sprite ram is copied to an external buffer first, as evidenced by 1-frame sprite lag in gradius2 and devilw otherwise, though there's probably more to it than that */ - memcpy(&machine->generic.buffered_spriteram.u16[0x1800],twin16_sprite_buffer,0x800*sizeof(UINT16)); - memcpy(twin16_sprite_buffer,&machine->generic.spriteram.u16[0x1800],0x800*sizeof(UINT16)); + memcpy(&machine->generic.buffered_spriteram.u16[0x1800],state->sprite_buffer,0x800*sizeof(UINT16)); + memcpy(state->sprite_buffer,&machine->generic.spriteram.u16[0x1800],0x800*sizeof(UINT16)); } else { address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); diff --git a/src/mame/video/wecleman.c b/src/mame/video/wecleman.c index bdb906c58e7..9751824fe1d 100644 --- a/src/mame/video/wecleman.c +++ b/src/mame/video/wecleman.c @@ -37,25 +37,6 @@ struct sprite int shadow_mode, flags; }; -/* Variables that driver has acces to: */ -UINT16 *wecleman_videostatus; -UINT16 *wecleman_pageram, *wecleman_txtram, *wecleman_roadram; -size_t wecleman_roadram_size; -static int wecleman_bgpage[4], wecleman_fgpage[4]; -static const int *wecleman_gfx_bank; - -/* Variables only used here: */ -static tilemap_t *bg_tilemap, *fg_tilemap, *txt_tilemap; - -static struct sprite *sprite_list; -static struct sprite **spr_ptr_list; -static int *spr_idx_list, *spr_pri_list, *t32x32pm; -static int gameid, spr_offsx, spr_offsy, spr_count; -static UINT16 *rgb_half; - -static int cloud_blend, cloud_ds, cloud_visible; -static pen_t black_pen; - /*************************************************************************** @@ -94,18 +75,19 @@ static pen_t black_pen; static void get_sprite_info(running_machine *machine) { + wecleman_state *state = machine->driver_data(); const pen_t *base_pal = machine->pens; UINT8 *base_gfx = machine->region("gfx1")->base(); int gfx_max = machine->region("gfx1")->bytes(); UINT16 *source = machine->generic.spriteram.u16; - struct sprite *sprite = sprite_list; - struct sprite *finish = sprite_list + NUM_SPRITES; + struct sprite *sprite = state->sprite_list; + struct sprite *finish = state->sprite_list + NUM_SPRITES; int bank, code, gfx, zoom; - for (spr_count=0; spritespr_count=0; spritepal_base = (source[0x0e/2] & 0xff) << 4; sprite->pal_data = base_pal + sprite->pal_base; - gfx = (wecleman_gfx_bank[bank] << 15) + (code & 0x7fff); + gfx = (state->gfx_bank[bank] << 15) + (code & 0x7fff); sprite->flags = 0; if (code & 0x8000) { sprite->flags |= SPRITE_FLIPX; gfx += 1-sprite->tile_width; } @@ -144,17 +126,17 @@ static void get_sprite_info(running_machine *machine) sprite->line_offset = sprite->tile_width; sprite->total_width = sprite->tile_width - (sprite->tile_width * (zoom & 0xff)) / 0x80; sprite->total_height += 1; - sprite->x += spr_offsx; - sprite->y += spr_offsy; + sprite->x += state->spr_offsx; + sprite->y += state->spr_offsy; - if (gameid == 0) + if (state->gameid == 0) { - spr_idx_list[spr_count] = spr_count; - spr_pri_list[spr_count] = source[0x0e/2] >> 8; + state->spr_idx_list[state->spr_count] = state->spr_count; + state->spr_pri_list[state->spr_count] = source[0x0e/2] >> 8; } - spr_ptr_list[spr_count] = sprite; - spr_count++; + state->spr_ptr_list[state->spr_count] = sprite; + state->spr_count++; } } @@ -187,7 +169,7 @@ static void sortsprite(int *idx_array, int *key_array, int size) } // draws a 8bpp palette sprites on a 16bpp direct RGB target (sub-par implementation) -static void do_blit_zoom32(bitmap_t *bitmap, const rectangle *cliprect, struct sprite *sprite) +static void do_blit_zoom32(wecleman_state *state, bitmap_t *bitmap, const rectangle *cliprect, struct sprite *sprite) { #define PRECISION_X 20 #define PRECISION_Y 20 @@ -335,7 +317,7 @@ static void do_blit_zoom32(bitmap_t *bitmap, const rectangle *cliprect, struct s dst_ptr[sx] = base + pix; else { - if (dst_ptr[sx] != black_pen) + if (dst_ptr[sx] != state->black_pen) dst_ptr[sx] |= 0x800; } } @@ -348,19 +330,20 @@ static void do_blit_zoom32(bitmap_t *bitmap, const rectangle *cliprect, struct s } } -static void sprite_draw(bitmap_t *bitmap, const rectangle *cliprect) +static void sprite_draw(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect) { + wecleman_state *state = machine->driver_data(); int i; - if (gameid == 0) // Wec Le Mans + if (state->gameid == 0) // Wec Le Mans { - sortsprite(spr_idx_list, spr_pri_list, spr_count); + sortsprite(state->spr_idx_list, state->spr_pri_list, state->spr_count); - for (i=0; ispr_count; i++) do_blit_zoom32(state, bitmap, cliprect, state->spr_ptr_list[state->spr_idx_list[i]]); } else // Hot Chase { - for (i=0; ispr_count; i++) do_blit_zoom32(state, bitmap, cliprect, state->spr_ptr_list[i]); } } @@ -436,14 +419,16 @@ static void sprite_draw(bitmap_t *bitmap, const rectangle *cliprect) static TILE_GET_INFO( wecleman_get_txt_tile_info ) { - int code = wecleman_txtram[tile_index]; + wecleman_state *state = machine->driver_data(); + int code = state->txtram[tile_index]; SET_TILE_INFO(PAGE_GFX, code&0xfff, (code>>5&0x78)+(code>>12), 0); } WRITE16_HANDLER( wecleman_txtram_w ) { - UINT16 old_data = wecleman_txtram[offset]; - UINT16 new_data = COMBINE_DATA(&wecleman_txtram[offset]); + wecleman_state *state = space->machine->driver_data(); + UINT16 old_data = state->txtram[offset]; + UINT16 new_data = COMBINE_DATA(&state->txtram[offset]); if ( old_data != new_data ) { @@ -452,27 +437,27 @@ WRITE16_HANDLER( wecleman_txtram_w ) /* pages selector for the background */ if (offset == 0xEFE/2) { - wecleman_bgpage[0] = (new_data >> 0x4) & 3; - wecleman_bgpage[1] = (new_data >> 0x0) & 3; - wecleman_bgpage[2] = (new_data >> 0xc) & 3; - wecleman_bgpage[3] = (new_data >> 0x8) & 3; - tilemap_mark_all_tiles_dirty(bg_tilemap); + state->bgpage[0] = (new_data >> 0x4) & 3; + state->bgpage[1] = (new_data >> 0x0) & 3; + state->bgpage[2] = (new_data >> 0xc) & 3; + state->bgpage[3] = (new_data >> 0x8) & 3; + tilemap_mark_all_tiles_dirty(state->bg_tilemap); } /* pages selector for the foreground */ if (offset == 0xEFC/2) { - wecleman_fgpage[0] = (new_data >> 0x4) & 3; - wecleman_fgpage[1] = (new_data >> 0x0) & 3; - wecleman_fgpage[2] = (new_data >> 0xc) & 3; - wecleman_fgpage[3] = (new_data >> 0x8) & 3; - tilemap_mark_all_tiles_dirty(fg_tilemap); + state->fgpage[0] = (new_data >> 0x4) & 3; + state->fgpage[1] = (new_data >> 0x0) & 3; + state->fgpage[2] = (new_data >> 0xc) & 3; + state->fgpage[3] = (new_data >> 0x8) & 3; + tilemap_mark_all_tiles_dirty(state->fg_tilemap); } /* Parallactic horizontal scroll registers follow */ } else - tilemap_mark_tile_dirty(txt_tilemap, offset); + tilemap_mark_tile_dirty(state->txt_tilemap, offset); } } @@ -482,8 +467,9 @@ WRITE16_HANDLER( wecleman_txtram_w ) static TILE_GET_INFO( wecleman_get_bg_tile_info ) { - int page = wecleman_bgpage[((tile_index&0x7f)>>6) + ((tile_index>>12)<<1)]; - int code = wecleman_pageram[(tile_index&0x3f) + ((tile_index>>7&0x1f)<<6) + (page<<11)]; + wecleman_state *state = machine->driver_data(); + int page = state->bgpage[((tile_index&0x7f)>>6) + ((tile_index>>12)<<1)]; + int code = state->pageram[(tile_index&0x3f) + ((tile_index>>7&0x1f)<<6) + (page<<11)]; SET_TILE_INFO(PAGE_GFX, code&0xfff, (code>>5&0x78)+(code>>12), 0); } @@ -494,8 +480,9 @@ static TILE_GET_INFO( wecleman_get_bg_tile_info ) static TILE_GET_INFO( wecleman_get_fg_tile_info ) { - int page = wecleman_fgpage[((tile_index&0x7f)>>6) + ((tile_index>>12)<<1)]; - int code = wecleman_pageram[(tile_index&0x3f) + ((tile_index>>7&0x1f)<<6) + (page<<11)]; + wecleman_state *state = machine->driver_data(); + int page = state->fgpage[((tile_index&0x7f)>>6) + ((tile_index>>12)<<1)]; + int code = state->pageram[(tile_index&0x3f) + ((tile_index>>7&0x1f)<<6) + (page<<11)]; if (!code || code==0xffff) code = 0x20; SET_TILE_INFO(PAGE_GFX, code&0xfff, (code>>5&0x78)+(code>>12), 0); @@ -508,7 +495,8 @@ static TILE_GET_INFO( wecleman_get_fg_tile_info ) /* Pages that compose both the background and the foreground */ WRITE16_HANDLER( wecleman_pageram_w ) { - COMBINE_DATA(&wecleman_pageram[offset]); + wecleman_state *state = space->machine->driver_data(); + COMBINE_DATA(&state->pageram[offset]); { int page,col,row; @@ -518,16 +506,16 @@ WRITE16_HANDLER( wecleman_pageram_w ) row = ( offset / PAGE_NX ) % PAGE_NY; /* background */ - if (wecleman_bgpage[0] == page) tilemap_mark_tile_dirty(bg_tilemap, (col+PAGE_NX*0) + (row+PAGE_NY*0)*PAGE_NX*2 ); - if (wecleman_bgpage[1] == page) tilemap_mark_tile_dirty(bg_tilemap, (col+PAGE_NX*1) + (row+PAGE_NY*0)*PAGE_NX*2 ); - if (wecleman_bgpage[2] == page) tilemap_mark_tile_dirty(bg_tilemap, (col+PAGE_NX*0) + (row+PAGE_NY*1)*PAGE_NX*2 ); - if (wecleman_bgpage[3] == page) tilemap_mark_tile_dirty(bg_tilemap, (col+PAGE_NX*1) + (row+PAGE_NY*1)*PAGE_NX*2 ); + if (state->bgpage[0] == page) tilemap_mark_tile_dirty(state->bg_tilemap, (col+PAGE_NX*0) + (row+PAGE_NY*0)*PAGE_NX*2 ); + if (state->bgpage[1] == page) tilemap_mark_tile_dirty(state->bg_tilemap, (col+PAGE_NX*1) + (row+PAGE_NY*0)*PAGE_NX*2 ); + if (state->bgpage[2] == page) tilemap_mark_tile_dirty(state->bg_tilemap, (col+PAGE_NX*0) + (row+PAGE_NY*1)*PAGE_NX*2 ); + if (state->bgpage[3] == page) tilemap_mark_tile_dirty(state->bg_tilemap, (col+PAGE_NX*1) + (row+PAGE_NY*1)*PAGE_NX*2 ); /* foreground */ - if (wecleman_fgpage[0] == page) tilemap_mark_tile_dirty(fg_tilemap, (col+PAGE_NX*0) + (row+PAGE_NY*0)*PAGE_NX*2 ); - if (wecleman_fgpage[1] == page) tilemap_mark_tile_dirty(fg_tilemap, (col+PAGE_NX*1) + (row+PAGE_NY*0)*PAGE_NX*2 ); - if (wecleman_fgpage[2] == page) tilemap_mark_tile_dirty(fg_tilemap, (col+PAGE_NX*0) + (row+PAGE_NY*1)*PAGE_NX*2 ); - if (wecleman_fgpage[3] == page) tilemap_mark_tile_dirty(fg_tilemap, (col+PAGE_NX*1) + (row+PAGE_NY*1)*PAGE_NX*2 ); + if (state->fgpage[0] == page) tilemap_mark_tile_dirty(state->fg_tilemap, (col+PAGE_NX*0) + (row+PAGE_NY*0)*PAGE_NX*2 ); + if (state->fgpage[1] == page) tilemap_mark_tile_dirty(state->fg_tilemap, (col+PAGE_NX*1) + (row+PAGE_NY*0)*PAGE_NX*2 ); + if (state->fgpage[2] == page) tilemap_mark_tile_dirty(state->fg_tilemap, (col+PAGE_NX*0) + (row+PAGE_NY*1)*PAGE_NX*2 ); + if (state->fgpage[3] == page) tilemap_mark_tile_dirty(state->fg_tilemap, (col+PAGE_NX*1) + (row+PAGE_NY*1)*PAGE_NX*2 ); } } @@ -553,6 +541,7 @@ WRITE16_HANDLER( wecleman_pageram_w ) static void wecleman_draw_road(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int priority) { + wecleman_state *state = machine->driver_data(); // must be powers of 2 #define XSIZE 512 #define YSIZE 256 @@ -593,10 +582,10 @@ static void wecleman_draw_road(running_machine *machine, bitmap_t *bitmap, const UINT32 pix; UINT16 road; - road = wecleman_roadram[sy]; + road = state->roadram[sy]; if ((road>>8) != 0x02) continue; - pix = rgb_ptr[(wecleman_roadram[sy+(YSIZE*2)] & 0xf) + 0x7f0]; + pix = rgb_ptr[(state->roadram[sy+(YSIZE*2)] & 0xf) + 0x7f0]; for (sx = 0; sx < DST_WIDTH; sx++) dst[sx] = pix; @@ -619,7 +608,7 @@ static void wecleman_draw_road(running_machine *machine, bitmap_t *bitmap, const UINT32 pix; UINT16 road; - road = wecleman_roadram[sy]; + road = state->roadram[sy]; if ((road>>8) != 0x04) continue; road &= YMASK; @@ -634,9 +623,9 @@ static void wecleman_draw_road(running_machine *machine, bitmap_t *bitmap, const mdy = ((road * MIDCURB_DY) >> 8) * bitmap->rowpixels; tdy = ((road * TOPCURB_DY) >> 8) * bitmap->rowpixels; - scrollx = wecleman_roadram[sy+YSIZE] + (0x18 - 0xe00); + scrollx = state->roadram[sy+YSIZE] + (0x18 - 0xe00); - pal_ptr = road_rgb + ((wecleman_roadram[sy+(YSIZE*2)]<<3) & 8); + pal_ptr = road_rgb + ((state->roadram[sy+(YSIZE*2)]<<3) & 8); for (sx = 0; sx < DST_WIDTH; sx++, scrollx++) { @@ -677,6 +666,7 @@ static void draw_cloud(bitmap_t *bitmap, int tmw_l2, int tmh_l2, // tilemap width and height in log(2) int alpha, int pal_offset ) // alpha(0-3f), # of color codes to shift { + wecleman_state *state = gfx->machine->driver_data(); const UINT8 *src_ptr; UINT16 *tmap_ptr; UINT32 *dst_base, *dst_ptr; @@ -749,9 +739,9 @@ static void draw_cloud(bitmap_t *bitmap, dg = (dstrgb >> 11) & 0x1f; db = (dstrgb >> 19) & 0x1f; - dr = (t32x32pm[dr - sr + alpha] >> 5) + dr; - dg = (t32x32pm[dg - sg + alpha] >> 5) + dg; - db = (t32x32pm[db - sb + alpha] >> 5) + db; + dr = (state->t32x32pm[dr - sr + alpha] >> 5) + dr; + dg = (state->t32x32pm[dg - sg + alpha] >> 5) + dg; + db = (state->t32x32pm[db - sb + alpha] >> 5) + db; dst_ptr[tx] = MAKE_RGB(pal5bit(db), pal5bit(dg), pal5bit(dr)); } @@ -804,6 +794,7 @@ static void draw_cloud(bitmap_t *bitmap, static void hotchase_draw_road(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect) { + wecleman_state *state = machine->driver_data(); /* Referred to what's in the ROMs */ #define XSIZE 512 #define YSIZE 512 @@ -814,7 +805,7 @@ static void hotchase_draw_road(running_machine *machine, bitmap_t *bitmap, const /* Let's draw from the top to the bottom of the visible screen */ for (sy = visarea.min_y;sy <= visarea.max_y;sy++) { - int code = wecleman_roadram[sy*4/2+2/2] + (wecleman_roadram[sy*4/2+0/2] << 16); + int code = state->roadram[sy*4/2+2/2] + (state->roadram[sy*4/2+0/2] << 16); int color = ((code & 0x00f00000) >> 20) + 0x70; int scrollx = ((code & 0x0007fc00) >> 10) * 2; @@ -845,20 +836,21 @@ static void hotchase_draw_road(running_machine *machine, bitmap_t *bitmap, const // new video and palette code WRITE16_HANDLER( wecleman_videostatus_w ) { - COMBINE_DATA(wecleman_videostatus); + wecleman_state *state = space->machine->driver_data(); + COMBINE_DATA(state->videostatus); // bit0-6: background transition, 0=off, 1=on // bit7: palette being changed, 0=no, 1=yes if (ACCESSING_BITS_0_7) { - if ((data & 0x7f) == 0 && !cloud_ds) - cloud_ds = BLEND_INC; + if ((data & 0x7f) == 0 && !state->cloud_ds) + state->cloud_ds = BLEND_INC; else - if ((data & 0x7f) == 1 && !cloud_visible) + if ((data & 0x7f) == 1 && !state->cloud_visible) { data ^= 1; - cloud_ds = BLEND_DEC; - cloud_visible = 1; + state->cloud_ds = BLEND_DEC; + state->cloud_visible = 1; } } } @@ -894,6 +886,7 @@ WRITE16_HANDLER( wecleman_paletteram16_SSSSBBBBGGGGRRRR_word_w ) VIDEO_START( wecleman ) { + wecleman_state *state = machine->driver_data(); /* Sprite banking - each bank is 0x20000 bytes (we support 0x40 bank codes) This game has ROMs for 16 banks @@ -912,69 +905,69 @@ VIDEO_START( wecleman ) assert(machine->primary_screen->format() == BITMAP_FORMAT_RGB32); buffer = auto_alloc_array(machine, UINT8, 0x12c00); // working buffer for sprite operations - gameid = 0; - wecleman_gfx_bank = bank; - spr_offsx = -0xbc + BMP_PAD; - spr_offsy = 1 + BMP_PAD; - cloud_blend = BLEND_MAX; - cloud_ds = 0; - cloud_visible = 0; - black_pen = get_black_pen(machine); + state->gameid = 0; + state->gfx_bank = bank; + state->spr_offsx = -0xbc + BMP_PAD; + state->spr_offsy = 1 + BMP_PAD; + state->cloud_blend = BLEND_MAX; + state->cloud_ds = 0; + state->cloud_visible = 0; + state->black_pen = get_black_pen(machine); - rgb_half = (UINT16*)(buffer + 0x00000); - t32x32pm = (int*)(buffer + 0x10020); - spr_ptr_list = (struct sprite **)(buffer + 0x12000); - spr_idx_list = (int *)(buffer + 0x12400); - spr_pri_list = (int *)(buffer + 0x12800); + state->rgb_half = (UINT16*)(buffer + 0x00000); + state->t32x32pm = (int*)(buffer + 0x10020); + state->spr_ptr_list = (struct sprite **)(buffer + 0x12000); + state->spr_idx_list = (int *)(buffer + 0x12400); + state->spr_pri_list = (int *)(buffer + 0x12800); for (i=0; i<0x8000; i++) { j = i>>1; - rgb_half[i] = (j&0xf) | (j&0x1e0) | (j&0x3c00); + state->rgb_half[i] = (j&0xf) | (j&0x1e0) | (j&0x3c00); } for (j=0; j<0x20; j++) { for (i=-0x1f; i<0x20; i++) { - *(t32x32pm + (j<<6) + i) = i * j; + *(state->t32x32pm + (j<<6) + i) = i * j; } } - sprite_list = auto_alloc_array_clear(machine, struct sprite, NUM_SPRITES); + state->sprite_list = auto_alloc_array_clear(machine, struct sprite, NUM_SPRITES); - bg_tilemap = tilemap_create(machine, wecleman_get_bg_tile_info, + state->bg_tilemap = tilemap_create(machine, wecleman_get_bg_tile_info, tilemap_scan_rows, /* We draw part of the road below */ 8,8, PAGE_NX * 2, PAGE_NY * 2 ); - fg_tilemap = tilemap_create(machine, wecleman_get_fg_tile_info, + state->fg_tilemap = tilemap_create(machine, wecleman_get_fg_tile_info, tilemap_scan_rows, 8,8, PAGE_NX * 2, PAGE_NY * 2); - txt_tilemap = tilemap_create(machine, wecleman_get_txt_tile_info, + state->txt_tilemap = tilemap_create(machine, wecleman_get_txt_tile_info, tilemap_scan_rows, 8,8, PAGE_NX * 1, PAGE_NY * 1); - tilemap_set_scroll_rows(bg_tilemap, TILEMAP_DIMY); /* Screen-wise scrolling */ - tilemap_set_scroll_cols(bg_tilemap, 1); - tilemap_set_transparent_pen(bg_tilemap,0); + tilemap_set_scroll_rows(state->bg_tilemap, TILEMAP_DIMY); /* Screen-wise scrolling */ + tilemap_set_scroll_cols(state->bg_tilemap, 1); + tilemap_set_transparent_pen(state->bg_tilemap,0); - tilemap_set_scroll_rows(fg_tilemap, TILEMAP_DIMY); /* Screen-wise scrolling */ - tilemap_set_scroll_cols(fg_tilemap, 1); - tilemap_set_transparent_pen(fg_tilemap,0); + tilemap_set_scroll_rows(state->fg_tilemap, TILEMAP_DIMY); /* Screen-wise scrolling */ + tilemap_set_scroll_cols(state->fg_tilemap, 1); + tilemap_set_transparent_pen(state->fg_tilemap,0); - tilemap_set_scroll_rows(txt_tilemap, 1); - tilemap_set_scroll_cols(txt_tilemap, 1); - tilemap_set_transparent_pen(txt_tilemap,0); + tilemap_set_scroll_rows(state->txt_tilemap, 1); + tilemap_set_scroll_cols(state->txt_tilemap, 1); + tilemap_set_transparent_pen(state->txt_tilemap,0); - tilemap_set_scrollx(txt_tilemap, 0, 512-320-16 -BMP_PAD); - tilemap_set_scrolly(txt_tilemap, 0, -BMP_PAD ); + tilemap_set_scrollx(state->txt_tilemap, 0, 512-320-16 -BMP_PAD); + tilemap_set_scrolly(state->txt_tilemap, 0, -BMP_PAD ); // patches out a mysterious pixel floating in the sky (tile decoding bug?) *(machine->gfx[0]->gfxdata + (machine->gfx[0]->char_modulo*0xaca+7)) = 0; @@ -996,6 +989,7 @@ void hotchase_zoom_callback_1(running_machine *machine, int *code,int *color,int VIDEO_START( hotchase ) { + wecleman_state *state = machine->driver_data(); /* Sprite banking - each bank is 0x20000 bytes (we support 0x40 bank codes) This game has ROMs for 0x30 banks @@ -1012,15 +1006,15 @@ VIDEO_START( hotchase ) buffer = auto_alloc_array(machine, UINT8, 0x400); // reserve 1k for sprite list - gameid = 1; - wecleman_gfx_bank = bank; - spr_offsx = -0xc0; - spr_offsy = 0; - black_pen = get_black_pen(machine); + state->gameid = 1; + state->gfx_bank = bank; + state->spr_offsx = -0xc0; + state->spr_offsy = 0; + state->black_pen = get_black_pen(machine); - spr_ptr_list = (struct sprite **)buffer; + state->spr_ptr_list = (struct sprite **)buffer; - sprite_list = auto_alloc_array_clear(machine, struct sprite, NUM_SPRITES); + state->sprite_list = auto_alloc_array_clear(machine, struct sprite, NUM_SPRITES); } @@ -1030,6 +1024,7 @@ VIDEO_START( hotchase ) VIDEO_UPDATE ( wecleman ) { + wecleman_state *state = screen->machine->driver_data(); const pen_t *mrct; int video_on; int fg_x, bg_x, fg_y, bg_y; @@ -1038,29 +1033,29 @@ VIDEO_UPDATE ( wecleman ) mrct = screen->machine->pens; - video_on = wecleman_irqctrl & 0x40; + video_on = state->irqctrl & 0x40; - set_led_status(screen->machine, 0, wecleman_selected_ip & 0x04); // Start lamp + set_led_status(screen->machine, 0, state->selected_ip & 0x04); // Start lamp - fg_y = (wecleman_txtram[0x0f24>>1] & (TILEMAP_DIMY - 1)); - bg_y = (wecleman_txtram[0x0f26>>1] & (TILEMAP_DIMY - 1)); + fg_y = (state->txtram[0x0f24>>1] & (TILEMAP_DIMY - 1)); + bg_y = (state->txtram[0x0f26>>1] & (TILEMAP_DIMY - 1)); - cloud_sx = wecleman_txtram[0xfee>>1] + 0xb0; + cloud_sx = state->txtram[0xfee>>1] + 0xb0; cloud_sy = bg_y; - tilemap_set_scrolly(bg_tilemap, 0, bg_y -BMP_PAD); - tilemap_set_scrolly(fg_tilemap, 0, fg_y -BMP_PAD); + tilemap_set_scrolly(state->bg_tilemap, 0, bg_y -BMP_PAD); + tilemap_set_scrolly(state->fg_tilemap, 0, fg_y -BMP_PAD); for (i=0; i<(28<<2); i+=4) { - fg_x = wecleman_txtram[(i+0xf80)>>1] + (0xb0 -BMP_PAD); - bg_x = wecleman_txtram[(i+0xf82)>>1] + (0xb0 -BMP_PAD); + fg_x = state->txtram[(i+0xf80)>>1] + (0xb0 -BMP_PAD); + bg_x = state->txtram[(i+0xf82)>>1] + (0xb0 -BMP_PAD); k = i<<1; for (j=0; j<8; j++) { - tilemap_set_scrollx(fg_tilemap, (fg_y + k + j) & (TILEMAP_DIMY - 1), fg_x); - tilemap_set_scrollx(bg_tilemap, (bg_y + k + j) & (TILEMAP_DIMY - 1), bg_x); + tilemap_set_scrollx(state->fg_tilemap, (fg_y + k + j) & (TILEMAP_DIMY - 1), fg_x); + tilemap_set_scrollx(state->bg_tilemap, (bg_y + k + j) & (TILEMAP_DIMY - 1), bg_x); } } @@ -1070,16 +1065,16 @@ VIDEO_UPDATE ( wecleman ) get_sprite_info(screen->machine); - bitmap_fill(bitmap, cliprect, black_pen); + bitmap_fill(bitmap, cliprect, state->black_pen); /* Draw the road (lines which have priority 0x02) */ if (video_on) wecleman_draw_road(screen->machine, bitmap, cliprect, 0x02); /* Draw the background */ - if (video_on) tilemap_draw(bitmap,cliprect, bg_tilemap, 0, 0); + if (video_on) tilemap_draw(bitmap,cliprect, state->bg_tilemap, 0, 0); // draws the cloud layer; needs work - if (cloud_visible) + if (state->cloud_visible) { /* palette hacks! */ ((pen_t *)mrct)[0] = ((pen_t *)mrct)[0x40] = ((pen_t *)mrct)[0x200] = ((pen_t *)mrct)[0x205]; @@ -1088,32 +1083,32 @@ VIDEO_UPDATE ( wecleman ) draw_cloud( bitmap, screen->machine->gfx[0], - wecleman_pageram+0x1800, + state->pageram+0x1800, BMP_PAD, BMP_PAD, 41, 20, cloud_sx, cloud_sy, 6, 5, - cloud_blend/BLEND_STEPS, 0); + state->cloud_blend/BLEND_STEPS, 0); - cloud_blend += cloud_ds; + state->cloud_blend += state->cloud_ds; - if (cloud_blend < BLEND_MIN) - { cloud_blend = BLEND_MIN; cloud_ds = 0; *wecleman_videostatus |= 1; } - else if (cloud_blend > BLEND_MAX) - { cloud_blend = BLEND_MAX; cloud_ds = 0; cloud_visible = 0; } + if (state->cloud_blend < BLEND_MIN) + { state->cloud_blend = BLEND_MIN; state->cloud_ds = 0; *state->videostatus |= 1; } + else if (state->cloud_blend > BLEND_MAX) + { state->cloud_blend = BLEND_MAX; state->cloud_ds = 0; state->cloud_visible = 0; } } /* Draw the foreground */ - if (video_on) tilemap_draw(bitmap,cliprect, fg_tilemap, 0, 0); + if (video_on) tilemap_draw(bitmap,cliprect, state->fg_tilemap, 0, 0); /* Draw the road (lines which have priority 0x04) */ if (video_on) wecleman_draw_road(screen->machine, bitmap,cliprect, 0x04); /* Draw the sprites */ - if (video_on) sprite_draw(bitmap,cliprect); + if (video_on) sprite_draw(screen->machine, bitmap,cliprect); /* Draw the text layer */ - if (video_on) tilemap_draw(bitmap,cliprect, txt_tilemap, 0, 0); + if (video_on) tilemap_draw(bitmap,cliprect, state->txt_tilemap, 0, 0); return 0; } @@ -1123,17 +1118,18 @@ VIDEO_UPDATE ( wecleman ) VIDEO_UPDATE( hotchase ) { + wecleman_state *state = screen->machine->driver_data(); device_t *k051316_1 = screen->machine->device("k051316_1"); device_t *k051316_2 = screen->machine->device("k051316_2"); int video_on; - video_on = wecleman_irqctrl & 0x40; + video_on = state->irqctrl & 0x40; - set_led_status(screen->machine, 0, wecleman_selected_ip & 0x04); // Start lamp + set_led_status(screen->machine, 0, state->selected_ip & 0x04); // Start lamp get_sprite_info(screen->machine); - bitmap_fill(bitmap, cliprect, black_pen); + bitmap_fill(bitmap, cliprect, state->black_pen); /* Draw the background */ if (video_on) @@ -1145,7 +1141,7 @@ VIDEO_UPDATE( hotchase ) /* Draw the sprites */ if (video_on) - sprite_draw(bitmap,cliprect); + sprite_draw(screen->machine, bitmap,cliprect); /* Draw the foreground (text) */ if (video_on)