trunk/src/mame/video/neogeo.c
| r30689 | r30690 | |
| 19 | 19 | * |
| 20 | 20 | *************************************/ |
| 21 | 21 | |
| 22 | | void neogeo_state::compute_rgb_weights( ) |
| 23 | | { |
| 24 | | static const int resistances[] = { 220, 470, 1000, 2200, 3900 }; |
| 25 | | |
| 26 | | /* compute four sets of weights - with or without the pulldowns - |
| 27 | | ensuring that we use the same scaler for all */ |
| 28 | | |
| 29 | | double scaler = compute_resistor_weights(0, 0xff, -1, |
| 30 | | 5, resistances, m_rgb_weights_normal, 0, 0, |
| 31 | | 0, 0, 0, 0, 0, |
| 32 | | 0, 0, 0, 0, 0); |
| 33 | | |
| 34 | | compute_resistor_weights(0, 0xff, scaler, |
| 35 | | 5, resistances, m_rgb_weights_normal_bit15, 8200, 0, |
| 36 | | 0, 0, 0, 0, 0, |
| 37 | | 0, 0, 0, 0, 0); |
| 38 | | |
| 39 | | compute_resistor_weights(0, 0xff, scaler, |
| 40 | | 5, resistances, m_rgb_weights_dark, 150, 0, |
| 41 | | 0, 0, 0, 0, 0, |
| 42 | | 0, 0, 0, 0, 0); |
| 43 | | |
| 44 | | compute_resistor_weights(0, 0xff, scaler, |
| 45 | | 5, resistances, m_rgb_weights_dark_bit15, 1 / ((1.0 / 8200) + (1.0 / 150)), 0, |
| 46 | | 0, 0, 0, 0, 0, |
| 47 | | 0, 0, 0, 0, 0); |
| 48 | | } |
| 49 | | |
| 50 | | |
| 51 | 22 | void neogeo_state::create_rgb_lookups() |
| 52 | 23 | { |
| 53 | 24 | static const int resistances[] = {3900, 2200, 1000, 470, 220}; |
| r30689 | r30690 | |
| 92 | 63 | } |
| 93 | 64 | } |
| 94 | 65 | |
| 95 | | |
| 96 | | pen_t neogeo_state::get_pen( UINT16 data ) |
| 66 | void neogeo_state::set_pens() |
| 97 | 67 | { |
| 98 | | double *weights; |
| 99 | | UINT8 r, g, b; |
| 100 | | |
| 101 | | if (m_screen_dark) |
| 102 | | { |
| 103 | | if (data & 0x8000) |
| 104 | | weights = m_rgb_weights_dark_bit15; |
| 105 | | else |
| 106 | | weights = m_rgb_weights_dark; |
| 107 | | } |
| 108 | | else |
| 109 | | { |
| 110 | | if (data & 0x8000) |
| 111 | | weights = m_rgb_weights_normal_bit15; |
| 112 | | else |
| 113 | | weights = m_rgb_weights_normal; |
| 114 | | } |
| 115 | | |
| 116 | | r = combine_5_weights(weights, |
| 117 | | (data >> 11) & 0x01, |
| 118 | | (data >> 10) & 0x01, |
| 119 | | (data >> 9) & 0x01, |
| 120 | | (data >> 8) & 0x01, |
| 121 | | (data >> 14) & 0x01); |
| 122 | | |
| 123 | | g = combine_5_weights(weights, |
| 124 | | (data >> 7) & 0x01, |
| 125 | | (data >> 6) & 0x01, |
| 126 | | (data >> 5) & 0x01, |
| 127 | | (data >> 4) & 0x01, |
| 128 | | (data >> 13) & 0x01); |
| 129 | | |
| 130 | | b = combine_5_weights(weights, |
| 131 | | (data >> 3) & 0x01, |
| 132 | | (data >> 2) & 0x01, |
| 133 | | (data >> 1) & 0x01, |
| 134 | | (data >> 0) & 0x01, |
| 135 | | (data >> 12) & 0x01); |
| 136 | | |
| 137 | | return rgb_t(r, g, b); |
| 68 | const pen_t *pen_base = m_palette->pens() + m_palette_bank + (m_screen_shadow ? 0x2000 : 0); |
| 69 | m_sprgen->set_pens(pen_base); |
| 70 | m_bg_pen = pen_base + 0xfff; |
| 138 | 71 | } |
| 139 | 72 | |
| 140 | 73 | |
| 141 | | void neogeo_state::regenerate_pens() |
| 74 | void neogeo_state::neogeo_set_screen_shadow( int data ) |
| 142 | 75 | { |
| 143 | | int i; |
| 144 | | |
| 145 | | for (i = 0; i < NUM_PENS; i++) |
| 146 | | m_pens[i] = get_pen(m_palettes[m_palette_bank][i]); |
| 76 | m_screen_shadow = data; |
| 77 | set_pens(); |
| 147 | 78 | } |
| 148 | 79 | |
| 149 | 80 | |
| 150 | | void neogeo_state::neogeo_set_palette_bank( UINT8 data ) |
| 81 | void neogeo_state::neogeo_set_palette_bank( int data ) |
| 151 | 82 | { |
| 152 | | if (data != m_palette_bank) |
| 153 | | { |
| 154 | | m_palette_bank = data; |
| 155 | | |
| 156 | | regenerate_pens(); |
| 157 | | } |
| 83 | m_palette_bank = data ? 0x1000 : 0; |
| 84 | set_pens(); |
| 158 | 85 | } |
| 159 | 86 | |
| 160 | 87 | |
| 161 | | void neogeo_state::neogeo_set_screen_dark( UINT8 data ) |
| 162 | | { |
| 163 | | if (data != m_screen_dark) |
| 164 | | { |
| 165 | | m_screen_dark = data; |
| 166 | | |
| 167 | | regenerate_pens(); |
| 168 | | } |
| 169 | | } |
| 170 | | |
| 171 | | |
| 172 | 88 | READ16_MEMBER(neogeo_state::neogeo_paletteram_r) |
| 173 | 89 | { |
| 174 | | return m_palettes[m_palette_bank][offset]; |
| 90 | return m_paletteram[m_palette_bank + offset]; |
| 175 | 91 | } |
| 176 | 92 | |
| 177 | 93 | |
| 178 | 94 | WRITE16_MEMBER(neogeo_state::neogeo_paletteram_w) |
| 179 | 95 | { |
| 180 | | UINT16 *addr = &m_palettes[m_palette_bank][offset]; |
| 96 | offset += m_palette_bank; |
| 97 | data = COMBINE_DATA(&m_paletteram[offset]); |
| 181 | 98 | |
| 182 | | COMBINE_DATA(addr); |
| 99 | int dark = data >> 15; |
| 100 | int r = ((data >> 14) & 0x1) | ((data >> 7) & 0x1e); |
| 101 | int g = ((data >> 13) & 0x1) | ((data >> 3) & 0x1e); |
| 102 | int b = ((data >> 12) & 0x1) | ((data << 1) & 0x1e); |
| 183 | 103 | |
| 184 | | m_pens[offset] = get_pen(*addr); |
| 104 | m_palette->set_pen_color(offset, |
| 105 | m_palette_lookup[r][dark], |
| 106 | m_palette_lookup[g][dark], |
| 107 | m_palette_lookup[b][dark]); // normal |
| 108 | |
| 109 | m_palette->set_pen_color(offset + 0x2000, |
| 110 | m_palette_lookup[r][dark+2], |
| 111 | m_palette_lookup[g][dark+2], |
| 112 | m_palette_lookup[b][dark+2]); // shadow |
| 185 | 113 | } |
| 186 | 114 | |
| 187 | 115 | |
| r30689 | r30690 | |
| 194 | 122 | |
| 195 | 123 | void neogeo_state::video_start() |
| 196 | 124 | { |
| 197 | | /* allocate memory not directly mapped */ |
| 198 | | m_palettes[0] = auto_alloc_array(machine(), UINT16, NUM_PENS); |
| 199 | | m_palettes[1] = auto_alloc_array(machine(), UINT16, NUM_PENS); |
| 200 | | m_pens = auto_alloc_array(machine(), pen_t, NUM_PENS); |
| 201 | | |
| 202 | | compute_rgb_weights(); |
| 203 | 125 | create_rgb_lookups(); |
| 204 | 126 | |
| 205 | | memset(m_palettes[0], 0x00, NUM_PENS * sizeof(UINT16)); |
| 206 | | memset(m_palettes[1], 0x00, NUM_PENS * sizeof(UINT16)); |
| 207 | | memset(m_pens, 0x00, NUM_PENS * sizeof(pen_t)); |
| 127 | m_paletteram.resize_and_clear(0x1000 * 2); |
| 208 | 128 | |
| 209 | | save_pointer(NAME(m_palettes[0]), NUM_PENS); |
| 210 | | save_pointer(NAME(m_palettes[1]), NUM_PENS); |
| 211 | | save_item(NAME(m_screen_dark)); |
| 129 | m_screen_shadow = 0; |
| 130 | m_palette_bank = 0; |
| 131 | |
| 132 | save_item(NAME(m_paletteram)); |
| 133 | save_item(NAME(m_screen_shadow)); |
| 212 | 134 | save_item(NAME(m_palette_bank)); |
| 213 | | machine().save().register_postload(save_prepost_delegate(FUNC(neogeo_state::regenerate_pens), this)); |
| 135 | machine().save().register_postload(save_prepost_delegate(FUNC(neogeo_state::set_pens), this)); |
| 214 | 136 | |
| 215 | | m_sprgen->set_pens(m_pens); |
| 137 | set_pens(); |
| 216 | 138 | } |
| 217 | 139 | |
| 218 | 140 | |
| r30689 | r30690 | |
| 239 | 161 | UINT32 neogeo_state::screen_update_neogeo(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect) |
| 240 | 162 | { |
| 241 | 163 | // fill with background color first |
| 242 | | bitmap.fill(m_pens[0x0fff], cliprect); |
| 164 | bitmap.fill(*m_bg_pen, cliprect); |
| 243 | 165 | |
| 244 | 166 | m_sprgen->draw_sprites(bitmap, cliprect.min_y); |
| 245 | 167 | |
trunk/src/mame/video/neogeo_spr.c
| r30689 | r30690 | |
| 234 | 234 | int i; |
| 235 | 235 | int gfx_offset = ((code << 5) | (scanline & 0x07)) & addr_mask; |
| 236 | 236 | |
| 237 | | pen_t *char_pens; |
| 237 | const pen_t *char_pens; |
| 238 | 238 | |
| 239 | 239 | char_pens = &m_pens[code_and_palette >> 12 << m_bppshift]; |
| 240 | 240 | |
| r30689 | r30690 | |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | |
| 255 | | inline void neosprite_base_device::draw_fixed_layer_2pixels(UINT32*&pixel_addr, int offset, UINT8* gfx_base, pen_t* char_pens) |
| 255 | inline void neosprite_base_device::draw_fixed_layer_2pixels(UINT32*&pixel_addr, int offset, UINT8* gfx_base, const pen_t* char_pens) |
| 256 | 256 | { |
| 257 | 257 | UINT8 data = gfx_base[offset]; |
| 258 | 258 | |
| r30689 | r30690 | |
| 377 | 377 | UINT16 attr; |
| 378 | 378 | UINT32 code; |
| 379 | 379 | const int *zoom_x_table; |
| 380 | | pen_t *line_pens; |
| 380 | const pen_t *line_pens; |
| 381 | 381 | int x_inc; |
| 382 | 382 | |
| 383 | 383 | int sprite_line = (scanline - y) & 0x1ff; |
| r30689 | r30690 | |
| 627 | 627 | m_screen = screen; |
| 628 | 628 | } |
| 629 | 629 | |
| 630 | | void neosprite_base_device::set_pens(pen_t* pens) |
| 630 | void neosprite_base_device::set_pens(const pen_t* pens) |
| 631 | 631 | { |
| 632 | 632 | m_pens = pens; |
| 633 | 633 | } |
| r30689 | r30690 | |
| 670 | 670 | m_sprite_gfx_address_mask = mask; |
| 671 | 671 | } |
| 672 | 672 | |
| 673 | | inline void neosprite_regular_device::draw_pixel(int romaddr, UINT32* dst, pen_t *line_pens) |
| 673 | inline void neosprite_regular_device::draw_pixel(int romaddr, UINT32* dst, const pen_t *line_pens) |
| 674 | 674 | { |
| 675 | 675 | const UINT8* src = m_region_sprites->base() + (((romaddr &~0xff)>>1) | (((romaddr&0x8)^0x8)<<3) | ((romaddr & 0xf0) >> 2)); |
| 676 | 676 | const int x = romaddr & 0x7; |
| r30689 | r30690 | |
| 739 | 739 | } |
| 740 | 740 | } |
| 741 | 741 | |
| 742 | | inline void neosprite_optimized_device::draw_pixel(int romaddr, UINT32* dst, pen_t *line_pens) |
| 742 | inline void neosprite_optimized_device::draw_pixel(int romaddr, UINT32* dst, const pen_t *line_pens) |
| 743 | 743 | { |
| 744 | 744 | const UINT8 gfx = m_sprite_gfx[romaddr]; |
| 745 | 745 | |
| r30689 | r30690 | |
| 765 | 765 | } |
| 766 | 766 | |
| 767 | 767 | |
| 768 | | inline void neosprite_midas_device::draw_pixel(int romaddr, UINT32* dst, pen_t *line_pens) |
| 768 | inline void neosprite_midas_device::draw_pixel(int romaddr, UINT32* dst, const pen_t *line_pens) |
| 769 | 769 | { |
| 770 | 770 | const UINT8* src = m_region_sprites->base() + (((romaddr &~0xff)) | (((romaddr&0x8)^0x8)<<4) | ((romaddr & 0xf0) >> 1)); |
| 771 | 771 | const int x = romaddr & 0x7; |
| r30689 | r30690 | |
| 800 | 800 | memcpy(m_videoram_buffer, m_videoram, (0x8000 + 0x800) * sizeof(UINT16)); |
| 801 | 801 | } |
| 802 | 802 | |
| 803 | | inline void neosprite_midas_device::draw_fixed_layer_2pixels(UINT32*&pixel_addr, int offset, UINT8* gfx_base, pen_t* char_pens) |
| 803 | inline void neosprite_midas_device::draw_fixed_layer_2pixels(UINT32*&pixel_addr, int offset, UINT8* gfx_base, const pen_t* char_pens) |
| 804 | 804 | { |
| 805 | 805 | UINT8 data; |
| 806 | 806 | |
trunk/src/mame/video/neogeo_spr.h
| r30689 | r30690 | |
| 23 | 23 | // neosprite_base_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 24 | 24 | |
| 25 | 25 | virtual void optimize_sprite_data(); |
| 26 | | virtual void draw_fixed_layer_2pixels(UINT32*&pixel_addr, int offset, UINT8* gfx_base, pen_t* char_pens); |
| 26 | virtual void draw_fixed_layer_2pixels(UINT32*&pixel_addr, int offset, UINT8* gfx_base, const pen_t* char_pens); |
| 27 | 27 | void draw_fixed_layer( bitmap_rgb32 &bitmap, int scanline ); |
| 28 | 28 | void set_videoram_offset( UINT16 data ); |
| 29 | 29 | UINT16 get_videoram_data( ); |
| r30689 | r30690 | |
| 37 | 37 | void start_auto_animation_timer( ); |
| 38 | 38 | void neogeo_set_fixed_layer_source( UINT8 data ); |
| 39 | 39 | inline bool sprite_on_scanline(int scanline, int y, int rows); |
| 40 | | virtual void draw_pixel(int romaddr, UINT32* dst, pen_t *line_pens) = 0; |
| 40 | virtual void draw_pixel(int romaddr, UINT32* dst, const pen_t *line_pens) = 0; |
| 41 | 41 | void draw_sprites( bitmap_rgb32 &bitmap, int scanline ); |
| 42 | 42 | void parse_sprites( int scanline ); |
| 43 | 43 | void create_sprite_line_timer( ); |
| r30689 | r30690 | |
| 45 | 45 | virtual void set_sprite_region(memory_region* region_sprites); |
| 46 | 46 | void set_fixed_regions(memory_region* fix_cart, memory_region* fix_bios); |
| 47 | 47 | void set_screen(screen_device* screen); |
| 48 | | void set_pens(pen_t* pens); |
| 48 | void set_pens(const pen_t* pens); |
| 49 | 49 | |
| 50 | 50 | UINT16 *m_videoram; |
| 51 | 51 | UINT16 *m_videoram_drawsource; |
| r30689 | r30690 | |
| 83 | 83 | memory_region* m_region_fixed; |
| 84 | 84 | memory_region* m_region_fixedbios; |
| 85 | 85 | screen_device* m_screen; |
| 86 | | pen_t *m_pens; |
| 86 | const pen_t *m_pens; |
| 87 | 87 | |
| 88 | 88 | private: |
| 89 | 89 | |
| r30689 | r30690 | |
| 96 | 96 | { |
| 97 | 97 | public: |
| 98 | 98 | neosprite_regular_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 99 | | virtual void draw_pixel(int romaddr, UINT32* dst, pen_t *line_pens); |
| 99 | virtual void draw_pixel(int romaddr, UINT32* dst, const pen_t *line_pens); |
| 100 | 100 | virtual void set_sprite_region(memory_region* region_sprites); |
| 101 | 101 | |
| 102 | 102 | }; |
| r30689 | r30690 | |
| 109 | 109 | public: |
| 110 | 110 | neosprite_optimized_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 111 | 111 | virtual void optimize_sprite_data(); |
| 112 | | virtual void draw_pixel(int romaddr, UINT32* dst, pen_t *line_pens); |
| 112 | virtual void draw_pixel(int romaddr, UINT32* dst, const pen_t *line_pens); |
| 113 | 113 | dynamic_array<UINT8> m_sprite_gfx; |
| 114 | 114 | |
| 115 | 115 | }; |
| r30689 | r30690 | |
| 125 | 125 | public: |
| 126 | 126 | neosprite_midas_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 127 | 127 | |
| 128 | | virtual void draw_pixel(int romaddr, UINT32* dst, pen_t *line_pens); |
| 128 | virtual void draw_pixel(int romaddr, UINT32* dst, const pen_t *line_pens); |
| 129 | 129 | |
| 130 | 130 | UINT16* m_videoram_buffer; |
| 131 | 131 | void buffer_vram(); |
| 132 | | virtual void draw_fixed_layer_2pixels(UINT32*&pixel_addr, int offset, UINT8* gfx_base, pen_t* char_pens); |
| 132 | virtual void draw_fixed_layer_2pixels(UINT32*&pixel_addr, int offset, UINT8* gfx_base, const pen_t* char_pens); |
| 133 | 133 | virtual void set_sprite_region(memory_region* region_sprites); |
| 134 | 134 | |
| 135 | 135 | protected: |