From c1459feacc7566a6a4d91ffb4426cdc4c16bb38f Mon Sep 17 00:00:00 2001 From: cam900 Date: Thu, 24 Oct 2019 12:08:02 +0900 Subject: 315_5313.cpp : Allow LCM scaling of horizontal resolution megaplay.cpp : Use LCM of support horizontal resolution in both VDPs 315_5124.cpp : Allow dividing hcounter related to using LCM --- src/devices/video/315_5124.cpp | 13 +++--- src/devices/video/315_5124.h | 3 ++ src/devices/video/315_5313.cpp | 98 +++++++++++++++++++++++++----------------- src/devices/video/315_5313.h | 4 ++ src/mame/drivers/megaplay.cpp | 23 ++++++---- 5 files changed, 87 insertions(+), 54 deletions(-) (limited to 'src') diff --git a/src/devices/video/315_5124.cpp b/src/devices/video/315_5124.cpp index 837f1af5215..15a599cf3d3 100644 --- a/src/devices/video/315_5124.cpp +++ b/src/devices/video/315_5124.cpp @@ -204,6 +204,7 @@ sega315_5124_device::sega315_5124_device(const machine_config &mconfig, device_t , device_memory_interface(mconfig, *this) , device_video_interface(mconfig, *this) , device_mixer_interface(mconfig, *this, 2) + , m_hcounter_divide(1) , m_cram_size(cram_size) , m_line_timing(line_timing) , m_palette_offset(palette_offset) @@ -361,7 +362,7 @@ u8 sega315_5124_device::vcount_read() const int active_scr_start = m_frame_timing[VERTICAL_SYNC] + m_frame_timing[TOP_BLANKING] + m_frame_timing[TOP_BORDER]; int vpos = screen().vpos(); - if (screen().hpos() < m_line_timing[VCOUNT_CHANGE_HPOS]) + if (screen_hpos() < m_line_timing[VCOUNT_CHANGE_HPOS]) { vpos--; if (vpos < 0) @@ -382,7 +383,7 @@ u8 sega315_5124_device::hcount_read() void sega315_5124_device::hcount_latch() { /* The hcount value returned by the VDP seems to be based on the previous hpos */ - int hclock = screen().hpos() - 1; + int hclock = screen_hpos() - 1; if (hclock < 0) hclock += WIDTH; @@ -677,7 +678,7 @@ void sega315_5124_device::check_pending_flags() return some position in the beginning of next line. To ensure the instruction will get updated status, here a maximum hpos is set if the timer reports no remaining time, what could also occur due to the ahead time of the timeslice. */ - int const hpos = (m_pending_flags_timer->remaining() == attotime::zero) ? (WIDTH - 1) : screen().hpos(); + int const hpos = (m_pending_flags_timer->remaining() == attotime::zero) ? (WIDTH - 1) : screen_hpos(); if ((m_pending_hint) && hpos >= m_line_timing[HINT_HPOS]) { @@ -853,11 +854,11 @@ void sega315_5124_device::control_write(u8 data) break; case 1: set_display_settings(); - if (screen().hpos() <= DISPLAY_DISABLED_HPOS) + if (screen_hpos() <= DISPLAY_DISABLED_HPOS) m_display_disabled = !BIT(m_reg[0x01], 6); break; case 8: - if (screen().hpos() <= m_line_timing[XSCROLL_HPOS]) + if (screen_hpos() <= m_line_timing[XSCROLL_HPOS]) m_reg8copy = m_reg[0x08]; } @@ -1303,7 +1304,7 @@ void sega315_5313_mode4_device::sprite_collision(int line, int sprite_col_x) // This function is been used to check for sprite collision of // the 315-5313 VDP, that occurs before the active screen is // drawn, so it must not flag a collision again when drawing. - if (screen().hpos() < m_draw_time) + if (screen_hpos() < m_draw_time) { m_pending_status |= STATUS_SPRCOL; m_pending_sprcol_x = m_line_timing[SPRCOL_BASEHPOS]; diff --git a/src/devices/video/315_5124.h b/src/devices/video/315_5124.h index f5bb3cc02f5..1836660da9b 100644 --- a/src/devices/video/315_5124.h +++ b/src/devices/video/315_5124.h @@ -55,6 +55,7 @@ public: // construction/destruction sega315_5124_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); + void set_hcounter_divide(unsigned divide) { m_hcounter_divide = divide; } void set_is_pal(bool is_pal) { m_is_pal = is_pal; } auto vblank() { return m_vblank_cb.bind(); } @@ -102,6 +103,7 @@ protected: void sega315_5124(address_map &map); + virtual int screen_hpos() { return screen().hpos() / ((m_hcounter_divide == 0) ? 1 : m_hcounter_divide); } void set_display_settings(); void set_frame_timing(); virtual void vblank_end(int vpos); @@ -130,6 +132,7 @@ protected: void draw_scanline_mode0(int *line_buffer, int line); void check_pending_flags(); + unsigned m_hcounter_divide; u8 m_reg[16]; /* All the registers */ u8 m_status; /* Status register */ u8 m_pending_status; /* Pending status flags */ diff --git a/src/devices/video/315_5313.cpp b/src/devices/video/315_5313.cpp index d664909bfae..397fcb436bd 100644 --- a/src/devices/video/315_5313.cpp +++ b/src/devices/video/315_5313.cpp @@ -153,6 +153,12 @@ static constexpr u8 line_315_5313_mode4[8] = { , 37 /* SPRCOL_BASEHPOS */ }; +static const unsigned hres[4] = { 256, 256, 320, 320 }; +static const unsigned hres_mul[4] = { 5, 5, 4, 4 }; + +inline u8 sega315_5313_device::get_hres() { return (MEGADRIVE_REG0C_RS0 | (MEGADRIVE_REG0C_RS1 << 1)) & 3; } +int sega315_5313_device::screen_hpos() { return screen().hpos() / (m_lcm_scaling ? hres_mul[get_hres()] : 1); } + #define MAX_HPOSITION 480 @@ -184,6 +190,7 @@ sega315_5313_device::sega315_5313_device(const machine_config &mconfig, const ch , m_scanline_counter(0) , m_vblank_flag(0) , m_imode(0) + , m_lcm_scaling(false) , m_visible_scanlines(0) , m_irq6_scanline(0) , m_z80irq_scanline(0) @@ -334,9 +341,9 @@ void sega315_5313_device::device_start() memset(m_palette_lookup.get(), 0x00, 0x40 * 2); if (!m_use_alt_timing) - m_render_bitmap = std::make_unique(320, 512); // allocate maximum sizes we're going to use, it's safer. + m_render_bitmap = std::make_unique(1280, 512); // allocate maximum sizes we're going to use, it's safer. else - m_render_line = std::make_unique(320); + m_render_line = std::make_unique(1280); m_render_line_raw = std::make_unique(320); @@ -348,7 +355,7 @@ void sega315_5313_device::device_start() save_pointer(NAME(m_palette_lookup), 0x40); save_pointer(NAME(m_render_line_raw), 320); if (m_use_alt_timing) - save_pointer(NAME(m_render_line), 320); + save_pointer(NAME(m_render_line), 1280); m_irq6_on_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sega315_5313_device::irq6_on_timer_callback), this)); m_irq4_on_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sega315_5313_device::irq4_on_timer_callback), this)); @@ -1234,7 +1241,7 @@ u16 sega315_5313_device::get_hposition() } else { - value4 = screen().hpos(); + value4 = screen_hpos(); } return value4; @@ -1378,7 +1385,7 @@ void sega315_5313_device::render_spriteline_to_spritebuffer(int scanline) int maxpixels = 0; u16 base_address = 0; - const int screenwidth = MEGADRIVE_REG0C_RS0 | (MEGADRIVE_REG0C_RS1 << 1); + const int screenwidth = get_hres(); switch (screenwidth & 3) { @@ -1654,14 +1661,15 @@ void sega315_5313_device::render_videoline_to_videobuffer(int scanline) int non_window_lastcol; const int screenheight = MEGADRIVE_REG01_240_LINE ? 240 : 224; struct nametable_t tile; + unsigned horz = m_lcm_scaling ? hres[get_hres()] : 320; /* Clear our Render Buffer */ - for (int x = 0; x < 320; x++) + for (int x = 0; x < horz; x++) { m_video_renderline[x] = MEGADRIVE_REG07_BGCOLOUR | 0x20000; // mark as BG } - memset(m_highpri_renderline.get(), 0, 320); + memset(m_highpri_renderline.get(), 0, horz); /* is this line enabled? */ if (!MEGADRIVE_REG01_DISP_ENABLE) @@ -1684,7 +1692,7 @@ void sega315_5313_device::render_videoline_to_videobuffer(int scanline) const u16 window_down = MEGADRIVE_REG12_WINDOW_DOWN; // const u16 window_vpos = MEGADRIVE_REG12_WINDOW_VPOS; - const int screenwidth = MEGADRIVE_REG0C_RS0 | (MEGADRIVE_REG0C_RS1 << 1); + const int screenwidth = get_hres(); switch (screenwidth) { @@ -1977,7 +1985,7 @@ void sega315_5313_device::render_videoline_to_videobuffer(int scanline) /* MEGADRIVE_REG0C_SHADOW_HIGLIGHT */ /* Low Priority Sprites */ - for (int x = 0; x < 320; x++) + for (int x = 0; x < horz; x++) { if (!MEGADRIVE_REG0C_SHADOW_HIGLIGHT) { @@ -2020,7 +2028,7 @@ void sega315_5313_device::render_videoline_to_videobuffer(int scanline) } /* High Priority A+B Tiles */ - for (int x = 0; x < 320; x++) + for (int x = 0; x < horz; x++) { if (!MEGADRIVE_REG0C_SHADOW_HIGLIGHT) { @@ -2046,7 +2054,7 @@ void sega315_5313_device::render_videoline_to_videobuffer(int scanline) } /* High Priority Sprites */ - for (int x = 0; x < 320; x++) + for (int x = 0; x < horz; x++) { if (!MEGADRIVE_REG0C_SHADOW_HIGLIGHT) { @@ -2089,6 +2097,8 @@ void sega315_5313_device::render_videobuffer_to_screenbuffer(int scanline) { const unsigned palette_per_scanline = scanline * 64; u32 *lineptr; + unsigned horz = m_lcm_scaling ? hres[get_hres()] : 320; + unsigned mul = m_lcm_scaling ? hres_mul[get_hres()] : 1; if (!m_use_alt_timing) { @@ -2114,27 +2124,27 @@ void sega315_5313_device::render_videobuffer_to_screenbuffer(int scanline) } } - for (int x = 0; x < 320; x++) + for (int srcx = 0, xx = 0, dstx = 0; srcx < horz; dstx++) { - const u32 dat = m_video_renderline[x]; + const u32 dat = m_video_renderline[srcx]; const u16 clut = (dat & 0x3f) + palette_per_scanline; if (!(dat & 0x20000)) - m_render_line_raw[x] = 0x100; + m_render_line_raw[srcx] = 0x100; else - m_render_line_raw[x] = 0x000; + m_render_line_raw[srcx] = 0x000; if (!MEGADRIVE_REG0C_SHADOW_HIGLIGHT) { if (dat & 0x10000) { - lineptr[x] = m_gfx_palette->pen(clut); - m_render_line_raw[x] |= (dat & 0x3f) | 0x080; + lineptr[dstx] = m_gfx_palette->pen(clut); + m_render_line_raw[srcx] |= (dat & 0x3f) | 0x080; } else { - lineptr[x] = m_gfx_palette->pen(clut); - m_render_line_raw[x] |= (dat & 0x3f) | 0x040; + lineptr[dstx] = m_gfx_palette->pen(clut); + m_render_line_raw[srcx] |= (dat & 0x3f) | 0x040; } } else @@ -2148,26 +2158,26 @@ void sega315_5313_device::render_videobuffer_to_screenbuffer(int scanline) case 0x10000: // (sprite) low priority, no shadow sprite, no highlight = shadow case 0x12000: // (sprite) low priority, shadow sprite, no highlight = shadow case 0x16000: // (sprite) normal pri, shadow sprite, no highlight = shadow? - lineptr[x] = m_gfx_palette_shadow->pen(clut); - m_render_line_raw[x] |= (dat & 0x3f) | 0x000; + lineptr[dstx] = m_gfx_palette_shadow->pen(clut); + m_render_line_raw[srcx] |= (dat & 0x3f) | 0x000; break; case 0x4000: // normal pri, no shadow sprite, no highlight = normal; case 0x8000: // low pri, highlight sprite = normal; - lineptr[x] = m_gfx_palette->pen(clut); - m_render_line_raw[x] |= (dat & 0x3f) | 0x040; + lineptr[dstx] = m_gfx_palette->pen(clut); + m_render_line_raw[srcx] |= (dat & 0x3f) | 0x040; break; case 0x14000: // (sprite) normal pri, no shadow sprite, no highlight = normal; case 0x18000: // (sprite) low pri, highlight sprite = normal; - lineptr[x] = m_gfx_palette->pen(clut); - m_render_line_raw[x] |= (dat & 0x3f) | 0x080; + lineptr[dstx] = m_gfx_palette->pen(clut); + m_render_line_raw[srcx] |= (dat & 0x3f) | 0x080; break; case 0x0c000: // normal pri, highlight set = highlight? case 0x1c000: // (sprite) normal pri, highlight set = highlight? - lineptr[x] = m_gfx_palette_hilight->pen(clut); - m_render_line_raw[x] |= (dat & 0x3f) | 0x0c0; + lineptr[dstx] = m_gfx_palette_hilight->pen(clut); + m_render_line_raw[srcx] |= (dat & 0x3f) | 0x0c0; break; case 0x0a000: // shadow set, highlight set - not possible @@ -2175,18 +2185,30 @@ void sega315_5313_device::render_videobuffer_to_screenbuffer(int scanline) case 0x1a000: // (sprite)shadow set, highlight set - not possible case 0x1e000: // (sprite)shadow set, highlight set, normal set, not possible default: - lineptr[x] = m_render_line_raw[x] |= (machine().rand() & 0x3f); + lineptr[dstx] = m_render_line_raw[srcx] |= (machine().rand() & 0x3f); break; } } + if (++xx >= mul) + { + srcx++; + xx = 0; + } } if (!m_32x_scanline_helper_func.isnull()) m_32x_scanline_helper_func(scanline); if (!m_32x_scanline_func.isnull()) { - for (int x = 0; x < 320; x++) - m_32x_scanline_func(x, m_video_renderline[x] & 0x20000, lineptr[x]); + for (int srcx = 0, xx = 0, dstx = 0; srcx < horz; dstx++) + { + m_32x_scanline_func(srcx, m_video_renderline[srcx] & 0x20000, lineptr[dstx]); + if (++xx >= mul) + { + srcx++; + xx = 0; + } + } } } @@ -2280,6 +2302,7 @@ void sega315_5313_device::vdp_handle_eof() { rectangle visarea; int scr_width = 320; + int scr_mul = 1; m_vblank_flag = 0; //m_irq6_pending = 0; /* NO! (breaks warlock) */ @@ -2315,19 +2338,14 @@ void sega315_5313_device::vdp_handle_eof() m_z80irq_scanline <<= 1; } - switch (MEGADRIVE_REG0C_RS0 | (MEGADRIVE_REG0C_RS1 << 1)) - { - /* note, add 240 mode + init new timings! */ - case 0: scr_width = 256; break; - case 1: scr_width = 256; break; - case 2: scr_width = 320; break; - case 3: scr_width = 320; break; - } + /* note, add 240 mode + init new timings! */ + scr_mul = m_lcm_scaling ? hres_mul[get_hres()] : 1; + scr_width = hres[get_hres()] * scr_mul; // osd_printf_debug("my mode %02x", m_regs[0x0c]); visarea.set(0, scr_width - 1, 0, m_visible_scanlines - 1); - screen().configure(480, m_total_scanlines, visarea, screen().frame_period().attoseconds()); + screen().configure(480 * scr_mul, m_total_scanlines, visarea, screen().frame_period().attoseconds()); } @@ -2353,7 +2371,7 @@ TIMER_DEVICE_CALLBACK_MEMBER(sega315_5313_device::megadriv_scanline_timer_callba { if (param == 0) { - //printf("where are we? %d %d\n", screen().vpos(), screen().hpos()); + //printf("where are we? %d %d\n", screen().vpos(), screen_hpos()); vdp_handle_eof(); //vdp_clear_bitmap(); } diff --git a/src/devices/video/315_5313.h b/src/devices/video/315_5313.h index fe68bb9d9a9..4f6513f47cb 100644 --- a/src/devices/video/315_5313.h +++ b/src/devices/video/315_5313.h @@ -32,6 +32,7 @@ public: auto lv6_irq() { return m_lv6irqline_callback.bind(); } auto lv4_irq() { return m_lv4irqline_callback.bind(); } + void set_lcm_scaling(bool lcm_scaling) { m_lcm_scaling = lcm_scaling; } void set_alt_timing(int use_alt_timing) { m_use_alt_timing = use_alt_timing; } void set_pal_write_base(int palwrite_base) { m_palwrite_base = palwrite_base; } template void set_ext_palette(T &&tag) { m_ext_palette.set_tag(std::forward(tag)); } @@ -116,6 +117,7 @@ protected: md_32x_interrupt_delegate m_32x_interrupt_func; md_32x_scanline_helper_delegate m_32x_scanline_helper_func; + virtual int screen_hpos() override; private: // vdp code defines const u8 CODE_DMA() { return m_vdp_code & 0x20; } @@ -142,6 +144,7 @@ private: void get_nametable(gfx_element *tile_gfx, u16 tile_base, nametable_t &tile, int vcolumn); inline void draw_tile(nametable_t tile, int start, int end, int &dpos, bool is_fg); + inline u8 get_hres(); int m_command_pending; // 2nd half of command pending.. u16 m_command_part1; u16 m_command_part2; @@ -159,6 +162,7 @@ private: int m_imode; + bool m_lcm_scaling; int m_visible_scanlines; int m_irq6_scanline; int m_z80irq_scanline; diff --git a/src/mame/drivers/megaplay.cpp b/src/mame/drivers/megaplay.cpp index c3f9989ced5..9c5803dd3dc 100644 --- a/src/mame/drivers/megaplay.cpp +++ b/src/mame/drivers/megaplay.cpp @@ -632,20 +632,24 @@ uint32_t mplay_state::screen_update_megplay(screen_device &screen, bitmap_rgb32 // if it's meant to be stretched we'll have to multiply the entire output x4 for the Genesis VDP and x5 for the SMS VDP to get a common 1280 pixel wide image // overlay, only drawn for pixels != 0 + const u32 width = sega315_5124_device::WIDTH - (sega315_5124_device::LBORDER_START + sega315_5124_device::LBORDER_WIDTH); for (int y = 0; y < 224; y++) { uint32_t* lineptr = &bitmap.pix32(y); - uint32_t* srcptr = &m_vdp1->get_bitmap().pix32(y + sega315_5124_device::TBORDER_START + sega315_5124_device::NTSC_224_TBORDER_HEIGHT); + uint32_t* srcptr = &m_vdp1->get_bitmap().pix32(y + sega315_5124_device::TBORDER_START + sega315_5124_device::NTSC_224_TBORDER_HEIGHT, sega315_5124_device::LBORDER_START + sega315_5124_device::LBORDER_WIDTH); - for (int x = 0; x < sega315_5124_device::WIDTH; x++) + for (int srcx = 0, xx = 0, dstx = 0; srcx < width; dstx++) { - uint32_t src = srcptr[x] & 0xffffff; + uint32_t src = srcptr[srcx] & 0xffffff; if (src) { - if (x>=16) - lineptr[x-16] = src; - + lineptr[dstx] = src; + } + if (++xx >= 5) + { + srcx++; + xx = 0; } } } @@ -690,15 +694,18 @@ void mplay_state::megaplay(machine_config &config) io2.in_porte_cb().set(FUNC(mplay_state::bios_6404_r)); io2.out_porte_cb().set(FUNC(mplay_state::bios_6404_w)); + m_vdp->set_lcm_scaling(true); + /* New update functions to handle the extra layer */ - subdevice("megadriv")->set_raw(XTAL(10'738'635)/2, \ - sega315_5124_device::WIDTH, sega315_5124_device::LBORDER_START + sega315_5124_device::LBORDER_WIDTH, sega315_5124_device::LBORDER_START + sega315_5124_device::LBORDER_WIDTH + 256, \ + subdevice("megadriv")->set_raw((XTAL(10'738'635) * 5)/2, \ + sega315_5124_device::WIDTH * 5, (sega315_5124_device::LBORDER_START + sega315_5124_device::LBORDER_WIDTH) * 5, (sega315_5124_device::LBORDER_START + sega315_5124_device::LBORDER_WIDTH + 256) * 5, \ sega315_5124_device::HEIGHT_NTSC, sega315_5124_device::TBORDER_START + sega315_5124_device::NTSC_224_TBORDER_HEIGHT, sega315_5124_device::TBORDER_START + sega315_5124_device::NTSC_224_TBORDER_HEIGHT + 224); subdevice("megadriv")->set_screen_update(FUNC(mplay_state::screen_update_megplay)); // Megaplay has an additional SMS VDP as an overlay SEGA315_5246(config, m_vdp1, MASTER_CLOCK / 5); /* ?? */ m_vdp1->set_screen("megadriv"); + m_vdp1->set_hcounter_divide(5); m_vdp1->set_is_pal(false); m_vdp1->n_int().set_inputline(m_bioscpu, 0); m_vdp1->add_route(ALL_OUTPUTS, "lspeaker", 0.25); -- cgit v1.2.3-70-g09d2