From 1f8976b6b439ef53fcffc7c444fe13efeb15ebe8 Mon Sep 17 00:00:00 2001 From: Happy Date: Thu, 24 Sep 2015 12:14:50 -0600 Subject: [PATCH] More effort to disentangle the VI and RDP in the source. VI now uses the values set in registers to set the screen resolution, instead of using fixed values. --- src/mame/includes/n64.h | 9 ++ src/mame/machine/n64.c | 16 ++- src/mame/video/n64.c | 208 ++++++++++++++++++-------------------- src/mame/video/n64.h | 9 -- src/mame/video/n64types.h | 2 - 5 files changed, 119 insertions(+), 125 deletions(-) diff --git a/src/mame/includes/n64.h b/src/mame/includes/n64.h index 1a35812e87b..bcbd8879188 100644 --- a/src/mame/includes/n64.h +++ b/src/mame/includes/n64.h @@ -100,6 +100,7 @@ public: void si_dma_tick(); void vi_scanline_tick(); void reset_tick(); + void video_update(bitmap_rgb32 &bitmap); // Video Interface (VI) registers UINT32 vi_width; @@ -263,6 +264,14 @@ private: // Video Interface (VI) functions void vi_recalculate_resolution(); + void video_update16(bitmap_rgb32 &bitmap); + void video_update32(bitmap_rgb32 &bitmap); + UINT8 random_seed; // %HACK%, adds 19 each time it's read and is more or less random + UINT8 get_random() { return random_seed += 0x13; } + + INT32 m_gamma_table[256]; + INT32 m_gamma_dither_table[0x4000]; + }; // device type definition diff --git a/src/mame/machine/n64.c b/src/mame/machine/n64.c index cfdcb914117..d4c0eec9f8f 100644 --- a/src/mame/machine/n64.c +++ b/src/mame/machine/n64.c @@ -27,7 +27,18 @@ n64_periphs::n64_periphs(const machine_config &mconfig, const char *tag, device_ , dd_present(false) , disk_present(false) , cart_present(false) -{ +{ + for (INT32 i = 0; i < 256; i++) + { + m_gamma_table[i] = sqrt((float)(i << 6)); + m_gamma_table[i] <<= 1; + } + + for (INT32 i = 0; i < 0x4000; i++) + { + m_gamma_dither_table[i] = sqrt((float)i); + m_gamma_dither_table[i] <<= 1; + } } TIMER_CALLBACK_MEMBER(n64_periphs::reset_timer_callback) @@ -1029,14 +1040,13 @@ void n64_periphs::vi_recalculate_resolution() if(vi_control & 0x40) /* Interlace */ { - height *= 2; } //state->m_rdp->m_misc_state.m_fb_height = height; visarea.max_x = width - 1; visarea.max_y = height - 1; - m_screen->configure(width, 525, visarea, period); + m_screen->configure((vi_hsync & 0x00000fff)>>2, (vi_vsync & 0x00000fff), visarea, period); } READ32_MEMBER( n64_periphs::vi_reg_r ) diff --git a/src/mame/video/n64.c b/src/mame/video/n64.c index e11de1b95b7..181b50cf7cc 100644 --- a/src/mame/video/n64.c +++ b/src/mame/video/n64.c @@ -89,16 +89,93 @@ INT32 n64_rdp::get_alpha_cvg(INT32 comb_alpha, rdp_span_aux* userdata, const rdp /*****************************************************************************/ -void n64_rdp::video_update(n64_periphs* n64, bitmap_rgb32 &bitmap) +void n64_state::video_start() { - switch(n64->vi_control & 0x3) + m_rdp = auto_alloc(machine(), n64_rdp(*this)); + + m_rdp->set_machine(machine()); + m_rdp->init_internal_state(); + + m_rdp->m_blender.set_machine(machine()); + m_rdp->m_blender.set_processor(m_rdp); + + m_rdp->m_tex_pipe.set_machine(machine()); + + m_rdp->m_aux_buf = auto_alloc_array_clear(machine(), UINT8, EXTENT_AUX_COUNT); + + if (LOG_RDP_EXECUTION) + { + rdp_exec = fopen("rdp_execute.txt", "wt"); + } +} + +UINT32 n64_state::screen_update_n64(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect) +{ + n64_periphs* n64 = machine().device("rcp"); + + //UINT16* frame_buffer = (UINT16*)&rdram[(n64->vi_origin & 0xffffff) >> 2]; + //UINT8* cvg_buffer = &m_rdp.m_hidden_bits[((n64->vi_origin & 0xffffff) >> 2) >> 1]; + //INT32 vibuffering = ((n64->vi_control & 2) && fsaa && divot); + + //vibuffering = 0; // Disabled for now + + /* + if (vibuffering && ((n64->vi_control & 3) == 2)) + { + if (frame_buffer) + { + for (j=0; j < vres; j++) + { + for (i=0; i < hres; i++) + { + UINT16 pix; + pix = frame_buffer[pixels ^ WORD_ADDR_XOR]; + curpixel_cvg = ((pix & 1) << 2) | (cvg_buffer[pixels ^ BYTE_ADDR_XOR] & 3); // Reuse of this variable + if (curpixel_cvg < 7 && i > 1 && j > 1 && i < (hres - 2) && j < (vres - 2) && fsaa) + { + newc = video_filter16(&frame_buffer[pixels ^ WORD_ADDR_XOR], &cvg_buffer[pixels ^ BYTE_ADDR_XOR], n64->vi_width); + ViBuffer[i][j] = newc; + } + else + { + newc.i.r = ((pix >> 8) & 0xf8) | (pix >> 13); + newc.i.g = ((pix >> 3) & 0xf8) | ((pix >> 8) & 0x07); + newc.i.b = ((pix << 2) & 0xf8) | ((pix >> 3) & 0x07); + ViBuffer[i][j] = newc; + } + pixels++; + } + pixels += invisiblewidth; + } + } + } + */ + + if (n64->vi_blank) + { + bitmap.fill(0, screen.visible_area()); + return 0; + } + + n64->video_update(bitmap); + + return 0; +} + +void n64_state::screen_eof_n64(screen_device &screen, bool state) +{ +} + +void n64_periphs::video_update(bitmap_rgb32 &bitmap) +{ + switch(vi_control & 0x3) { case PIXEL_SIZE_16BIT: - video_update16(n64, bitmap); + video_update16(bitmap); break; case PIXEL_SIZE_32BIT: - video_update32(n64, bitmap); + video_update32(bitmap); break; default: @@ -107,7 +184,7 @@ void n64_rdp::video_update(n64_periphs* n64, bitmap_rgb32 &bitmap) } } -void n64_rdp::video_update16(n64_periphs* n64, bitmap_rgb32 &bitmap) +void n64_periphs::video_update16(bitmap_rgb32 &bitmap) { //INT32 fsaa = (((n64->vi_control >> 8) & 3) < 2); //INT32 divot = (n64->vi_control >> 4) & 1; @@ -117,17 +194,17 @@ void n64_rdp::video_update16(n64_periphs* n64, bitmap_rgb32 &bitmap) //INT32 dither_filter = (n64->vi_control >> 16) & 1; //INT32 vibuffering = ((n64->vi_control & 2) && fsaa && divot); - UINT16* frame_buffer = (UINT16*)&rdram[(n64->vi_origin & 0xffffff) >> 2]; + UINT16* frame_buffer = (UINT16*)&rdram[(vi_origin & 0xffffff) >> 2]; //UINT32 hb = ((n64->vi_origin & 0xffffff) >> 2) >> 1; //UINT8* hidden_buffer = &m_hidden_bits[hb]; - INT32 hdiff = (n64->vi_hstart & 0x3ff) - ((n64->vi_hstart >> 16) & 0x3ff); - float hcoeff = ((float)(n64->vi_xscale & 0xfff) / (1 << 10)); + INT32 hdiff = (vi_hstart & 0x3ff) - ((vi_hstart >> 16) & 0x3ff); + float hcoeff = ((float)(vi_xscale & 0xfff) / (1 << 10)); UINT32 hres = ((float)hdiff * hcoeff); - INT32 invisiblewidth = n64->vi_width - hres; + INT32 invisiblewidth = vi_width - hres; - INT32 vdiff = ((n64->vi_vstart & 0x3ff) - ((n64->vi_vstart >> 16) & 0x3ff)) >> 1; - float vcoeff = ((float)(n64->vi_yscale & 0xfff) / (1 << 10)); + INT32 vdiff = ((vi_vstart & 0x3ff) - ((vi_vstart >> 16) & 0x3ff)) >> 1; + float vcoeff = ((float)(vi_yscale & 0xfff) / (1 << 10)); UINT32 vres = ((float)vdiff * vcoeff); if (vdiff <= 0 || hdiff <= 0) @@ -169,21 +246,21 @@ void n64_rdp::video_update16(n64_periphs* n64, bitmap_rgb32 &bitmap) } } -void n64_rdp::video_update32(n64_periphs* n64, bitmap_rgb32 &bitmap) +void n64_periphs::video_update32(bitmap_rgb32 &bitmap) { - INT32 gamma = (n64->vi_control >> 3) & 1; - INT32 gamma_dither = (n64->vi_control >> 2) & 1; + INT32 gamma = (vi_control >> 3) & 1; + INT32 gamma_dither = (vi_control >> 2) & 1; //INT32 vibuffering = ((n64->vi_control & 2) && fsaa && divot); - UINT32* frame_buffer32 = (UINT32*)&rdram[(n64->vi_origin & 0xffffff) >> 2]; + UINT32* frame_buffer32 = (UINT32*)&rdram[(vi_origin & 0xffffff) >> 2]; - const INT32 hdiff = (n64->vi_hstart & 0x3ff) - ((n64->vi_hstart >> 16) & 0x3ff); - const float hcoeff = ((float)(n64->vi_xscale & 0xfff) / (1 << 10)); + const INT32 hdiff = (vi_hstart & 0x3ff) - ((vi_hstart >> 16) & 0x3ff); + const float hcoeff = ((float)(vi_xscale & 0xfff) / (1 << 10)); UINT32 hres = ((float)hdiff * hcoeff); - INT32 invisiblewidth = n64->vi_width - hres; + INT32 invisiblewidth = vi_width - hres; - const INT32 vdiff = ((n64->vi_vstart & 0x3ff) - ((n64->vi_vstart >> 16) & 0x3ff)) >> 1; - const float vcoeff = ((float)(n64->vi_yscale & 0xfff) / (1 << 10)); + const INT32 vdiff = ((vi_vstart & 0x3ff) - ((vi_vstart >> 16) & 0x3ff)) >> 1; + const float vcoeff = ((float)(vi_yscale & 0xfff) / (1 << 10)); const UINT32 vres = ((float)vdiff * vcoeff); if (vdiff <= 0 || hdiff <= 0) @@ -242,7 +319,6 @@ void n64_rdp::video_update32(n64_periphs* n64, bitmap_rgb32 &bitmap) pix = (r << 24) | (g << 16) | (b << 8); } - d[i] = (pix >> 8); } frame_buffer32 += invisiblewidth; @@ -3067,19 +3143,6 @@ n64_rdp::n64_rdp(n64_state &state) : poly_managerset_machine(machine()); - m_rdp->init_internal_state(); - - m_rdp->m_blender.set_machine(machine()); - m_rdp->m_blender.set_processor(m_rdp); - - m_rdp->m_tex_pipe.set_machine(machine()); - - m_rdp->m_aux_buf = auto_alloc_array_clear(machine(), UINT8, EXTENT_AUX_COUNT); - - if (LOG_RDP_EXECUTION) - { - rdp_exec = fopen("rdp_execute.txt", "wt"); - } -} - -UINT32 n64_state::screen_update_n64(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect) -{ - n64_periphs* n64 = machine().device("rcp"); - - //UINT16* frame_buffer = (UINT16*)&rdram[(n64->vi_origin & 0xffffff) >> 2]; - //UINT8* cvg_buffer = &m_rdp.m_hidden_bits[((n64->vi_origin & 0xffffff) >> 2) >> 1]; - //INT32 vibuffering = ((n64->vi_control & 2) && fsaa && divot); - - //vibuffering = 0; // Disabled for now - - /* - if (vibuffering && ((n64->vi_control & 3) == 2)) - { - if (frame_buffer) - { - for (j=0; j < vres; j++) - { - for (i=0; i < hres; i++) - { - UINT16 pix; - pix = frame_buffer[pixels ^ WORD_ADDR_XOR]; - curpixel_cvg = ((pix & 1) << 2) | (cvg_buffer[pixels ^ BYTE_ADDR_XOR] & 3); // Reuse of this variable - if (curpixel_cvg < 7 && i > 1 && j > 1 && i < (hres - 2) && j < (vres - 2) && fsaa) - { - newc = video_filter16(&frame_buffer[pixels ^ WORD_ADDR_XOR], &cvg_buffer[pixels ^ BYTE_ADDR_XOR], n64->vi_width); - ViBuffer[i][j] = newc; - } - else - { - newc.i.r = ((pix >> 8) & 0xf8) | (pix >> 13); - newc.i.g = ((pix >> 3) & 0xf8) | ((pix >> 8) & 0x07); - newc.i.b = ((pix << 2) & 0xf8) | ((pix >> 3) & 0x07); - ViBuffer[i][j] = newc; - } - pixels++; - } - pixels += invisiblewidth; - } - } - } - */ - - if (n64->vi_blank) - { - bitmap.fill(0, screen.visible_area()); - return 0; - } - - m_rdp->video_update(n64, bitmap); - - return 0; -} - -void n64_state::screen_eof_n64(screen_device &screen, bool state) -{ -} - void n64_rdp::render_spans(INT32 start, INT32 end, INT32 tilenum, bool flip, extent_t* spans, bool rect, rdp_poly_state* object) { const INT32 clipy1 = m_scissor.m_yh; diff --git a/src/mame/video/n64.h b/src/mame/video/n64.h index 25238d9b881..2d44786f232 100644 --- a/src/mame/video/n64.h +++ b/src/mame/video/n64.h @@ -195,9 +195,6 @@ public: UINT8* get_tmem8() { return m_tmem; } UINT16* get_tmem16() { return (UINT16*)m_tmem; } - // Emulation Accelerators - UINT8 get_random() { return m_misc_state.m_random_seed += 0x13; } - // YUV Factors void set_yuv_factors(color_t k023, color_t k1, color_t k4, color_t k5) { m_k023 = k023; m_k1 = k1; m_k4 = k4; m_k5 = k5; } color_t& get_k023() { return m_k023; } @@ -226,9 +223,6 @@ public: INT32 normalize_dzpix(INT32 sum); bool z_compare(UINT32 zcurpixel, UINT32 dzcurpixel, UINT32 sz, UINT16 dzpix, rdp_span_aux* userdata, const rdp_poly_state &object); - // Fullscreen update-related - void video_update(n64_periphs* n64, bitmap_rgb32 &bitmap); - // Commands void cmd_invalid(UINT32 w1, UINT32 w2); void cmd_noop(UINT32 w1, UINT32 w2); @@ -374,9 +368,6 @@ private: INT32 m_norm_point_rom[64]; INT32 m_norm_slope_rom[64]; - INT32 m_gamma_table[256]; - INT32 m_gamma_dither_table[0x4000]; - static UINT32 s_special_9bit_clamptable[512]; static const z_decompress_entry_t m_z_dec_table[8]; diff --git a/src/mame/video/n64types.h b/src/mame/video/n64types.h index fedac9e0225..74a7a958888 100644 --- a/src/mame/video/n64types.h +++ b/src/mame/video/n64types.h @@ -27,8 +27,6 @@ struct misc_state_t INT32 m_ti_width; // Width (in pixels) of TI transfers UINT32 m_ti_address; // Destination address for TI transfers - UINT8 m_random_seed; // %HACK%, adds 19 each time it's read and is more or less random - UINT32 m_max_level; // Maximum LOD level for texture filtering UINT32 m_min_level; // Minimum LOD level for texture filtering