updated MegaPlay and MegaTech to use modern SMS VDP. [Fabio Priuli]

with this, it was finally possible to remove the other outdated (& non-device) 
implementation which was lurking inside segamsys.c 
also, MESS at last compiles without the need of megatech.c
This commit is contained in:
Fabio Priuli 2014-03-25 22:06:18 +00:00
parent 5a8dee9023
commit bd8f99ea2d
6 changed files with 59 additions and 1092 deletions

1
.gitattributes vendored
View File

@ -6584,7 +6584,6 @@ src/mame/machine/segag80.c svneol=native#text/plain
src/mame/machine/segag80.h svneol=native#text/plain
src/mame/machine/segaic16.c svneol=native#text/plain
src/mame/machine/segaic16.h svneol=native#text/plain
src/mame/machine/segamsys.c svneol=native#text/plain
src/mame/machine/segas32.c svneol=native#text/plain
src/mame/machine/seibuspi.c svneol=native#text/plain
src/mame/machine/seibuspi.h svneol=native#text/plain

View File

@ -537,47 +537,69 @@ static ADDRESS_MAP_START( megaplay_bios_map, AS_PROGRAM, 8, mplay_state )
AM_RANGE(0x8000, 0xffff) AM_READWRITE(bank_r, bank_w)
ADDRESS_MAP_END
/* basically from src/drivers/segasyse.c */
READ8_MEMBER(mplay_state::vdp_count_r)
{
address_space &prg = m_bioscpu->space(AS_PROGRAM);
if (offset & 0x01)
return m_vdp->hcount_read(prg, offset);
else
return m_vdp->vcount_read(prg, offset);
}
static ADDRESS_MAP_START( megaplay_bios_io_map, AS_IO, 8, mplay_state )
ADDRESS_MAP_GLOBAL_MASK(0xff)
AM_RANGE(0x7f, 0x7f) AM_DEVWRITE("sn2", sn76496_device, write) /* SN76489 */
AM_RANGE(0xbe, 0xbe) AM_READWRITE(sms_vdp_data_r, sms_vdp_data_w) /* VDP */
AM_RANGE(0xbf, 0xbf) AM_READWRITE(sms_vdp_ctrl_r, sms_vdp_ctrl_w) /* VDP */
AM_RANGE(0x7f, 0x7f) AM_DEVWRITE("sn2", sn76496_device, write)
AM_RANGE(0x40, 0x41) AM_MIRROR(0x3e) AM_READ(vdp_count_r)
AM_RANGE(0x80, 0x80) AM_MIRROR(0x3e) AM_DEVREADWRITE("gen_vdp", sega315_5124_device, vram_read, vram_write)
AM_RANGE(0x81, 0x81) AM_MIRROR(0x3e) AM_DEVREADWRITE("gen_vdp", sega315_5124_device, register_read, register_write)
ADDRESS_MAP_END
VIDEO_START_MEMBER(mplay_state,megplay)
{
//printf("megplay vs\n");
VIDEO_START_CALL_MEMBER(megadriv);
}
UINT32 mplay_state::screen_update_megplay(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
{
//printf("megplay vu\n");
screen_update_megadriv(screen,bitmap,cliprect);
screen_update_megaplay_bios(screen,bitmap,cliprect);
screen_update_megadriv(screen, bitmap, cliprect);
// m_vdp->screen_update(screen, bitmap, cliprect);
// overlay, only drawn for pixels != 0
for (int y = 0; y < 224; y++)
{
UINT32* lineptr = &bitmap.pix32(y, 0);
UINT32* srcptr = &m_vdp->get_bitmap().pix32(y + SEGA315_5124_TBORDER_START + SEGA315_5124_NTSC_224_TBORDER_HEIGHT);
for (int x = 0; x < SEGA315_5124_WIDTH; x++)
{
UINT32 src = srcptr[x] & 0xffffff;
if (src)
lineptr[x] = src;
}
}
return 0;
}
MACHINE_RESET_MEMBER(mplay_state,megaplay)
{
m_bios_mode = MP_ROM;
m_mp_bios_bank_addr = 0;
m_readpos = 1;
MACHINE_RESET_CALL_MEMBER(megadriv);
MACHINE_RESET_CALL_MEMBER(megaplay_bios);
}
void mplay_state::screen_eof_megaplay(screen_device &screen, bool state)
WRITE_LINE_MEMBER( mplay_state::bios_int_callback )
{
screen_eof_megadriv(screen,state);
screen_eof_megaplay_bios(screen,state);
m_bioscpu->set_input_line(0, state);
}
static const sega315_5124_interface bios_vdp_intf =
{
false,
DEVCB_DRIVER_LINE_MEMBER(mplay_state, bios_int_callback),
DEVCB_NULL,
};
static MACHINE_CONFIG_START( megaplay, mplay_state )
/* basic machine hardware */
MCFG_FRAGMENT_ADD(md_ntsc)
@ -588,8 +610,6 @@ static MACHINE_CONFIG_START( megaplay, mplay_state )
MCFG_CPU_PROGRAM_MAP(megaplay_bios_map)
MCFG_CPU_IO_MAP(megaplay_bios_io_map)
MCFG_MACHINE_RESET_OVERRIDE(mplay_state, megaplay )
MCFG_QUANTUM_TIME(attotime::from_hz(6000))
MCFG_SOUND_ADD("sn2", SN76496, MASTER_CLOCK/15)
@ -597,10 +617,19 @@ static MACHINE_CONFIG_START( megaplay, mplay_state )
MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker",0.25) /* 3.58 MHz */
/* New update functions to handle the extra layer */
MCFG_VIDEO_START_OVERRIDE(mplay_state,megplay)
MCFG_SCREEN_MODIFY("megadriv")
MCFG_SCREEN_RAW_PARAMS(XTAL_10_738635MHz/2, \
SEGA315_5124_WIDTH , SEGA315_5124_LBORDER_START + SEGA315_5124_LBORDER_WIDTH, SEGA315_5124_LBORDER_START + SEGA315_5124_LBORDER_WIDTH + 256, \
SEGA315_5124_HEIGHT_NTSC, SEGA315_5124_TBORDER_START + SEGA315_5124_NTSC_224_TBORDER_HEIGHT, SEGA315_5124_TBORDER_START + SEGA315_5124_NTSC_224_TBORDER_HEIGHT + 224)
MCFG_SCREEN_UPDATE_DRIVER(mplay_state, screen_update_megplay)
MCFG_SCREEN_VBLANK_DRIVER(mplay_state, screen_eof_megaplay)
MCFG_DEVICE_REMOVE("gen_vdp")
MCFG_DEVICE_ADD("gen_vdp", SEGA_GEN_VDP, 0)
MCFG_DEVICE_CONFIG( bios_vdp_intf )
MCFG_VIDEO_SET_SCREEN("megadriv")
sega_genesis_vdp_device::set_genesis_vdp_sndirqline_callback(*device, DEVCB2_WRITELINE(md_base_state, genesis_vdp_sndirqline_callback_genesis_z80));
sega_genesis_vdp_device::set_genesis_vdp_lv6irqline_callback(*device, DEVCB2_WRITELINE(md_base_state, genesis_vdp_lv6irqline_callback_genesis_68k));
sega_genesis_vdp_device::set_genesis_vdp_lv4irqline_callback(*device, DEVCB2_WRITELINE(md_base_state, genesis_vdp_lv4irqline_callback_genesis_68k));
MACHINE_CONFIG_END
@ -820,8 +849,6 @@ DRIVER_INIT_MEMBER(mplay_state,megaplay)
/* instead of a RAM mirror the 68k sees the extra ram of the 2nd z80 too */
m_maincpu->space(AS_PROGRAM).install_readwrite_handler(0xa02000, 0xa03fff, read16_delegate(FUNC(mplay_state::megadriv_68k_read_z80_extra_ram),this), write16_delegate(FUNC(mplay_state::megadriv_68k_write_z80_extra_ram),this));
init_megaplay_legacy_overlay();
}
/*

View File

@ -285,106 +285,11 @@ public:
};
class segamsys_state : public md_base_state
{
public:
segamsys_state(const machine_config &mconfig, device_type type, const char *tag)
: md_base_state(mconfig, type, tag)
{ }
struct sms_vdp
{
UINT8 chip_id;
UINT8 cmd_pend;
UINT8 cmd_part1;
UINT8 cmd_part2;
UINT16 addr_reg;
UINT8 cmd_reg;
UINT8 regs[0x10];
UINT8 readbuf;
UINT8* vram;
UINT8* cram;
UINT8 writemode;
bitmap_rgb32* r_bitmap;
UINT8* tile_renderline;
UINT8* sprite_renderline;
UINT8 sprite_collision;
UINT8 sprite_overflow;
UINT8 yscroll;
UINT8 hint_counter;
UINT8 frame_irq_pending;
UINT8 line_irq_pending;
UINT8 vdp_type;
UINT8 gg_cram_latch; // gamegear specific.
/* below are MAME specific, to make things easier */
UINT8 screen_mode;
UINT8 is_pal;
int sms_scanline_counter;
int sms_total_scanlines;
int sms_framerate;
emu_timer* sms_scanline_timer;
UINT32* cram_mamecolours; // for use on RGB_DIRECT screen
int (*set_irq)(running_machine &machine, int state);
};
UINT32 screen_update_megaplay_bios(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
UINT32 screen_update_megatech_sms(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
void init_megaplay_legacy_overlay();
DECLARE_MACHINE_RESET(megaplay_bios);
void screen_eof_megaplay_bios(screen_device &screen, bool state);
DECLARE_READ8_MEMBER( sms_vcounter_r );
DECLARE_READ8_MEMBER( sms_vdp_data_r );
DECLARE_WRITE8_MEMBER( sms_vdp_data_w );
DECLARE_READ8_MEMBER( sms_vdp_ctrl_r );
DECLARE_WRITE8_MEMBER( sms_vdp_ctrl_w );
private:
UINT8* vdp1_vram_bank0;
UINT8* vdp1_vram_bank1;
struct sms_vdp *vdp1;
struct sms_vdp *md_sms_vdp;
static int sms_vdp_null_irq_callback(running_machine &machine, int status);
static int sms_vdp_cpu1_irq_callback(running_machine &machine, int status);
static int sms_vdp_cpu2_irq_callback(running_machine &machine, int status);
void *start_vdp(int type);
UINT8 vcounter_r(struct sms_vdp *chip);
UINT8 vdp_data_r(struct sms_vdp *chip);
void vdp_data_w(address_space &space, UINT8 data, struct sms_vdp* chip);
UINT8 vdp_ctrl_r(address_space &space, struct sms_vdp *chip);
void vdp_update_code_addr_regs(struct sms_vdp *chip);
void vdp_set_register(struct sms_vdp *chip);
void vdp_ctrl_w(address_space &space, UINT8 data, struct sms_vdp *chip);
void draw_tile_line(int drawxpos, int tileline, UINT16 tiledata, UINT8* linebuf, struct sms_vdp* chip);
void sms_render_spriteline(int scanline, struct sms_vdp* chip);
void sms_render_tileline(int scanline, struct sms_vdp* chip);
void sms_copy_to_renderbuffer(int scanline, struct sms_vdp* chip);
void sms_draw_scanline(int scanline, struct sms_vdp* chip);
TIMER_CALLBACK_MEMBER( sms_scanline_timer_callback );
void end_of_frame(screen_device &screen, struct sms_vdp *chip);
READ8_MEMBER( sms_z80_unmapped_port_r );
WRITE8_MEMBER( sms_z80_unmapped_port_w );
READ8_MEMBER(sms_z80_unmapped_r );
WRITE8_MEMBER( sms_z80_unmapped_w );
};
class mplay_state : public segamsys_state
class mplay_state : public md_base_state
{
public:
mplay_state(const machine_config &mconfig, device_type type, const char *tag)
: segamsys_state(mconfig, type, tag),
: md_base_state(mconfig, type, tag),
m_ic3_ram(*this, "ic3_ram"),
m_vdp1(*this, "vdp1"),
m_bioscpu(*this, "mtbios")
@ -410,7 +315,8 @@ public:
required_device<cpu_device> m_bioscpu;
UINT8* m_ic37_ram;
UINT16 *m_ic36_ram;
DECLARE_WRITE_LINE_MEMBER( int_callback );
DECLARE_WRITE_LINE_MEMBER( bios_int_callback );
READ8_MEMBER(vdp_count_r);
DECLARE_DRIVER_INIT(megaplay);
DECLARE_VIDEO_START(megplay);
DECLARE_MACHINE_RESET(megaplay);
@ -440,7 +346,7 @@ public:
DECLARE_WRITE16_MEMBER( megadriv_68k_write_z80_extra_ram );
};
class mtech_state : public segamsys_state
class mtech_state : public md_base_state
{
public:
enum
@ -450,7 +356,7 @@ public:
};
mtech_state(const machine_config &mconfig, device_type type, const char *tag)
: segamsys_state(mconfig, type, tag),
: md_base_state(mconfig, type, tag),
m_vdp1(*this, "vdp1"),
m_bioscpu(*this, "mtbios")
{ }

View File

@ -1,963 +0,0 @@
/*
SMS code from HazeMD
- used by Syetem E
- Megatech / Megaplay
this contains common code to support those systems
(not currently very good / accurate, should be rewritten)
*/
#include "emu.h"
#include "cpu/z80/z80.h"
#include "sound/sn76496.h"
#include "machine/mc8123.h"
#include "machine/segacrpt.h"
#include "includes/megadriv.h"
/* All Accesses to VRAM go through here for safety */
#define SMS_VDP_VRAM(address) chip->vram[(address)&0x3fff]
/* Precalculated tables for H/V counters. Note the position the counter 'jumps' is marked with with
an empty comment */
static const UINT8 hc_256[] =
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0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xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6,
0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6,
0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6,
0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
};
static const UINT8 vc_pal_240[] =
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
0x80, 0x81, 0x82, 0x83, 0x84,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0xfe, 0xff,
};
static const struct
{
UINT8 sms2_name[40];
int sms2_valid;
int sms2_height;
int sms2_tilemap_height;
const UINT8* sms_vcounter_table;
const UINT8* sms_hcounter_table;
} sms_mode_table[] =
{
/* NTSC Modes */
{ "Graphic 1 (NTSC)", 0, 192, 224, vc_ntsc_192, hc_256 },
{ "Text (NTSC)", 0, 192, 224, vc_ntsc_192, hc_256 },
{ "Graphic 2 (NTSC)", 0, 192, 224, vc_ntsc_192, hc_256 },
{ "Mode 1+2 (NTSC)" , 0, 192, 224, vc_ntsc_192, hc_256 },
{ "Multicolor (NTSC)", 0, 192, 224, vc_ntsc_192, hc_256 },
{ "Mode 1+3 (NTSC)", 0, 192, 224, vc_ntsc_192, hc_256 },
{ "Mode 2+3 (NTSC)", 0, 192, 224, vc_ntsc_192, hc_256 },
{ "Mode 1+2+3 (NTSC)", 0, 192, 224, vc_ntsc_192, hc_256 },
{ "Mode 4 (NTSC)", 1, 192, 224, vc_ntsc_192, hc_256 },
{ "Invalid Text (NTSC)", 0, 192, 224, vc_ntsc_192, hc_256 },
{ "Mode 4 (NTSC)", 1, 192, 224, vc_ntsc_192, hc_256 },
{ "Mode 4 (224-line) (NTSC)", 1, 224, 256, vc_ntsc_224, hc_256 },
{ "Mode 4 (NTSC)", 1, 192, 224, vc_ntsc_192, hc_256 },
{ "Invalid Text (NTSC)", 0, 192, 224, vc_ntsc_192, hc_256 },
{ "Mode 4 (240-line) (NTSC)", 1, 240, 256, vc_ntsc_240, hc_256 },
{ "Mode 4 (NTSC)", 1, 192, 244, vc_ntsc_192, hc_256 },
/* Pal Modes (different Vcounter) */
{ "Graphic 1 (PAL)", 0, 192, 224, vc_pal_192, hc_256 },
{ "Text (PAL)", 0, 192, 224, vc_pal_192, hc_256 },
{ "Graphic 2 (PAL)", 0, 192, 224, vc_pal_192, hc_256 },
{ "Mode 1+2 (PAL)" , 0, 192, 224, vc_pal_192, hc_256 },
{ "Multicolor (PAL)", 0, 192, 224, vc_pal_192, hc_256 },
{ "Mode 1+3 (PAL)", 0, 192, 224, vc_pal_192, hc_256 },
{ "Mode 2+3 (PAL)", 0, 192, 224, vc_pal_192, hc_256 },
{ "Mode 1+2+3 (PAL)", 0, 192, 224, vc_pal_192, hc_256 },
{ "Mode 4 (PAL)", 1, 192, 224, vc_pal_192, hc_256 },
{ "Invalid Text (PAL)", 0, 192, 224, vc_pal_192, hc_256 },
{ "Mode 4 (PAL)", 1, 192, 224, vc_pal_192, hc_256 },
{ "Mode 4 (224-line) (PAL)", 1, 224, 256, vc_pal_224, hc_256 },
{ "Mode 4 (PAL)", 1, 192, 224, vc_pal_192, hc_256 },
{ "Invalid Text (PAL)", 0, 192, 224, vc_pal_192, hc_256 },
{ "Mode 4 (240-line) (PAL)", 1, 240, 256, vc_pal_240, hc_256 },
{ "Mode 4 (PAL)", 1, 192, 244, vc_pal_192, hc_256 }
};
enum
{
SMS_VDP = 0, // SMS1 VDP
SMS2_VDP = 1, // SMS2 VDP, or Game Gear VDP running in SMS2 Mode
GEN_VDP = 3 // Genesis VDP running in SMS2 Mode
};
int segamsys_state::sms_vdp_null_irq_callback(running_machine &machine, int status)
{
return -1;
}
int segamsys_state::sms_vdp_cpu1_irq_callback(running_machine &machine, int status)
{
if (status == 1)
machine.device("genesis_snd_z80")->execute().set_input_line(0, HOLD_LINE);
else
machine.device("genesis_snd_z80")->execute().set_input_line(0, CLEAR_LINE);
return 0;
}
int segamsys_state::sms_vdp_cpu2_irq_callback(running_machine &machine, int status)
{
if (status == 1)
machine.device("mtbios")->execute().set_input_line(0, HOLD_LINE);
else
machine.device("mtbios")->execute().set_input_line(0, CLEAR_LINE);
return 0;
}
void *segamsys_state::start_vdp(int type)
{
struct sms_vdp *chip;
chip = auto_alloc_clear(machine(), struct sms_vdp);
chip->vdp_type = type;
chip->set_irq = segamsys_state::sms_vdp_null_irq_callback;
chip->cmd_pend = 0;
chip->cmd_part1 = 0;
chip->cmd_part2 = 0;
chip->addr_reg = 0;
chip->cmd_reg = 0;
chip->regs[0x0] = 0x06; // mode 4
chip->regs[0x1] = 0x18; // mode 4
chip->regs[0x2] = 0;
chip->regs[0x3] = 0;
chip->regs[0x4] = 0;
chip->regs[0x5] = 0;
chip->regs[0x6] = 0;
chip->regs[0x7] = 0;
chip->regs[0x8] = 0;
chip->regs[0x9] = 0;
chip->regs[0xa] = 0;
/* b-f don't matter */
chip->readbuf = 0;
chip->vram = auto_alloc_array_clear(machine(), UINT8, 0x4000);
//printf("%d\n", (*chip->set_irq)(machine, 200));
chip->cram = auto_alloc_array_clear(machine(), UINT8, 0x0020);
chip->cram_mamecolours = auto_alloc_array(machine(), UINT32, 0x0040/2);
chip->tile_renderline = auto_alloc_array(machine(), UINT8, 256+8);
memset(chip->tile_renderline,0x00,256+8);
chip->sprite_renderline = auto_alloc_array(machine(), UINT8, 256+32);
memset(chip->sprite_renderline,0x00,256+32);
chip->writemode = 0;
chip->r_bitmap = auto_bitmap_rgb32_alloc(machine(), 256, 256);
chip->sms_scanline_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(segamsys_state::sms_scanline_timer_callback),this), chip);
return chip;
}
UINT8 segamsys_state::vcounter_r(struct sms_vdp *chip)
{
// return vc_pal_224[sms_scanline_counter%(sizeof vc_pal_224)];
UINT8 retvalue;
int scanline = chip->sms_scanline_counter%chip->sms_total_scanlines;
retvalue = sms_mode_table[chip->screen_mode].sms_vcounter_table[scanline];
return retvalue;
//printf("retvalue %d\n";
}
UINT8 segamsys_state::vdp_data_r(struct sms_vdp *chip)
{
UINT8 retdata = chip->readbuf;
chip->readbuf = SMS_VDP_VRAM(chip->addr_reg);
chip->addr_reg++; chip->addr_reg&=0x3fff;
return retdata;
}
void segamsys_state::vdp_data_w(address_space &space, UINT8 data, struct sms_vdp* chip)
{
/* data writes clear the pending flag */
chip->cmd_pend = 0;
if (chip->writemode==0)
{ /* Write to VRAM */
SMS_VDP_VRAM(chip->addr_reg)=data;
chip->addr_reg++; chip->addr_reg&=0x3fff;
chip->readbuf = data; // quirk of the VDP
}
else if (chip->writemode==1)
{
chip->cram[chip->addr_reg&0x1f]=data;
/* Set Colour */
{
UINT8 r,g,b;
r = (data & 0x03)>>0;
g = (data & 0x0c)>>2;
b = (data & 0x30)>>4;
rgb_t rgb = rgb_t(pal2bit(r), pal2bit(g), pal2bit(b));
//m_palette->set_pen_color(chip->addr_reg&0x1f, rgb);
chip->cram_mamecolours[chip->addr_reg&0x1f]=rgb;
}
chip->addr_reg++; chip->addr_reg&=0x3fff;
chip->readbuf = data; // quirk of the VDP
}
}
UINT8 segamsys_state::vdp_ctrl_r(address_space &space, struct sms_vdp *chip)
{
UINT8 retvalue;
retvalue = (chip->frame_irq_pending<<7) |
(chip->sprite_overflow<<6) |
(chip->sprite_collision<<5);
chip->cmd_pend = 0;
chip->frame_irq_pending = 0;
chip->line_irq_pending = 0;
chip->sprite_collision = 0;
chip->sprite_overflow = 0;
(chip->set_irq)(machine(), 0); // clear IRQ;
return retvalue;
}
/* check me */
void segamsys_state::vdp_update_code_addr_regs(struct sms_vdp *chip)
{
chip->addr_reg = ((chip->cmd_part2&0x3f)<<8) | chip->cmd_part1;
chip->cmd_reg = (chip->cmd_part2&0xc0)>>6;
}
void segamsys_state::vdp_set_register(struct sms_vdp *chip)
{
UINT8 reg = chip->cmd_part2&0x0f;
chip->regs[reg] = chip->cmd_part1;
//if(reg==0) printf("setting reg 0 to %02x\n",chip->cmd_part1);
//if (reg>0xa) printf("Invalid register write to register %01x\n",reg);
if(reg==1)
{
if ((chip->regs[0x1]&0x20) && chip->frame_irq_pending)
{
(chip->set_irq)(machine(), 1); // set IRQ;
}
else
{
(chip->set_irq)(machine(), 0); // clear IRQ;
}
}
if(reg==0)
{
if ((chip->regs[0x0]&0x10) && chip->line_irq_pending)
{
(chip->set_irq)(machine(), 1); // set IRQ;
}
else
{
(chip->set_irq)(machine(), 0); // clear IRQ;
}
}
// printf("VDP: setting register %01x to %02x\n",reg, chip->cmd_part1);
}
void segamsys_state::vdp_ctrl_w(address_space &space, UINT8 data, struct sms_vdp *chip)
{
if (chip->cmd_pend)
{ /* Part 2 of a command word write */
chip->cmd_pend = 0;
chip->cmd_part2 = data;
vdp_update_code_addr_regs(chip);
switch (chip->cmd_reg)
{
case 0x0: /* VRAM read mode */
chip->readbuf = SMS_VDP_VRAM(chip->addr_reg);
chip->addr_reg++; chip->addr_reg&=0x3fff;
chip->writemode = 0;
break;
case 0x1: /* VRAM write mode */
chip->writemode = 0;
break;
case 0x2: /* REG setting */
vdp_set_register(chip);
chip->writemode = 0;
break;
case 0x3: /* CRAM write mode */
chip->writemode = 1;
break;
}
}
else
{ /* Part 1 of a command word write */
chip->cmd_pend = 1;
chip->cmd_part1 = data;
vdp_update_code_addr_regs(chip);
}
}
/* Read / Write Handlers - call other functions */
READ8_MEMBER(segamsys_state::sms_vcounter_r )
{
return vcounter_r(vdp1);
}
READ8_MEMBER(segamsys_state::sms_vdp_data_r )
{
return vdp_data_r(vdp1);
}
WRITE8_MEMBER(segamsys_state::sms_vdp_data_w )
{
vdp_data_w(space, data, vdp1);
}
READ8_MEMBER(segamsys_state::sms_vdp_ctrl_r )
{
return vdp_ctrl_r(space, vdp1);
}
WRITE8_MEMBER(segamsys_state::sms_vdp_ctrl_w )
{
vdp_ctrl_w(space, data, vdp1);
}
void segamsys_state::draw_tile_line(int drawxpos, int tileline, UINT16 tiledata, UINT8* linebuf, struct sms_vdp* chip)
{
int xx;
UINT32 gfxdata;
UINT16 gfx_base = (tiledata & 0x01ff)<<5;
UINT8 flipx = (tiledata & 0x0200)>>9;
UINT8 flipy = (tiledata & 0x0400)>>10;
UINT8 pal = (tiledata & 0x0800)>>11;
UINT8 pri = (tiledata & 0x1000)>>12;
if (flipy)
{
gfx_base+=(7-tileline)*4;
}
else
{
gfx_base+=tileline*4;
}
gfxdata = (SMS_VDP_VRAM(gfx_base)<<24)|(SMS_VDP_VRAM(gfx_base+1)<<16)|(SMS_VDP_VRAM(gfx_base+2)<<8)|(SMS_VDP_VRAM(gfx_base+3)<<0);
for (xx=0;xx<8;xx++)
{
UINT8 pixel;
if (flipx)
{
pixel = (( (gfxdata>>(0+xx) ) &0x00000001)<<3)|
(( (gfxdata>>(8+xx) ) &0x00000001)<<2)|
(( (gfxdata>>(16+xx) ) &0x00000001)<<1)|
(( (gfxdata>>(24+xx) ) &0x00000001)<<0);
}
else
{
pixel = (( (gfxdata>>(7-xx) ) &0x00000001)<<3)|
(( (gfxdata>>(15-xx) ) &0x00000001)<<2)|
(( (gfxdata>>(23-xx) ) &0x00000001)<<1)|
(( (gfxdata>>(31-xx) ) &0x00000001)<<0);
}
pixel += pal*0x10;
if (!pri) linebuf[drawxpos+xx] = pixel;
else
{
if (pixel&0xf)
linebuf[drawxpos+xx] = pixel|0x80;
else
linebuf[drawxpos+xx] = pixel;
}
}
}
void segamsys_state::sms_render_spriteline(int scanline, struct sms_vdp* chip)
{
int spritenum;
int height = 8;
int width = 8;
int max_sprites = 8;
int visible_line = 0;
UINT16 table_base = (chip->regs[0x5]&0x7e) << 7;
UINT8 pattern_bit = (chip->regs[0x6]&0x04) >> 2; // high bit of the tile # (because spriteram can only contain an 8-bit tile #)
memset(chip->sprite_renderline, 0, 256+32);
for (spritenum = 0;spritenum<64;spritenum++)
{
int xpos,ypos,num;
/*
00: yyyyyyyyyyyyyyyy
10: yyyyyyyyyyyyyyyy
20: yyyyyyyyyyyyyyyy
30: yyyyyyyyyyyyyyyy
40: ????????????????
50: ????????????????
60: ????????????????
70: ????????????????
80: xnxnxnxnxnxnxnxn
90: xnxnxnxnxnxnxnxn
A0: xnxnxnxnxnxnxnxn
B0: xnxnxnxnxnxnxnxn
C0: xnxnxnxnxnxnxnxn
D0: xnxnxnxnxnxnxnxn
E0: xnxnxnxnxnxnxnxn
F0: xnxnxnxnxnxnxnxn
*/
ypos = SMS_VDP_VRAM(table_base+spritenum);
xpos = SMS_VDP_VRAM(table_base+0x80+spritenum*2+0);
num = SMS_VDP_VRAM(table_base+0x80+spritenum*2+1)|(pattern_bit<<8);
if (chip->regs[0x1]&0x2)
{
num &=0x1fe;
height=16;
}
else height = 8;
xpos+=16; // allow room either side for clipping (avoids xdrawpos of -8 if bit below is set)
if (chip->regs[0x0]&0x08) xpos-=8;
if ((sms_mode_table[chip->screen_mode].sms2_height)==192)
{
if (ypos == 0xd0)
return;
}
ypos++;
num <<= 5;
//num+=((scanline-ypos)&0x7)*4;
visible_line = 0;
if (ypos<=scanline && ypos+height>scanline)
{
visible_line = 1;
num+=((scanline-ypos)&(height-1))*4;
}
else if (ypos+height>0x100)
{
if (scanline< ypos+height-0x100)
{
visible_line = 1;
num+=((scanline-ypos)&(height-1))*4;
}
}
if (visible_line)
{
int xx;
UINT32 gfxdata;
gfxdata = (SMS_VDP_VRAM(num&0x3fff)<<24)|(SMS_VDP_VRAM((num+1)&0x3fff)<<16)|(SMS_VDP_VRAM((num+2)&0x3fff)<<8)|(SMS_VDP_VRAM((num+3)&0x3fff)<<0);
for (xx=0;xx<8;xx++)
{
UINT8 pixel = (( (gfxdata>>(0+xx) ) &0x00000001)<<3)|
(( (gfxdata>>(8+xx) ) &0x00000001)<<2)|
(( (gfxdata>>(16+xx) ) &0x00000001)<<1)|
(( (gfxdata>>(24+xx) ) &0x00000001)<<0);
if (pixel)
{
if (!chip->sprite_renderline[xpos+((width-1)-xx)])
{
chip->sprite_renderline[xpos+((width-1)-xx)] = pixel;
}
else
{
chip->sprite_collision = 1;
}
}
}
max_sprites--;
if (max_sprites==0)
{
chip->sprite_overflow = 1;
return;
}
}
}
}
void segamsys_state::sms_render_tileline(int scanline, struct sms_vdp* chip)
{
int column = 0;
int count = 32;
int drawxpos;
UINT8 xscroll = chip->regs[0x8];
UINT8 yscroll = chip->yscroll;
UINT16 table_base = (chip->regs[0x2]&0x0e)<<10;
UINT16 our_base;
UINT8 our_line = (scanline+yscroll) & 0x7;
/* In 224 and 240 line modes the table base is different */
if ((sms_mode_table[chip->screen_mode].sms2_height)!=192)
{
table_base &=0x3700; table_base|=0x700;
}
if ((chip->regs[0x0]&0x40) && scanline < 16)
{
xscroll = 0;
}
// xscroll = 0;
// table_base -= 0x0100;
our_base = table_base+(((scanline+yscroll)%sms_mode_table[chip->screen_mode].sms2_tilemap_height)>>3)*64;// + (yscroll>>3)*32;
our_base &=0x3fff;
memset(chip->tile_renderline, (chip->regs[0x7]&0x0f)+0x10, 256+8);
drawxpos = xscroll&0x7;
column = 32-(xscroll>>3);
do
{
UINT16 tiledata = (SMS_VDP_VRAM((our_base+(column&0x1f)*2+1)&0x3fff) << 8) |
(SMS_VDP_VRAM((our_base+(column&0x1f)*2+0)&0x3fff) << 0);
// UINT16 pattern = ((column+((scanline>>3)*32)) & 0x01ff)<<5;
draw_tile_line(drawxpos, our_line, tiledata, chip->tile_renderline, chip);
drawxpos+=8;
column++;
column&=0x1f;
count--;
} while (count);
}
void segamsys_state::sms_copy_to_renderbuffer(int scanline, struct sms_vdp* chip)
{
int x;
UINT32* lineptr = &chip->r_bitmap->pix32(scanline);
for (x=0;x<256;x++)
{
UINT8 dat = chip->tile_renderline[x];
UINT8 col;
col = (chip->regs[0x7]&0x0f)+0x10;
lineptr[x] = chip->cram_mamecolours[col];
if ((x<8 && (chip->regs[0x0]&0x20)) || !(chip->regs[0x1]&0x40))
continue;
if (!(dat & 0x80))
{
lineptr[x] = chip->cram_mamecolours[dat&0x1f];
if ((dat&0xf)==0x0) lineptr[x]|=0x80000000;
}
if (chip->sprite_renderline[x+16])
{
lineptr[x] = chip->cram_mamecolours[chip->sprite_renderline[x+16]+0x10];
}
if (dat & 0x80)
{
lineptr[x] = chip->cram_mamecolours[dat&0x1f];
if ((dat&0xf)==0x0) lineptr[x]|=0x80000000;
}
}
}
void segamsys_state::sms_draw_scanline(int scanline, struct sms_vdp* chip)
{
if (scanline>=0 && scanline<sms_mode_table[chip->screen_mode].sms2_height)
{
sms_render_spriteline(scanline, chip);
sms_render_tileline(scanline, chip);
sms_copy_to_renderbuffer(scanline, chip);
}
}
TIMER_CALLBACK_MEMBER( segamsys_state::sms_scanline_timer_callback )
{
/* This function is called at the very start of every scanline starting at the very
top-left of the screen. The first scanline is scanline 0 (we set scanline to -1 in
VIDEO_EOF) */
/* Compensate for some rounding errors
When the counter reaches 314 (or whatever the max lines is) we should have reached the
end of the frame, however due to rounding errors in the timer calculation we're not quite
there. Let's assume we are still in the previous scanline for now.
The position to get the H position also has to compensate for a few errors
*/
// printf("num %d\n",num );
struct sms_vdp *chip = (struct sms_vdp *)ptr;
if (chip->sms_scanline_counter<(chip->sms_total_scanlines-1))
{
chip->sms_scanline_counter++;
chip->sms_scanline_timer->adjust(attotime::from_hz(chip->sms_framerate * chip->sms_total_scanlines));
if (chip->sms_scanline_counter>sms_mode_table[chip->screen_mode].sms2_height)
{
chip->hint_counter=chip->regs[0xa];
}
if (chip->sms_scanline_counter==0)
{
chip->hint_counter=chip->regs[0xa];
}
if (chip->sms_scanline_counter<=192)
{
chip->hint_counter--;
if (chip->hint_counter==0xff)
{
//if (chip->chip_id==2) printf("irq triggerd on scanline %d %d\n", vdp1->sms_scanline_counter, vdp2->sms_scanline_counter);
chip->line_irq_pending = 1;
chip->hint_counter=chip->regs[0xa];
if (chip->regs[0x0]&0x10)
{
(chip->set_irq)(machine(), 1); // set IRQ;
}
else
{
(chip->set_irq)(machine(), 0); // clear IRQ;
}
}
}
sms_draw_scanline(chip->sms_scanline_counter, chip);
//if(sms_scanline_counter==0) chip->sprite_collision = 0;
if (chip->sms_scanline_counter==sms_mode_table[chip->screen_mode].sms2_height+1 )
{
chip->frame_irq_pending = 1;
if (chip->regs[0x1]&0x20)
{
(chip->set_irq)(machine(), 1); // set IRQ;
}
else
{
(chip->set_irq)(machine(), 0); // clear IRQ;
}
}
}
else
{ /* if we're called passed the total number of scanlines then assume we're still on the last one.
this can happen due to rounding errors */
chip->sms_scanline_counter = chip->sms_total_scanlines-1;
}
}
/*
Register $00 - Mode Control No. 1
D7 - 1= Disable vertical scrolling for columns 24-31
D6 - 1= Disable horizontal scrolling for rows 0-1
D5 - 1= Mask column 0 with overscan color from register #7
D4 - (IE1) 1= Line interrupt enable
D3 - (EC) 1= Shift sprites left by 8 pixels
D2 - (M4) 1= Use Mode 4, 0= Use TMS9918 modes (selected with M1, M2, M3)
D1 - (M2) Must be 1 for M1/M3 to change screen height in Mode 4.
Otherwise has no effect.
D0 - 1= No sync, display is monochrome, 0= Normal display
Bits 0 and 5 have no effect on the GameGear in either mode, while bit 6
has no effect in GG mode but works normally in SMS mode.
*/
/*
Register $01 - Mode Control No. 2
D7 - No effect
D6 - (BLK) 1= Display visible, 0= display blanked.
D5 - (IE0) 1= Frame interrupt enable.
D4 - (M1) Selects 224-line screen for Mode 4 if M2=1, else has no effect.
D3 - (M3) Selects 240-line screen for Mode 4 if M2=1, else has no effect.
D2 - No effect
D1 - Sprites are 1=16x16,0=8x8 (TMS9918), Sprites are 1=8x16,0=8x8 (Mode 4)
D0 - Sprite pixels are doubled in size.
Even though some games set bit 7, it does nothing.
*/
void segamsys_state::end_of_frame(screen_device &screen, struct sms_vdp *chip)
{
UINT8 m1 = (chip->regs[0x1]&0x10)>>4;
UINT8 m2 = (chip->regs[0x0]&0x02)>>1;
UINT8 m3 = (chip->regs[0x1]&0x08)>>3;
UINT8 m4 = (chip->regs[0x0]&0x04)>>2;
UINT8 m5 = chip->is_pal;
chip->screen_mode = m1|(m2<<1)|(m3<<2)|(m4<<3)|(m5<<4);
rectangle visarea(0, 256-1, 0, sms_mode_table[chip->screen_mode].sms2_height-1);
if (chip->chip_id==3) screen.configure(256, 256, visarea, HZ_TO_ATTOSECONDS(chip->sms_framerate));
// printf("Mode: %s is ok\n", sms_mode_table[chip->screen_mode].sms2_name);
chip->sms_scanline_counter = -1;
chip->yscroll = chip->regs[0x9]; // this can't change mid-frame
chip->sms_scanline_timer->adjust(attotime::zero);
}
MACHINE_RESET_MEMBER(segamsys_state, megaplay_bios)
{
vdp1->sms_scanline_timer->adjust(attotime::zero);
}
void segamsys_state::screen_eof_megaplay_bios(screen_device &screen, bool state)
{
// rising edge
if (state)
end_of_frame(screen, vdp1);
}
UINT32 segamsys_state::screen_update_megaplay_bios(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
{
int x,y;
for (y=0;y<224;y++)
{
UINT32* lineptr = &bitmap.pix32(y+16, 32);
UINT32* srcptr = &vdp1->r_bitmap->pix32(y);
for (x=0;x<256;x++)
{
UINT32 src = srcptr[x]&0xffffff;
if (src)
lineptr[x]=src;
}
}
return 0;
}
void segamsys_state::init_megaplay_legacy_overlay()
{
vdp1 = (struct sms_vdp *)start_vdp(SMS2_VDP);
vdp1->set_irq = segamsys_state::sms_vdp_cpu2_irq_callback;
vdp1->is_pal = 0;
vdp1->sms_total_scanlines = 262;
vdp1->sms_framerate = 60;
vdp1->chip_id = 1;
vdp1_vram_bank0 = vdp1->vram;
vdp1_vram_bank1 = auto_alloc_array(machine(), UINT8, 0x4000);
}

View File

@ -1567,7 +1567,7 @@ $(MAMEOBJ)/sega.a: \
$(DRIVERS)/triforce.o \
$(DRIVERS)/puckpkmn.o \
$(DRIVERS)/segac2.o \
$(DRIVERS)/segae.o $(MACHINE)/segamsys.o \
$(DRIVERS)/segae.o \
$(DRIVERS)/shtzone.o \
$(DRIVERS)/segag80r.o $(MACHINE)/segag80.o $(AUDIO)/segag80r.o $(VIDEO)/segag80r.o \
$(DRIVERS)/segag80v.o $(AUDIO)/segag80v.o $(VIDEO)/segag80v.o \

View File

@ -807,8 +807,6 @@ $(MESSOBJ)/mame.a: \
$(MAME_MACHINE)/megacdcd.o \
$(MAME_MACHINE)/mega32x.o \
$(MAME_MACHINE)/megavdp.o \
$(MAME_MACHINE)/segamsys.o \
$(MAME_DRIVERS)/megatech.o \
$(MAME_MACHINE)/dc.o \
$(MAME_DRIVERS)/naomi.o \
$(MAME_VIDEO)/powervr2.o \