src/mess/video/smsvdp.c
| r13435 | r13436 | |
| 42 | 42 | - bottom border 48 C0-EF 32 E0-FF 24 F0-07 |
| 43 | 43 | - bottom blanking 3 F0-F2 3 00-02 3 08-0A |
| 44 | 44 | |
| 45 | | TODO: |
| 46 | | - implement differences between SMS1_VDP & SMS_VDP/GG_VDP |
| 47 | | |
| 48 | 45 | */ |
| 49 | 46 | |
| 50 | 47 | #include "emu.h" |
| 51 | 48 | #include "video/smsvdp.h" |
| 49 | #include "machine/devhelpr.h" |
| 52 | 50 | |
| 53 | | #define IS_SMS1_VDP (smsvdp->m_features & MODEL_315_5124) |
| 54 | | #define IS_SMS2_VDP (smsvdp->m_features & MODEL_315_5246) |
| 55 | | #define IS_GAMEGEAR_VDP (smsvdp->m_features & MODEL_315_5378) |
| 56 | 51 | |
| 57 | 52 | #define STATUS_VINT 0x80 /* Pending vertical interrupt flag */ |
| 58 | 53 | #define STATUS_SPROVR 0x40 /* Sprite overflow flag */ |
| r13435 | r13436 | |
| 67 | 62 | #define SPRCOL_BASEHPOS 42 |
| 68 | 63 | #define DISPLAY_CB_HPOS 5 /* fix X-Scroll latchtime (Flubba's VDPTest) */ |
| 69 | 64 | |
| 70 | | #define GG_CRAM_SIZE 0x40 /* 32 colors x 2 bytes per color = 64 bytes */ |
| 71 | | #define SMS_CRAM_SIZE 0x20 /* 32 colors x 1 bytes per color = 32 bytes */ |
| 72 | | #define MAX_CRAM_SIZE 0x40 |
| 65 | #define SEGA315_5378_CRAM_SIZE 0x40 /* 32 colors x 2 bytes per color = 64 bytes */ |
| 66 | #define SEGA315_5124_CRAM_SIZE 0x20 /* 32 colors x 1 bytes per color = 32 bytes */ |
| 73 | 67 | |
| 74 | 68 | #define VRAM_SIZE 0x4000 |
| 75 | 69 | |
| 76 | 70 | #define PRIORITY_BIT 0x1000 |
| 77 | | #define BACKDROP_COLOR ((smsvdp->m_vdp_mode == 4 ? 0x10 : 0x00) + (smsvdp->m_reg[0x07] & 0x0f)) |
| 71 | #define BACKDROP_COLOR ((m_vdp_mode == 4 ? 0x10 : 0x00) + (m_reg[0x07] & 0x0f)) |
| 78 | 72 | |
| 79 | | #define NUM_OF_REGISTER 0x10 /* 16 registers */ |
| 80 | | |
| 81 | 73 | #define INIT_VCOUNT 0 |
| 82 | 74 | #define VERTICAL_BLANKING 1 |
| 83 | 75 | #define TOP_BLANKING 2 |
| r13435 | r13436 | |
| 86 | 78 | #define BOTTOM_BORDER 5 |
| 87 | 79 | #define BOTTOM_BLANKING 6 |
| 88 | 80 | |
| 89 | | static const UINT8 sms_ntsc_192[7] = { 0xd5, 3, 13, 27, 192, 24, 3 }; |
| 90 | | static const UINT8 sms_ntsc_224[7] = { 0xe5, 3, 13, 11, 224, 8, 3 }; |
| 91 | | static const UINT8 sms_ntsc_240[7] = { 0xee, 3, 13, 3, 240, 0, 3 }; |
| 92 | | static const UINT8 sms_pal_192[7] = { 0xba, 3, 13, 54, 192, 48, 3 }; |
| 93 | | static const UINT8 sms_pal_224[7] = { 0xca, 3, 13, 38, 224, 32, 3 }; |
| 94 | | static const UINT8 sms_pal_240[7] = { 0xd2, 3, 13, 30, 240, 24, 3 }; |
| 81 | static const UINT8 ntsc_192[7] = { 0xd5, 3, 13, 27, 192, 24, 3 }; |
| 82 | static const UINT8 ntsc_224[7] = { 0xe5, 3, 13, 11, 224, 8, 3 }; |
| 83 | static const UINT8 ntsc_240[7] = { 0xee, 3, 13, 3, 240, 0, 3 }; |
| 84 | static const UINT8 pal_192[7] = { 0xba, 3, 13, 54, 192, 48, 3 }; |
| 85 | static const UINT8 pal_224[7] = { 0xca, 3, 13, 38, 224, 32, 3 }; |
| 86 | static const UINT8 pal_240[7] = { 0xd2, 3, 13, 30, 240, 24, 3 }; |
| 95 | 87 | |
| 96 | 88 | |
| 97 | | typedef struct _smsvdp_t smsvdp_t; |
| 98 | | struct _smsvdp_t |
| 89 | const device_type SEGA315_5124 = &device_creator<sega315_5124_device>; |
| 90 | const device_type SEGA315_5246 = &device_creator<sega315_5246_device>; |
| 91 | const device_type SEGA315_5378 = &device_creator<sega315_5378_device>; |
| 92 | |
| 93 | |
| 94 | PALETTE_INIT( sega315_5124 ) |
| 99 | 95 | { |
| 100 | | UINT32 m_features; |
| 101 | | UINT8 m_reg[NUM_OF_REGISTER]; /* All the registers */ |
| 102 | | UINT8 m_status; /* Status register */ |
| 103 | | UINT8 m_reg9copy; /* Internal copy of register 9 */ |
| 104 | | UINT8 m_addrmode; /* Type of VDP action */ |
| 105 | | UINT16 m_addr; /* Contents of internal VDP address register */ |
| 106 | | UINT8 m_cram_mask; /* Mask to switch between SMS and GG CRAM sizes */ |
| 107 | | int m_cram_dirty; /* Have there been any changes to the CRAM area */ |
| 108 | | int m_pending; |
| 109 | | UINT8 m_buffer; |
| 110 | | int m_gg_sms_mode; /* Shrunk SMS screen on GG lcd mode flag */ |
| 111 | | int m_irq_state; /* The status of the IRQ line of the VDP */ |
| 112 | | int m_vdp_mode; /* Current mode of the VDP: 0,1,2,3,4 */ |
| 113 | | int m_y_pixels; /* 192, 224, 240 */ |
| 114 | | UINT8 m_line_counter; |
| 115 | | UINT8 m_hcounter; |
| 116 | | memory_region *m_VRAM; /* Pointer to VRAM */ |
| 117 | | memory_region *m_CRAM; /* Pointer to CRAM */ |
| 118 | | const UINT8 *m_sms_frame_timing; |
| 119 | | bitmap_t *m_tmpbitmap; |
| 120 | | UINT8 *m_collision_buffer; |
| 96 | int i; |
| 97 | for (i = 0; i < 64; i++) |
| 98 | { |
| 99 | int r = i & 0x03; |
| 100 | int g = (i & 0x0c) >> 2; |
| 101 | int b = (i & 0x30) >> 4; |
| 102 | palette_set_color_rgb(machine, i, r << 6, g << 6, b << 6); |
| 103 | } |
| 104 | /* TMS9918 palette */ |
| 105 | palette_set_color_rgb(machine, 64+ 0, 0, 0, 0); |
| 106 | palette_set_color_rgb(machine, 64+ 1, 0, 0, 0); |
| 107 | palette_set_color_rgb(machine, 64+ 2, 33, 200, 66); |
| 108 | palette_set_color_rgb(machine, 64+ 3, 94, 220, 120); |
| 109 | palette_set_color_rgb(machine, 64+ 4, 84, 85, 237); |
| 110 | palette_set_color_rgb(machine, 64+ 5, 125, 118, 252); |
| 111 | palette_set_color_rgb(machine, 64+ 6, 212, 82, 77); |
| 112 | palette_set_color_rgb(machine, 64+ 7, 66, 235, 245); |
| 113 | palette_set_color_rgb(machine, 64+ 8, 252, 85, 84); |
| 114 | palette_set_color_rgb(machine, 64+ 9, 255, 121, 120); |
| 115 | palette_set_color_rgb(machine, 64+10, 212, 193, 84); |
| 116 | palette_set_color_rgb(machine, 64+11, 230, 206, 128); |
| 117 | palette_set_color_rgb(machine, 64+12, 33, 176, 59); |
| 118 | palette_set_color_rgb(machine, 64+13, 201, 91, 186); |
| 119 | palette_set_color_rgb(machine, 64+14, 204, 204, 204); |
| 120 | palette_set_color_rgb(machine, 64+15, 255, 255, 255); |
| 121 | } |
| 121 | 122 | |
| 122 | | /* line_buffer will be used to hold 5 lines of line data. Line #0 is the regular blitting area. |
| 123 | | Lines #1-#4 will be used as a kind of cache to be used for vertical scaling in the gamegear |
| 124 | | sms compatibility mode. */ |
| 125 | | int *m_line_buffer; |
| 126 | | int m_current_palette[32]; |
| 127 | | devcb_resolved_write_line m_int_callback; |
| 128 | | devcb_resolved_write_line m_pause_callback; |
| 129 | | emu_timer *m_smsvdp_display_timer; |
| 130 | | screen_device *m_screen; |
| 131 | | }; |
| 132 | 123 | |
| 133 | | static TIMER_CALLBACK( smsvdp_display_callback ); |
| 134 | | static void sms_refresh_line( running_machine &machine, smsvdp_t *smsvdp, bitmap_t *bitmap, int offsetx, int offsety, int line ); |
| 135 | | static void sms_update_palette( smsvdp_t *smsvdp ); |
| 124 | PALETTE_INIT( sega315_5378 ) |
| 125 | { |
| 126 | int i; |
| 127 | for (i = 0; i < 4096; i++) |
| 128 | { |
| 129 | int r = i & 0x000f; |
| 130 | int g = (i & 0x00f0) >> 4; |
| 131 | int b = (i & 0x0f00) >> 8; |
| 132 | palette_set_color_rgb(machine, i, r << 4, g << 4, b << 4); |
| 133 | } |
| 134 | } |
| 136 | 135 | |
| 137 | 136 | |
| 138 | | /***************************************************************************** |
| 139 | | INLINE FUNCTIONS |
| 140 | | *****************************************************************************/ |
| 137 | sega315_5124_device::sega315_5124_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 138 | : device_t( mconfig, SEGA315_5124, "Sega 315-5124", tag, owner, clock ) |
| 139 | , m_cram_size( SEGA315_5124_CRAM_SIZE ) |
| 140 | , m_palette_offset( 0 ) |
| 141 | { |
| 142 | } |
| 141 | 143 | |
| 142 | | INLINE smsvdp_t *get_safe_token(device_t *device) |
| 144 | |
| 145 | sega315_5124_device::sega315_5124_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, UINT8 cram_size, UINT8 palette_offset) |
| 146 | : device_t( mconfig, type, name, tag, owner, clock ) |
| 147 | , m_cram_size( cram_size ) |
| 148 | , m_palette_offset( palette_offset ) |
| 143 | 149 | { |
| 144 | | assert(device != NULL); |
| 145 | | assert(device->type() == SMSVDP); |
| 150 | } |
| 146 | 151 | |
| 147 | | return (smsvdp_t *)downcast<legacy_device_base *>(device)->token(); |
| 152 | |
| 153 | sega315_5246_device::sega315_5246_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 154 | : sega315_5124_device( mconfig, SEGA315_5246, "Sega 315-5246", tag, owner, clock, SEGA315_5124_CRAM_SIZE, 0 ) |
| 155 | { |
| 148 | 156 | } |
| 149 | 157 | |
| 150 | | INLINE const smsvdp_interface *get_interface(device_t *device) |
| 158 | |
| 159 | sega315_5378_device::sega315_5378_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 160 | : sega315_5124_device( mconfig, SEGA315_5378, "Sega 315-5378", tag, owner, clock, SEGA315_5378_CRAM_SIZE, 0x10 ) |
| 151 | 161 | { |
| 152 | | assert(device != NULL); |
| 153 | | assert((device->type() == SMSVDP)); |
| 154 | | return (const smsvdp_interface *) device->static_config(); |
| 155 | 162 | } |
| 156 | 163 | |
| 157 | | /************************************* |
| 158 | | * |
| 159 | | * Utilities |
| 160 | | * |
| 161 | | *************************************/ |
| 162 | 164 | |
| 163 | | static void set_display_settings( device_t *device ) |
| 165 | void sega315_5124_device::set_display_settings() |
| 164 | 166 | { |
| 165 | | smsvdp_t *smsvdp = get_safe_token(device); |
| 167 | bool M1 = m_reg[0x01] & 0x10; |
| 168 | bool M2 = m_reg[0x00] & 0x02; |
| 169 | bool M3 = m_reg[0x01] & 0x08; |
| 170 | bool M4 = m_reg[0x00] & 0x04; |
| 166 | 171 | |
| 167 | | int height = smsvdp->m_screen->height(); |
| 168 | | int M1, M2, M3, M4; |
| 169 | | M1 = smsvdp->m_reg[0x01] & 0x10; |
| 170 | | M2 = smsvdp->m_reg[0x00] & 0x02; |
| 171 | | M3 = smsvdp->m_reg[0x01] & 0x08; |
| 172 | | M4 = smsvdp->m_reg[0x00] & 0x04; |
| 173 | | smsvdp->m_y_pixels = 192; |
| 172 | m_y_pixels = 192; |
| 173 | |
| 174 | 174 | if (M4) |
| 175 | 175 | { |
| 176 | 176 | /* mode 4 */ |
| 177 | | smsvdp->m_vdp_mode = 4; |
| 178 | | if (M2 && (IS_SMS2_VDP || IS_GAMEGEAR_VDP)) |
| 177 | m_vdp_mode = 4; |
| 178 | } |
| 179 | else |
| 180 | { |
| 181 | /* original TMS9918 mode */ |
| 182 | if (!M1 && !M2 && !M3) |
| 179 | 183 | { |
| 184 | m_vdp_mode = 0; |
| 185 | } |
| 186 | else |
| 187 | // if (M1 && !M2 && !M3) |
| 188 | // { |
| 189 | // m_vdp_mode = 1; |
| 190 | // } |
| 191 | // else |
| 192 | if (!M1 && M2 && !M3) |
| 193 | { |
| 194 | m_vdp_mode = 2; |
| 195 | // } |
| 196 | // else |
| 197 | // if (!M1 && !M2 && M3) |
| 198 | // { |
| 199 | // m_vdp_mode = 3; |
| 200 | } |
| 201 | else |
| 202 | { |
| 203 | logerror("Unknown video mode detected (M1 = %c, M2 = %c, M3 = %c, M4 = %c)\n", M1 ? '1' : '0', M2 ? '1' : '0', M3 ? '1' : '0', M4 ? '1' : '0'); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | switch (m_y_pixels) |
| 208 | { |
| 209 | case 192: |
| 210 | m_frame_timing = (m_is_pal) ? pal_192 : ntsc_192; |
| 211 | break; |
| 212 | |
| 213 | case 224: |
| 214 | m_frame_timing = (m_is_pal) ? pal_224 : ntsc_224; |
| 215 | break; |
| 216 | |
| 217 | case 240: |
| 218 | m_frame_timing = (m_is_pal) ? pal_240 : ntsc_240; |
| 219 | break; |
| 220 | } |
| 221 | m_cram_dirty = 1; |
| 222 | } |
| 223 | |
| 224 | |
| 225 | void sega315_5246_device::set_display_settings() |
| 226 | { |
| 227 | bool M1 = m_reg[0x01] & 0x10; |
| 228 | bool M2 = m_reg[0x00] & 0x02; |
| 229 | bool M3 = m_reg[0x01] & 0x08; |
| 230 | bool M4 = m_reg[0x00] & 0x04; |
| 231 | |
| 232 | m_y_pixels = 192; |
| 233 | |
| 234 | if (M4) |
| 235 | { |
| 236 | /* mode 4 */ |
| 237 | m_vdp_mode = 4; |
| 238 | if (M2) |
| 239 | { |
| 180 | 240 | if (M1 && !M3) |
| 181 | | smsvdp->m_y_pixels = 224; /* 224-line display */ |
| 241 | { |
| 242 | m_y_pixels = 224; /* 224-line display */ |
| 243 | } |
| 182 | 244 | else if (!M1 && M3) |
| 183 | | smsvdp->m_y_pixels = 240; /* 240-line display */ |
| 245 | { |
| 246 | m_y_pixels = 240; /* 240-line display */ |
| 247 | } |
| 184 | 248 | } |
| 185 | 249 | } |
| 186 | 250 | else |
| r13435 | r13436 | |
| 188 | 252 | /* original TMS9918 mode */ |
| 189 | 253 | if (!M1 && !M2 && !M3) |
| 190 | 254 | { |
| 191 | | smsvdp->m_vdp_mode = 0; |
| 255 | m_vdp_mode = 0; |
| 192 | 256 | } |
| 193 | 257 | else |
| 194 | 258 | // if (M1 && !M2 && !M3) |
| 195 | 259 | // { |
| 196 | | // smsvdp->m_vdp_mode = 1; |
| 260 | // m_vdp_mode = 1; |
| 197 | 261 | // } |
| 198 | 262 | // else |
| 199 | 263 | if (!M1 && M2 && !M3) |
| 200 | 264 | { |
| 201 | | smsvdp->m_vdp_mode = 2; |
| 265 | m_vdp_mode = 2; |
| 202 | 266 | // } |
| 203 | 267 | // else |
| 204 | 268 | // if (!M1 && !M2 && M3) |
| 205 | 269 | // { |
| 206 | | // smsvdp->m_vdp_mode = 3; |
| 270 | // m_vdp_mode = 3; |
| 207 | 271 | } |
| 208 | 272 | else |
| 209 | 273 | { |
| r13435 | r13436 | |
| 211 | 275 | } |
| 212 | 276 | } |
| 213 | 277 | |
| 214 | | switch (smsvdp->m_y_pixels) |
| 278 | switch (m_y_pixels) |
| 215 | 279 | { |
| 216 | 280 | case 192: |
| 217 | | smsvdp->m_sms_frame_timing = (height == SMS_PAL_Y_PIXELS) ? sms_pal_192 : sms_ntsc_192; |
| 281 | m_frame_timing = (m_is_pal) ? pal_192 : ntsc_192; |
| 218 | 282 | break; |
| 219 | 283 | |
| 220 | 284 | case 224: |
| 221 | | smsvdp->m_sms_frame_timing = (height == SMS_PAL_Y_PIXELS) ? sms_pal_224 : sms_ntsc_224; |
| 285 | m_frame_timing = (m_is_pal) ? pal_224 : ntsc_224; |
| 222 | 286 | break; |
| 223 | 287 | |
| 224 | 288 | case 240: |
| 225 | | smsvdp->m_sms_frame_timing = (height == SMS_PAL_Y_PIXELS) ? sms_pal_240 : sms_ntsc_240; |
| 289 | m_frame_timing = (m_is_pal) ? pal_240 : ntsc_240; |
| 226 | 290 | break; |
| 227 | 291 | } |
| 228 | | smsvdp->m_cram_dirty = 1; |
| 292 | m_cram_dirty = 1; |
| 229 | 293 | } |
| 230 | 294 | |
| 231 | 295 | |
| 232 | | READ8_DEVICE_HANDLER( sms_vdp_vcount_r ) |
| 296 | void sega315_5378_device::set_display_settings() |
| 233 | 297 | { |
| 234 | | smsvdp_t *smsvdp = get_safe_token(device); |
| 235 | | int vpos = smsvdp->m_screen->vpos(); |
| 298 | bool M1 = m_reg[0x01] & 0x10; |
| 299 | bool M2 = m_reg[0x00] & 0x02; |
| 300 | bool M3 = m_reg[0x01] & 0x08; |
| 301 | bool M4 = m_reg[0x00] & 0x04; |
| 236 | 302 | |
| 237 | | if (smsvdp->m_screen->hpos() < VCOUNT_CHANGE_HPOS) |
| 303 | m_y_pixels = 192; |
| 304 | |
| 305 | if (M4) |
| 238 | 306 | { |
| 239 | | vpos--; |
| 240 | | if (vpos < 0) |
| 241 | | vpos += smsvdp->m_screen->height(); |
| 307 | /* mode 4 */ |
| 308 | m_vdp_mode = 4; |
| 309 | if (M2) |
| 310 | { |
| 311 | if (M1 && !M3) |
| 312 | { |
| 313 | m_y_pixels = 224; /* 224-line display */ |
| 314 | } |
| 315 | else if (!M1 && M3) |
| 316 | { |
| 317 | m_y_pixels = 240; /* 240-line display */ |
| 318 | } |
| 319 | } |
| 242 | 320 | } |
| 321 | else |
| 322 | { |
| 323 | /* original TMS9918 mode */ |
| 324 | if (!M1 && !M2 && !M3) |
| 325 | { |
| 326 | m_vdp_mode = 0; |
| 327 | } |
| 328 | else |
| 329 | // if (M1 && !M2 && !M3) |
| 330 | // { |
| 331 | // m_vdp_mode = 1; |
| 332 | // } |
| 333 | // else |
| 334 | if (!M1 && M2 && !M3) |
| 335 | { |
| 336 | m_vdp_mode = 2; |
| 337 | // } |
| 338 | // else |
| 339 | // if (!M1 && !M2 && M3) |
| 340 | // { |
| 341 | // m_vdp_mode = 3; |
| 342 | } |
| 343 | else |
| 344 | { |
| 345 | logerror("Unknown video mode detected (M1 = %c, M2 = %c, M3 = %c, M4 = %c)\n", M1 ? '1' : '0', M2 ? '1' : '0', M3 ? '1' : '0', M4 ? '1' : '0'); |
| 346 | } |
| 347 | } |
| 243 | 348 | |
| 244 | | return (smsvdp->m_sms_frame_timing[INIT_VCOUNT] + vpos) & 0xff; |
| 349 | switch (m_y_pixels) |
| 350 | { |
| 351 | case 192: |
| 352 | m_frame_timing = (m_is_pal) ? pal_192 : ntsc_192; |
| 353 | break; |
| 354 | |
| 355 | case 224: |
| 356 | m_frame_timing = (m_is_pal) ? pal_224 : ntsc_224; |
| 357 | break; |
| 358 | |
| 359 | case 240: |
| 360 | m_frame_timing = (m_is_pal) ? pal_240 : ntsc_240; |
| 361 | break; |
| 362 | } |
| 363 | m_cram_dirty = 1; |
| 245 | 364 | } |
| 246 | 365 | |
| 247 | 366 | |
| 248 | | READ8_DEVICE_HANDLER( sms_vdp_hcount_latch_r ) |
| 367 | READ8_MEMBER( sega315_5124_device::vcount_read ) |
| 249 | 368 | { |
| 250 | | smsvdp_t *smsvdp = get_safe_token(device); |
| 369 | int vpos = m_screen->vpos(); |
| 251 | 370 | |
| 252 | | return smsvdp->m_hcounter; |
| 371 | if (m_screen->hpos() < VCOUNT_CHANGE_HPOS) |
| 372 | { |
| 373 | vpos--; |
| 374 | if (vpos < 0) |
| 375 | vpos += m_screen->height(); |
| 376 | } |
| 377 | |
| 378 | return (m_frame_timing[INIT_VCOUNT] + vpos) & 0xff; |
| 253 | 379 | } |
| 254 | 380 | |
| 255 | | WRITE8_DEVICE_HANDLER( sms_vdp_hcount_latch_w ) |
| 381 | |
| 382 | READ8_MEMBER( sega315_5124_device::hcount_latch_read ) |
| 256 | 383 | { |
| 257 | | smsvdp_t *smsvdp = get_safe_token(device); |
| 258 | | |
| 259 | | smsvdp->m_hcounter = data; |
| 384 | return m_hcounter; |
| 260 | 385 | } |
| 261 | 386 | |
| 262 | 387 | |
| 263 | | void sms_vdp_set_ggsmsmode( device_t *device, int mode ) |
| 388 | WRITE8_MEMBER( sega315_5124_device::hcount_latch_write ) |
| 264 | 389 | { |
| 265 | | smsvdp_t *smsvdp = get_safe_token(device); |
| 266 | | |
| 267 | | smsvdp->m_gg_sms_mode = mode; |
| 268 | | smsvdp->m_cram_mask = (IS_GAMEGEAR_VDP && !smsvdp->m_gg_sms_mode) ? (GG_CRAM_SIZE - 1) : (SMS_CRAM_SIZE - 1); |
| 390 | m_hcounter = data; |
| 269 | 391 | } |
| 270 | 392 | |
| 271 | 393 | |
| 272 | | static TIMER_CALLBACK( smsvdp_set_status ) |
| 394 | void sega315_5378_device::set_gg_sms_mode( int mode ) |
| 273 | 395 | { |
| 274 | | smsvdp_t *smsvdp = (smsvdp_t *) ptr; |
| 275 | | |
| 276 | | smsvdp->m_status |= (UINT8) param; |
| 396 | m_gg_sms_mode = mode; |
| 397 | m_cram_mask = (!m_gg_sms_mode) ? (SEGA315_5378_CRAM_SIZE - 1) : (SEGA315_5124_CRAM_SIZE - 1); |
| 277 | 398 | } |
| 278 | 399 | |
| 279 | 400 | |
| 280 | | static TIMER_CALLBACK( smsvdp_check_hint ) |
| 401 | void sega315_5124_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 281 | 402 | { |
| 282 | | smsvdp_t *smsvdp = (smsvdp_t *) ptr; |
| 283 | | |
| 284 | | if (smsvdp->m_line_counter == 0x00) |
| 403 | switch( id ) |
| 285 | 404 | { |
| 286 | | smsvdp->m_line_counter = smsvdp->m_reg[0x0a]; |
| 287 | | smsvdp->m_status |= STATUS_HINT; |
| 288 | | } |
| 289 | | else |
| 290 | | { |
| 291 | | smsvdp->m_line_counter--; |
| 292 | | } |
| 405 | case TIMER_LINE: |
| 406 | process_line_timer(); |
| 407 | break; |
| 293 | 408 | |
| 294 | | if ((smsvdp->m_status & STATUS_HINT) && (smsvdp->m_reg[0x00] & 0x10)) |
| 295 | | { |
| 296 | | smsvdp->m_irq_state = 1; |
| 409 | case TIMER_SET_STATUS_VINT: |
| 410 | m_status |= STATUS_VINT; |
| 411 | break; |
| 297 | 412 | |
| 298 | | smsvdp->m_int_callback(ASSERT_LINE); |
| 299 | | } |
| 300 | | } |
| 413 | case TIMER_SET_STATUS_SPROVR: |
| 414 | m_status |= STATUS_SPROVR; |
| 415 | break; |
| 301 | 416 | |
| 417 | case TIMER_CHECK_HINT: |
| 418 | if (m_line_counter == 0x00) |
| 419 | { |
| 420 | m_line_counter = m_reg[0x0a]; |
| 421 | m_status |= STATUS_HINT; |
| 422 | } |
| 423 | else |
| 424 | { |
| 425 | m_line_counter--; |
| 426 | } |
| 302 | 427 | |
| 303 | | static TIMER_CALLBACK( smsvdp_check_vint ) |
| 304 | | { |
| 305 | | smsvdp_t *smsvdp = (smsvdp_t *) ptr; |
| 428 | if ((m_status & STATUS_HINT) && (m_reg[0x00] & 0x10)) |
| 429 | { |
| 430 | m_irq_state = 1; |
| 306 | 431 | |
| 307 | | if ((smsvdp->m_status & STATUS_VINT) && (smsvdp->m_reg[0x01] & 0x20)) |
| 308 | | { |
| 309 | | smsvdp->m_irq_state = 1; |
| 432 | if ( !m_cb_int.isnull() ) |
| 433 | m_cb_int(ASSERT_LINE); |
| 434 | } |
| 435 | break; |
| 310 | 436 | |
| 311 | | smsvdp->m_int_callback(ASSERT_LINE); |
| 437 | case TIMER_CHECK_VINT: |
| 438 | if ((m_status & STATUS_VINT) && (m_reg[0x01] & 0x20)) |
| 439 | { |
| 440 | m_irq_state = 1; |
| 441 | |
| 442 | if ( !m_cb_int.isnull() ) |
| 443 | m_cb_int(ASSERT_LINE); |
| 444 | } |
| 445 | break; |
| 312 | 446 | } |
| 313 | 447 | } |
| 314 | 448 | |
| 315 | 449 | |
| 316 | | static TIMER_CALLBACK( smsvdp_display_callback ) |
| 450 | void sega315_5124_device::process_line_timer() |
| 317 | 451 | { |
| 318 | | smsvdp_t *smsvdp = (smsvdp_t *) ptr; |
| 319 | | |
| 320 | 452 | rectangle rec; |
| 321 | | int vpos = smsvdp->m_screen->vpos(); |
| 322 | | int vpos_limit = smsvdp->m_sms_frame_timing[VERTICAL_BLANKING] + smsvdp->m_sms_frame_timing[TOP_BLANKING] |
| 323 | | + smsvdp->m_sms_frame_timing[TOP_BORDER] + smsvdp->m_sms_frame_timing[ACTIVE_DISPLAY_V] |
| 324 | | + smsvdp->m_sms_frame_timing[BOTTOM_BORDER] + smsvdp->m_sms_frame_timing[BOTTOM_BLANKING]; |
| 453 | int vpos = m_screen->vpos(); |
| 454 | int vpos_limit = m_frame_timing[VERTICAL_BLANKING] + m_frame_timing[TOP_BLANKING] |
| 455 | + m_frame_timing[TOP_BORDER] + m_frame_timing[ACTIVE_DISPLAY_V] |
| 456 | + m_frame_timing[BOTTOM_BORDER] + m_frame_timing[BOTTOM_BLANKING]; |
| 325 | 457 | |
| 326 | 458 | rec.min_y = rec.max_y = vpos; |
| 327 | 459 | |
| 328 | 460 | /* Check if we're on the last line of a frame */ |
| 329 | 461 | if (vpos == vpos_limit - 1) |
| 330 | 462 | { |
| 331 | | smsvdp->m_line_counter = smsvdp->m_reg[0x0a]; |
| 332 | | smsvdp->m_pause_callback(0); |
| 463 | m_line_counter = m_reg[0x0a]; |
| 464 | if ( !m_cb_pause.isnull() ) |
| 465 | m_cb_pause(0); |
| 333 | 466 | |
| 334 | 467 | return; |
| 335 | 468 | } |
| 336 | 469 | |
| 337 | | vpos_limit -= smsvdp->m_sms_frame_timing[BOTTOM_BLANKING]; |
| 470 | vpos_limit -= m_frame_timing[BOTTOM_BLANKING]; |
| 338 | 471 | |
| 339 | 472 | /* Check if we're below the bottom border */ |
| 340 | 473 | if (vpos >= vpos_limit) |
| 341 | 474 | { |
| 342 | | smsvdp->m_line_counter = smsvdp->m_reg[0x0a]; |
| 475 | m_line_counter = m_reg[0x0a]; |
| 343 | 476 | return; |
| 344 | 477 | } |
| 345 | 478 | |
| 346 | | vpos_limit -= smsvdp->m_sms_frame_timing[BOTTOM_BORDER]; |
| 479 | vpos_limit -= m_frame_timing[BOTTOM_BORDER]; |
| 347 | 480 | |
| 348 | 481 | /* Check if we're in the bottom border area */ |
| 349 | 482 | if (vpos >= vpos_limit) |
| 350 | 483 | { |
| 351 | 484 | if (vpos == vpos_limit) |
| 352 | 485 | { |
| 353 | | machine.scheduler().timer_set(smsvdp->m_screen->time_until_pos(vpos, HINT_HPOS), FUNC(smsvdp_check_hint),0 ,smsvdp); |
| 486 | m_check_hint_timer->adjust( m_screen->time_until_pos( vpos, HINT_HPOS ) ); |
| 354 | 487 | } |
| 355 | 488 | else |
| 356 | 489 | { |
| 357 | | smsvdp->m_line_counter = smsvdp->m_reg[0x0a]; |
| 490 | m_line_counter = m_reg[0x0a]; |
| 358 | 491 | } |
| 359 | 492 | |
| 360 | 493 | if (vpos == vpos_limit + 1) |
| 361 | 494 | { |
| 362 | | machine.scheduler().timer_set(smsvdp->m_screen->time_until_pos(vpos, VINT_FLAG_HPOS), FUNC(smsvdp_set_status), (int)STATUS_VINT, smsvdp); |
| 363 | | machine.scheduler().timer_set(smsvdp->m_screen->time_until_pos(vpos, VINT_HPOS), FUNC(smsvdp_check_vint), 0, smsvdp); |
| 495 | m_set_status_vint_timer->adjust( m_screen->time_until_pos( vpos, VINT_FLAG_HPOS ) ); |
| 496 | m_check_vint_timer->adjust( m_screen->time_until_pos( vpos, VINT_HPOS ) ); |
| 364 | 497 | } |
| 365 | 498 | |
| 366 | | sms_update_palette(smsvdp); |
| 499 | update_palette(); |
| 367 | 500 | |
| 368 | 501 | /* Draw left border */ |
| 369 | 502 | rec.min_x = SMS_LBORDER_START; |
| 370 | 503 | rec.max_x = SMS_LBORDER_START + SMS_LBORDER_X_PIXELS - 1; |
| 371 | | bitmap_fill(smsvdp->m_tmpbitmap, &rec, machine.pens[smsvdp->m_current_palette[BACKDROP_COLOR]]); |
| 504 | bitmap_fill(m_tmpbitmap, &rec, machine().pens[m_current_palette[BACKDROP_COLOR]]); |
| 372 | 505 | |
| 373 | 506 | /* Draw right border */ |
| 374 | 507 | rec.min_x = SMS_LBORDER_START + SMS_LBORDER_X_PIXELS + 256; |
| 375 | 508 | rec.max_x = rec.min_x + SMS_RBORDER_X_PIXELS - 1; |
| 376 | | bitmap_fill(smsvdp->m_tmpbitmap, &rec, machine.pens[smsvdp->m_current_palette[BACKDROP_COLOR]]); |
| 509 | bitmap_fill(m_tmpbitmap, &rec, machine().pens[m_current_palette[BACKDROP_COLOR]]); |
| 377 | 510 | |
| 378 | 511 | /* Draw middle of the border */ |
| 379 | 512 | /* We need to do this through the regular drawing function so it will */ |
| 380 | 513 | /* be included in the gamegear scaling functions */ |
| 381 | | sms_refresh_line(machine, smsvdp, smsvdp->m_tmpbitmap, SMS_LBORDER_START + SMS_LBORDER_X_PIXELS, vpos_limit - smsvdp->m_sms_frame_timing[ACTIVE_DISPLAY_V], vpos - (vpos_limit - smsvdp->m_sms_frame_timing[ACTIVE_DISPLAY_V])); |
| 514 | refresh_line( SMS_LBORDER_START + SMS_LBORDER_X_PIXELS, vpos_limit - m_frame_timing[ACTIVE_DISPLAY_V], vpos - (vpos_limit - m_frame_timing[ACTIVE_DISPLAY_V]) ); |
| 382 | 515 | return; |
| 383 | 516 | } |
| 384 | 517 | |
| 385 | | vpos_limit -= smsvdp->m_sms_frame_timing[ACTIVE_DISPLAY_V]; |
| 518 | vpos_limit -= m_frame_timing[ACTIVE_DISPLAY_V]; |
| 386 | 519 | |
| 387 | 520 | /* Check if we're in the active display area */ |
| 388 | 521 | if (vpos >= vpos_limit) |
| 389 | 522 | { |
| 390 | 523 | if (vpos == vpos_limit) |
| 391 | 524 | { |
| 392 | | smsvdp->m_reg9copy = smsvdp->m_reg[0x09]; |
| 525 | m_reg9copy = m_reg[0x09]; |
| 393 | 526 | } |
| 394 | 527 | |
| 395 | | machine.scheduler().timer_set(smsvdp->m_screen->time_until_pos(vpos, HINT_HPOS), FUNC(smsvdp_check_hint),0, smsvdp); |
| 528 | m_check_hint_timer->adjust( m_screen->time_until_pos( vpos, HINT_HPOS ) ); |
| 396 | 529 | |
| 397 | | sms_update_palette(smsvdp); |
| 530 | update_palette(); |
| 398 | 531 | |
| 399 | 532 | /* Draw left border */ |
| 400 | 533 | rec.min_x = SMS_LBORDER_START; |
| 401 | 534 | rec.max_x = SMS_LBORDER_START + SMS_LBORDER_X_PIXELS - 1; |
| 402 | | bitmap_fill(smsvdp->m_tmpbitmap, &rec, machine.pens[smsvdp->m_current_palette[BACKDROP_COLOR]]); |
| 535 | bitmap_fill(m_tmpbitmap, &rec, machine().pens[m_current_palette[BACKDROP_COLOR]]); |
| 403 | 536 | |
| 404 | 537 | /* Draw right border */ |
| 405 | 538 | rec.min_x = SMS_LBORDER_START + SMS_LBORDER_X_PIXELS + 256; |
| 406 | 539 | rec.max_x = rec.min_x + SMS_RBORDER_X_PIXELS - 1; |
| 407 | | bitmap_fill(smsvdp->m_tmpbitmap, &rec, machine.pens[smsvdp->m_current_palette[BACKDROP_COLOR]]); |
| 540 | bitmap_fill(m_tmpbitmap, &rec, machine().pens[m_current_palette[BACKDROP_COLOR]]); |
| 408 | 541 | |
| 409 | | sms_refresh_line(machine, smsvdp, smsvdp->m_tmpbitmap, SMS_LBORDER_START + SMS_LBORDER_X_PIXELS, vpos_limit, vpos - vpos_limit); |
| 542 | refresh_line( SMS_LBORDER_START + SMS_LBORDER_X_PIXELS, vpos_limit, vpos - vpos_limit ); |
| 410 | 543 | |
| 411 | 544 | return; |
| 412 | 545 | } |
| 413 | 546 | |
| 414 | | vpos_limit -= smsvdp->m_sms_frame_timing[TOP_BORDER]; |
| 547 | vpos_limit -= m_frame_timing[TOP_BORDER]; |
| 415 | 548 | |
| 416 | 549 | /* Check if we're in the top border area */ |
| 417 | 550 | if (vpos >= vpos_limit) |
| 418 | 551 | { |
| 419 | | smsvdp->m_line_counter = smsvdp->m_reg[0x0a]; |
| 420 | | sms_update_palette(smsvdp); |
| 552 | m_line_counter = m_reg[0x0a]; |
| 553 | update_palette(); |
| 421 | 554 | |
| 422 | 555 | /* Draw left border */ |
| 423 | 556 | rec.min_x = SMS_LBORDER_START; |
| 424 | 557 | rec.max_x = SMS_LBORDER_START + SMS_LBORDER_X_PIXELS - 1; |
| 425 | | bitmap_fill(smsvdp->m_tmpbitmap, &rec, machine.pens[smsvdp->m_current_palette[BACKDROP_COLOR]]); |
| 558 | bitmap_fill(m_tmpbitmap, &rec, machine().pens[m_current_palette[BACKDROP_COLOR]]); |
| 426 | 559 | |
| 427 | 560 | /* Draw right border */ |
| 428 | 561 | rec.min_x = SMS_LBORDER_START + SMS_LBORDER_X_PIXELS + 256; |
| 429 | 562 | rec.max_x = rec.min_x + SMS_RBORDER_X_PIXELS - 1; |
| 430 | | bitmap_fill(smsvdp->m_tmpbitmap, &rec, machine.pens[smsvdp->m_current_palette[BACKDROP_COLOR]]); |
| 563 | bitmap_fill(m_tmpbitmap, &rec, machine().pens[m_current_palette[BACKDROP_COLOR]]); |
| 431 | 564 | |
| 432 | 565 | /* Draw middle of the border */ |
| 433 | 566 | /* We need to do this through the regular drawing function so it will */ |
| 434 | 567 | /* be included in the gamegear scaling functions */ |
| 435 | | sms_refresh_line(machine, smsvdp, smsvdp->m_tmpbitmap, SMS_LBORDER_START + SMS_LBORDER_X_PIXELS, vpos_limit + smsvdp->m_sms_frame_timing[TOP_BORDER], vpos - (vpos_limit + smsvdp->m_sms_frame_timing[TOP_BORDER])); |
| 568 | refresh_line( SMS_LBORDER_START + SMS_LBORDER_X_PIXELS, vpos_limit + m_frame_timing[TOP_BORDER], vpos - (vpos_limit + m_frame_timing[TOP_BORDER]) ); |
| 436 | 569 | return; |
| 437 | 570 | } |
| 438 | 571 | |
| 439 | 572 | /* we're in the vertical or top blanking area */ |
| 440 | | smsvdp->m_line_counter = smsvdp->m_reg[0x0a]; |
| 573 | m_line_counter = m_reg[0x0a]; |
| 441 | 574 | } |
| 442 | 575 | |
| 443 | 576 | |
| 444 | | READ8_DEVICE_HANDLER( sms_vdp_data_r ) |
| 577 | READ8_MEMBER( sega315_5124_device::vram_read ) |
| 445 | 578 | { |
| 446 | | smsvdp_t *smsvdp = get_safe_token(device); |
| 447 | 579 | UINT8 temp; |
| 448 | 580 | |
| 449 | 581 | /* SMS 2 & GG behaviour. Seems like the latched data is passed straight through */ |
| 450 | 582 | /* to the address register when in the middle of doing a command. */ |
| 451 | 583 | /* Cosmic Spacehead needs this, among others */ |
| 452 | 584 | /* Clear pending write flag */ |
| 453 | | smsvdp->m_pending = 0; |
| 585 | m_pending = 0; |
| 454 | 586 | |
| 455 | 587 | /* Return read buffer contents */ |
| 456 | | temp = smsvdp->m_buffer; |
| 588 | temp = m_buffer; |
| 457 | 589 | |
| 458 | 590 | /* Load read buffer */ |
| 459 | | smsvdp->m_buffer = smsvdp->m_VRAM->u8((smsvdp->m_addr & 0x3fff)); |
| 591 | m_buffer = m_VRAM->u8(m_addr & 0x3fff); |
| 460 | 592 | |
| 461 | 593 | /* Bump internal address register */ |
| 462 | | smsvdp->m_addr += 1; |
| 594 | m_addr += 1; |
| 463 | 595 | return temp; |
| 464 | 596 | } |
| 465 | 597 | |
| 466 | 598 | |
| 467 | | READ8_DEVICE_HANDLER( sms_vdp_ctrl_r ) |
| 599 | READ8_MEMBER( sega315_5124_device::register_read ) |
| 468 | 600 | { |
| 469 | | smsvdp_t *smsvdp = get_safe_token(device); |
| 601 | UINT8 temp = m_status; |
| 470 | 602 | |
| 471 | | UINT8 temp = smsvdp->m_status; |
| 472 | | |
| 473 | 603 | /* Clear pending write flag */ |
| 474 | | smsvdp->m_pending = 0; |
| 604 | m_pending = 0; |
| 475 | 605 | |
| 476 | | smsvdp->m_status &= ~(STATUS_VINT | STATUS_SPROVR | STATUS_SPRCOL | STATUS_HINT); |
| 606 | m_status &= ~(STATUS_VINT | STATUS_SPROVR | STATUS_SPRCOL | STATUS_HINT); |
| 477 | 607 | |
| 478 | | if (smsvdp->m_irq_state == 1) |
| 608 | if (m_irq_state == 1) |
| 479 | 609 | { |
| 480 | | smsvdp->m_irq_state = 0; |
| 610 | m_irq_state = 0; |
| 481 | 611 | |
| 482 | | smsvdp->m_int_callback(CLEAR_LINE); |
| 612 | if ( !m_cb_int.isnull() ) |
| 613 | m_cb_int(CLEAR_LINE); |
| 483 | 614 | } |
| 484 | 615 | |
| 485 | 616 | /* low 5 bits return non-zero data (it fixes PGA Tour Golf course map introduction) */ |
| r13435 | r13436 | |
| 487 | 618 | } |
| 488 | 619 | |
| 489 | 620 | |
| 490 | | WRITE8_DEVICE_HANDLER( sms_vdp_data_w ) |
| 621 | WRITE8_MEMBER( sega315_5124_device::vram_write ) |
| 491 | 622 | { |
| 492 | | smsvdp_t *smsvdp = get_safe_token(device); |
| 493 | | int address; |
| 494 | | |
| 495 | 623 | /* SMS 2 & GG behaviour. Seems like the latched data is passed straight through */ |
| 496 | 624 | /* to the address register when in the middle of doing a command. */ |
| 497 | 625 | /* Cosmic Spacehead needs this, among others */ |
| 498 | 626 | /* Clear pending write flag */ |
| 499 | | smsvdp->m_pending = 0; |
| 627 | m_pending = 0; |
| 500 | 628 | |
| 501 | | switch(smsvdp->m_addrmode) |
| 629 | switch(m_addrmode) |
| 502 | 630 | { |
| 503 | 631 | case 0x00: |
| 504 | 632 | case 0x01: |
| 505 | 633 | case 0x02: |
| 506 | | address = (smsvdp->m_addr & 0x3fff); |
| 507 | | smsvdp->m_VRAM->u8(address) = data; |
| 634 | m_VRAM->u8(m_addr & 0x3fff) = data; |
| 508 | 635 | break; |
| 509 | 636 | |
| 510 | 637 | case 0x03: |
| 511 | | address = smsvdp->m_addr & smsvdp->m_cram_mask; |
| 512 | | if (data != smsvdp->m_CRAM->u8(address)) |
| 513 | 638 | { |
| 514 | | smsvdp->m_CRAM->u8(address) = data; |
| 515 | | smsvdp->m_cram_dirty = 1; |
| 639 | UINT16 address = m_addr & m_cram_mask; |
| 640 | if (data != m_CRAM->u8(address)) |
| 641 | { |
| 642 | m_CRAM->u8(address) = data; |
| 643 | m_cram_dirty = 1; |
| 644 | } |
| 516 | 645 | } |
| 517 | 646 | break; |
| 518 | 647 | } |
| 519 | 648 | |
| 520 | | smsvdp->m_buffer = data; |
| 521 | | smsvdp->m_addr += 1; |
| 649 | m_buffer = data; |
| 650 | m_addr += 1; |
| 522 | 651 | } |
| 523 | 652 | |
| 524 | 653 | |
| 525 | | WRITE8_DEVICE_HANDLER( sms_vdp_ctrl_w ) |
| 654 | WRITE8_MEMBER( sega315_5124_device::register_write ) |
| 526 | 655 | { |
| 527 | | smsvdp_t *smsvdp = get_safe_token(device); |
| 528 | | |
| 529 | 656 | int reg_num; |
| 530 | 657 | |
| 531 | | if (smsvdp->m_pending == 0) |
| 658 | if (m_pending == 0) |
| 532 | 659 | { |
| 533 | | smsvdp->m_addr = (smsvdp->m_addr & 0xff00) | data; |
| 534 | | smsvdp->m_pending = 1; |
| 660 | m_addr = (m_addr & 0xff00) | data; |
| 661 | m_pending = 1; |
| 535 | 662 | } |
| 536 | 663 | else |
| 537 | 664 | { |
| 538 | 665 | /* Clear pending write flag */ |
| 539 | | smsvdp->m_pending = 0; |
| 666 | m_pending = 0; |
| 540 | 667 | |
| 541 | | smsvdp->m_addrmode = (data >> 6) & 0x03; |
| 542 | | smsvdp->m_addr = (data << 8) | (smsvdp->m_addr & 0xff); |
| 543 | | switch (smsvdp->m_addrmode) |
| 668 | m_addrmode = (data >> 6) & 0x03; |
| 669 | m_addr = (data << 8) | (m_addr & 0xff); |
| 670 | switch (m_addrmode) |
| 544 | 671 | { |
| 545 | 672 | case 0: /* VRAM reading mode */ |
| 546 | | smsvdp->m_buffer = smsvdp->m_VRAM->u8(smsvdp->m_addr & 0x3fff); |
| 547 | | smsvdp->m_addr += 1; |
| 673 | m_buffer = m_VRAM->u8(m_addr & 0x3fff); |
| 674 | m_addr += 1; |
| 548 | 675 | break; |
| 549 | 676 | |
| 550 | 677 | case 1: /* VRAM writing mode */ |
| r13435 | r13436 | |
| 552 | 679 | |
| 553 | 680 | case 2: /* VDP register write */ |
| 554 | 681 | reg_num = data & 0x0f; |
| 555 | | smsvdp->m_reg[reg_num] = smsvdp->m_addr & 0xff; |
| 556 | | if (reg_num == 0 && smsvdp->m_addr & 0x02) |
| 682 | m_reg[reg_num] = m_addr & 0xff; |
| 683 | if ( reg_num == 0 && ( m_addr & 0x02 ) ) |
| 557 | 684 | logerror("overscan enabled.\n"); |
| 558 | 685 | |
| 559 | 686 | if (reg_num == 0 || reg_num == 1) |
| 560 | | set_display_settings(device); |
| 687 | set_display_settings(); |
| 561 | 688 | |
| 562 | 689 | if (reg_num == 1) |
| 563 | 690 | { |
| 564 | | device->machine().scheduler().timer_set(smsvdp->m_screen->time_until_pos(smsvdp->m_screen->vpos(), VINT_HPOS), FUNC(smsvdp_check_vint),0 ,smsvdp); |
| 691 | m_check_vint_timer->adjust( m_screen->time_until_pos( m_screen->vpos(), VINT_HPOS) ); |
| 565 | 692 | } |
| 566 | | smsvdp->m_addrmode = 0; |
| 693 | m_addrmode = 0; |
| 567 | 694 | break; |
| 568 | 695 | |
| 569 | 696 | case 3: /* CRAM writing mode */ |
| r13435 | r13436 | |
| 573 | 700 | } |
| 574 | 701 | |
| 575 | 702 | |
| 576 | | static void sms_refresh_line_mode4( smsvdp_t *smsvdp, int *line_buffer, int *priority_selected, int line ) |
| 703 | UINT16 sega315_5124_device::get_name_table_address() |
| 577 | 704 | { |
| 578 | | int tile_column; |
| 579 | | int x_scroll, y_scroll, x_scroll_start_column; |
| 580 | | int pixel_x, pixel_plot_x; |
| 581 | | int bit_plane_0, bit_plane_1, bit_plane_2, bit_plane_3; |
| 582 | | int scroll_mod; |
| 583 | | UINT16 name_table_address; |
| 584 | | UINT8 *name_table; |
| 705 | UINT16 result; |
| 585 | 706 | |
| 586 | | if (smsvdp->m_y_pixels != 192) |
| 707 | if ( m_y_pixels != 192 ) |
| 587 | 708 | { |
| 588 | | name_table_address = ((smsvdp->m_reg[0x02] & 0x0c) << 10) | 0x0700; |
| 589 | | scroll_mod = 256; |
| 709 | result = ((m_reg[0x02] & 0x0c) << 10) | 0x0700; |
| 590 | 710 | } |
| 591 | 711 | else |
| 592 | 712 | { |
| 593 | | name_table_address = (smsvdp->m_reg[0x02] << 10) & 0x3800; |
| 594 | | scroll_mod = 224; |
| 713 | result = (m_reg[0x02] << 10) & 0x3800; |
| 595 | 714 | } |
| 596 | 715 | |
| 597 | | if (IS_SMS1_VDP) |
| 598 | | name_table_address = name_table_address & (((smsvdp->m_reg[0x02] & 0x01) << 10) | 0x3bff); |
| 716 | return result & (((m_reg[0x02] & 0x01) << 10) | 0x3bff); |
| 717 | } |
| 599 | 718 | |
| 719 | |
| 720 | UINT16 sega315_5246_device::get_name_table_address() |
| 721 | { |
| 722 | UINT16 result; |
| 723 | |
| 724 | if ( m_y_pixels != 192 ) |
| 725 | { |
| 726 | result = ((m_reg[0x02] & 0x0c) << 10) | 0x0700; |
| 727 | } |
| 728 | else |
| 729 | { |
| 730 | result = (m_reg[0x02] << 10) & 0x3800; |
| 731 | } |
| 732 | |
| 733 | return result; |
| 734 | } |
| 735 | |
| 736 | |
| 737 | UINT16 sega315_5378_device::get_name_table_address() |
| 738 | { |
| 739 | UINT16 result; |
| 740 | |
| 741 | if ( m_y_pixels != 192 ) |
| 742 | { |
| 743 | result = ((m_reg[0x02] & 0x0c) << 10) | 0x0700; |
| 744 | } |
| 745 | else |
| 746 | { |
| 747 | result = (m_reg[0x02] << 10) & 0x3800; |
| 748 | } |
| 749 | |
| 750 | return result; |
| 751 | } |
| 752 | |
| 753 | |
| 754 | void sega315_5124_device::refresh_line_mode4( int *line_buffer, int *priority_selected, int line ) |
| 755 | { |
| 756 | int tile_column; |
| 757 | int x_scroll, y_scroll, x_scroll_start_column; |
| 758 | int pixel_x, pixel_plot_x; |
| 759 | int bit_plane_0, bit_plane_1, bit_plane_2, bit_plane_3; |
| 760 | int scroll_mod = ( m_y_pixels != 192 ) ? 256 : 224; |
| 761 | UINT16 name_table_address = get_name_table_address(); |
| 762 | UINT8 *name_table; |
| 763 | |
| 600 | 764 | /* if top 2 rows of screen not affected by horizontal scrolling, then x_scroll = 0 */ |
| 601 | 765 | /* else x_scroll = m_reg[0x08] */ |
| 602 | | x_scroll = (((smsvdp->m_reg[0x00] & 0x40) && (line < 16)) ? 0 : 0x0100 - smsvdp->m_reg[0x08]); |
| 766 | x_scroll = (((m_reg[0x00] & 0x40) && (line < 16)) ? 0 : 0x0100 - m_reg[0x08]); |
| 603 | 767 | |
| 604 | 768 | x_scroll_start_column = (x_scroll >> 3); /* x starting column tile */ |
| 605 | 769 | |
| r13435 | r13436 | |
| 612 | 776 | |
| 613 | 777 | /* Rightmost 8 columns for SMS (or 2 columns for GG) not affected by */ |
| 614 | 778 | /* vertical scrolling when bit 7 of reg[0x00] is set */ |
| 615 | | y_scroll = ((smsvdp->m_reg[0x00] & 0x80) && (tile_column > 23)) ? 0 : smsvdp->m_reg9copy; |
| 779 | y_scroll = ((m_reg[0x00] & 0x80) && (tile_column > 23)) ? 0 : m_reg9copy; |
| 616 | 780 | |
| 617 | | name_table = smsvdp->m_VRAM->base() + name_table_address + ((((line + y_scroll) % scroll_mod) >> 3) << 6); |
| 781 | name_table = m_VRAM->base() + name_table_address + ((((line + y_scroll) % scroll_mod) >> 3) << 6); |
| 618 | 782 | |
| 619 | 783 | tile_line = ((tile_column + x_scroll_start_column) & 0x1f) * 2; |
| 620 | 784 | tile_data = name_table[tile_line] | (name_table[tile_line + 1] << 8); |
| r13435 | r13436 | |
| 629 | 793 | if (vert_selected) |
| 630 | 794 | tile_line = 0x07 - tile_line; |
| 631 | 795 | |
| 632 | | bit_plane_0 = smsvdp->m_VRAM->u8(((tile_selected << 5) + ((tile_line & 0x07) << 2)) + 0x00); |
| 633 | | bit_plane_1 = smsvdp->m_VRAM->u8(((tile_selected << 5) + ((tile_line & 0x07) << 2)) + 0x01); |
| 634 | | bit_plane_2 = smsvdp->m_VRAM->u8(((tile_selected << 5) + ((tile_line & 0x07) << 2)) + 0x02); |
| 635 | | bit_plane_3 = smsvdp->m_VRAM->u8(((tile_selected << 5) + ((tile_line & 0x07) << 2)) + 0x03); |
| 796 | bit_plane_0 = m_VRAM->u8(((tile_selected << 5) + ((tile_line & 0x07) << 2)) + 0x00); |
| 797 | bit_plane_1 = m_VRAM->u8(((tile_selected << 5) + ((tile_line & 0x07) << 2)) + 0x01); |
| 798 | bit_plane_2 = m_VRAM->u8(((tile_selected << 5) + ((tile_line & 0x07) << 2)) + 0x02); |
| 799 | bit_plane_3 = m_VRAM->u8(((tile_selected << 5) + ((tile_line & 0x07) << 2)) + 0x03); |
| 636 | 800 | |
| 637 | 801 | for (pixel_x = 0; pixel_x < 8 ; pixel_x++) |
| 638 | 802 | { |
| r13435 | r13436 | |
| 661 | 825 | if (pixel_plot_x >= 0 && pixel_plot_x < 256) |
| 662 | 826 | { |
| 663 | 827 | // logerror("%x %x\n", pixel_plot_x + pixel_offset_x, pixel_plot_y); |
| 664 | | line_buffer[pixel_plot_x] = smsvdp->m_current_palette[pen_selected]; |
| 828 | line_buffer[pixel_plot_x] = m_current_palette[pen_selected]; |
| 665 | 829 | priority_selected[pixel_plot_x] = priority_select | (pen_selected & 0x0f); |
| 666 | 830 | } |
| 667 | 831 | } |
| 668 | 832 | } |
| 669 | 833 | } |
| 670 | 834 | |
| 671 | | static void sms_refresh_mode4_sprites( running_machine &machine, smsvdp_t *smsvdp, int *line_buffer, int *priority_selected, int pixel_plot_y, int line ) |
| 835 | void sega315_5124_device::refresh_mode4_sprites( int *line_buffer, int *priority_selected, int pixel_plot_y, int line ) |
| 672 | 836 | { |
| 673 | 837 | int sprite_index; |
| 674 | 838 | int pixel_x, pixel_plot_x; |
| r13435 | r13436 | |
| 676 | 840 | int sprite_col_occurred, sprite_col_x; |
| 677 | 841 | int sprite_buffer[8], sprite_buffer_count, sprite_buffer_index; |
| 678 | 842 | int bit_plane_0, bit_plane_1, bit_plane_2, bit_plane_3; |
| 679 | | UINT8 *sprite_table = smsvdp->m_VRAM->base() + ((smsvdp->m_reg[0x05] << 7) & 0x3f00); |
| 843 | UINT8 *sprite_table = m_VRAM->base() + ((m_reg[0x05] << 7) & 0x3f00); |
| 680 | 844 | |
| 681 | 845 | /* Draw sprite layer */ |
| 682 | | sprite_height = (smsvdp->m_reg[0x01] & 0x02 ? 16 : 8); |
| 846 | sprite_height = (m_reg[0x01] & 0x02 ? 16 : 8); |
| 683 | 847 | sprite_zoom = 1; |
| 684 | 848 | |
| 685 | | if (smsvdp->m_reg[0x01] & 0x01) /* sprite doubling */ |
| 849 | if (m_reg[0x01] & 0x01) /* sprite doubling */ |
| 686 | 850 | sprite_zoom = 2; |
| 687 | 851 | |
| 688 | 852 | sprite_buffer_count = 0; |
| 689 | | for (sprite_index = 0; (sprite_index < 64) && (sprite_table[sprite_index] != 0xd0 || smsvdp->m_y_pixels != 192) && (sprite_buffer_count < 9); sprite_index++) |
| 853 | for (sprite_index = 0; (sprite_index < 64) && (sprite_table[sprite_index] != 0xd0 || m_y_pixels != 192) && (sprite_buffer_count < 9); sprite_index++) |
| 690 | 854 | { |
| 691 | 855 | sprite_y = sprite_table[sprite_index] + 1; /* sprite y position starts at line 1 */ |
| 692 | 856 | |
| r13435 | r13436 | |
| 699 | 863 | { |
| 700 | 864 | sprite_buffer[sprite_buffer_count] = sprite_index; |
| 701 | 865 | } |
| 702 | | else if (line >= 0 && line < smsvdp->m_sms_frame_timing[ACTIVE_DISPLAY_V]) |
| 866 | else if (line >= 0 && line < m_frame_timing[ACTIVE_DISPLAY_V]) |
| 703 | 867 | { |
| 704 | 868 | /* Too many sprites per line */ |
| 705 | | machine.scheduler().timer_set(smsvdp->m_screen->time_until_pos(pixel_plot_y + line, SPROVR_HPOS), FUNC(smsvdp_set_status), (int)STATUS_SPROVR, smsvdp); |
| 869 | m_set_status_sprovr_timer->adjust( m_screen->time_until_pos( pixel_plot_y + line, SPROVR_HPOS ) ); |
| 706 | 870 | } |
| 707 | 871 | sprite_buffer_count++; |
| 708 | 872 | } |
| 709 | 873 | } |
| 710 | 874 | |
| 711 | 875 | /* Check if display is disabled */ |
| 712 | | if (!(smsvdp->m_reg[0x01] & 0x40)) |
| 876 | if (!(m_reg[0x01] & 0x40)) |
| 713 | 877 | return; |
| 714 | 878 | |
| 715 | 879 | if (sprite_buffer_count > 8) |
| 716 | 880 | sprite_buffer_count = 8; |
| 717 | 881 | |
| 718 | | memset(smsvdp->m_collision_buffer, 0, SMS_X_PIXELS); |
| 882 | memset(m_collision_buffer, 0, SMS_X_PIXELS); |
| 719 | 883 | sprite_buffer_count--; |
| 720 | 884 | |
| 721 | 885 | for (sprite_buffer_index = sprite_buffer_count; sprite_buffer_index >= 0; sprite_buffer_index--) |
| r13435 | r13436 | |
| 728 | 892 | |
| 729 | 893 | sprite_x = sprite_table[0x80 + (sprite_index << 1)]; |
| 730 | 894 | |
| 731 | | if (smsvdp->m_reg[0x00] & 0x08) |
| 895 | if (m_reg[0x00] & 0x08) |
| 732 | 896 | sprite_x -= 0x08; /* sprite shift */ |
| 733 | 897 | |
| 734 | 898 | sprite_tile_selected = sprite_table[0x81 + (sprite_index << 1)]; |
| 735 | 899 | |
| 736 | | if (smsvdp->m_reg[0x06] & 0x04) |
| 900 | if (m_reg[0x06] & 0x04) |
| 737 | 901 | sprite_tile_selected += 256; /* pattern table select */ |
| 738 | 902 | |
| 739 | | if (smsvdp->m_reg[0x01] & 0x02) |
| 903 | if (m_reg[0x01] & 0x02) |
| 740 | 904 | sprite_tile_selected &= 0x01fe; /* force even index */ |
| 741 | 905 | |
| 742 | 906 | sprite_line = (line - sprite_y) / sprite_zoom; |
| r13435 | r13436 | |
| 744 | 908 | if (sprite_line > 0x07) |
| 745 | 909 | sprite_tile_selected += 1; |
| 746 | 910 | |
| 747 | | bit_plane_0 = smsvdp->m_VRAM->u8(((sprite_tile_selected << 5) + ((sprite_line & 0x07) << 2)) + 0x00); |
| 748 | | bit_plane_1 = smsvdp->m_VRAM->u8(((sprite_tile_selected << 5) + ((sprite_line & 0x07) << 2)) + 0x01); |
| 749 | | bit_plane_2 = smsvdp->m_VRAM->u8(((sprite_tile_selected << 5) + ((sprite_line & 0x07) << 2)) + 0x02); |
| 750 | | bit_plane_3 = smsvdp->m_VRAM->u8(((sprite_tile_selected << 5) + ((sprite_line & 0x07) << 2)) + 0x03); |
| 911 | bit_plane_0 = m_VRAM->u8(((sprite_tile_selected << 5) + ((sprite_line & 0x07) << 2)) + 0x00); |
| 912 | bit_plane_1 = m_VRAM->u8(((sprite_tile_selected << 5) + ((sprite_line & 0x07) << 2)) + 0x01); |
| 913 | bit_plane_2 = m_VRAM->u8(((sprite_tile_selected << 5) + ((sprite_line & 0x07) << 2)) + 0x02); |
| 914 | bit_plane_3 = m_VRAM->u8(((sprite_tile_selected << 5) + ((sprite_line & 0x07) << 2)) + 0x03); |
| 751 | 915 | |
| 752 | 916 | sprite_col_occurred = 0; |
| 753 | 917 | sprite_col_x = 0; |
| r13435 | r13436 | |
| 769 | 933 | continue; |
| 770 | 934 | } |
| 771 | 935 | |
| 772 | | if (smsvdp->m_reg[0x01] & 0x01) |
| 936 | if (m_reg[0x01] & 0x01) |
| 773 | 937 | { |
| 774 | 938 | /* sprite doubling is enabled */ |
| 775 | 939 | pixel_plot_x = sprite_x + (pixel_x << 1); |
| r13435 | r13436 | |
| 782 | 946 | |
| 783 | 947 | if (!(priority_selected[pixel_plot_x] & PRIORITY_BIT)) |
| 784 | 948 | { |
| 785 | | line_buffer[pixel_plot_x] = smsvdp->m_current_palette[pen_selected]; |
| 786 | | line_buffer[pixel_plot_x + 1] = smsvdp->m_current_palette[pen_selected]; |
| 949 | line_buffer[pixel_plot_x] = m_current_palette[pen_selected]; |
| 950 | line_buffer[pixel_plot_x + 1] = m_current_palette[pen_selected]; |
| 787 | 951 | } |
| 788 | 952 | else |
| 789 | 953 | { |
| 790 | 954 | if (priority_selected[pixel_plot_x] == PRIORITY_BIT) |
| 791 | 955 | { |
| 792 | | line_buffer[pixel_plot_x] = smsvdp->m_current_palette[pen_selected]; |
| 956 | line_buffer[pixel_plot_x] = m_current_palette[pen_selected]; |
| 793 | 957 | } |
| 794 | 958 | if (priority_selected[pixel_plot_x + 1] == PRIORITY_BIT) |
| 795 | 959 | { |
| 796 | | line_buffer[pixel_plot_x + 1] = smsvdp->m_current_palette[pen_selected]; |
| 960 | line_buffer[pixel_plot_x + 1] = m_current_palette[pen_selected]; |
| 797 | 961 | } |
| 798 | 962 | } |
| 799 | | if (smsvdp->m_collision_buffer[pixel_plot_x] != 1) |
| 963 | if (m_collision_buffer[pixel_plot_x] != 1) |
| 800 | 964 | { |
| 801 | | smsvdp->m_collision_buffer[pixel_plot_x] = 1; |
| 965 | m_collision_buffer[pixel_plot_x] = 1; |
| 802 | 966 | } |
| 803 | 967 | else |
| 804 | 968 | { |
| r13435 | r13436 | |
| 808 | 972 | sprite_col_x = pixel_plot_x; |
| 809 | 973 | } |
| 810 | 974 | } |
| 811 | | if (smsvdp->m_collision_buffer[pixel_plot_x + 1] != 1) |
| 975 | if (m_collision_buffer[pixel_plot_x + 1] != 1) |
| 812 | 976 | { |
| 813 | | smsvdp->m_collision_buffer[pixel_plot_x + 1] = 1; |
| 977 | m_collision_buffer[pixel_plot_x + 1] = 1; |
| 814 | 978 | } |
| 815 | 979 | else |
| 816 | 980 | { |
| r13435 | r13436 | |
| 833 | 997 | |
| 834 | 998 | if (!(priority_selected[pixel_plot_x] & PRIORITY_BIT)) |
| 835 | 999 | { |
| 836 | | line_buffer[pixel_plot_x] = smsvdp->m_current_palette[pen_selected]; |
| 1000 | line_buffer[pixel_plot_x] = m_current_palette[pen_selected]; |
| 837 | 1001 | } |
| 838 | 1002 | else |
| 839 | 1003 | { |
| 840 | 1004 | if (priority_selected[pixel_plot_x] == PRIORITY_BIT) |
| 841 | 1005 | { |
| 842 | | line_buffer[pixel_plot_x] = smsvdp->m_current_palette[pen_selected]; |
| 1006 | line_buffer[pixel_plot_x] = m_current_palette[pen_selected]; |
| 843 | 1007 | } |
| 844 | 1008 | } |
| 845 | | if (smsvdp->m_collision_buffer[pixel_plot_x] != 1) |
| 1009 | if (m_collision_buffer[pixel_plot_x] != 1) |
| 846 | 1010 | { |
| 847 | | smsvdp->m_collision_buffer[pixel_plot_x] = 1; |
| 1011 | m_collision_buffer[pixel_plot_x] = 1; |
| 848 | 1012 | } |
| 849 | 1013 | else |
| 850 | 1014 | { |
| r13435 | r13436 | |
| 857 | 1021 | } |
| 858 | 1022 | } |
| 859 | 1023 | if (sprite_col_occurred) |
| 860 | | machine.scheduler().timer_set(smsvdp->m_screen->time_until_pos(pixel_plot_y + line, SPRCOL_BASEHPOS + sprite_col_x), FUNC(smsvdp_set_status), (int)STATUS_SPRCOL, smsvdp); |
| 1024 | { |
| 1025 | m_set_status_sprovr_timer->adjust( m_screen->time_until_pos( pixel_plot_y + line, SPRCOL_BASEHPOS + sprite_col_x ) ); |
| 1026 | } |
| 861 | 1027 | } |
| 862 | 1028 | |
| 863 | 1029 | /* Fill column 0 with overscan color from m_reg[0x07] */ |
| 864 | | if (smsvdp->m_reg[0x00] & 0x20) |
| 1030 | if (m_reg[0x00] & 0x20) |
| 865 | 1031 | { |
| 866 | | line_buffer[0] = smsvdp->m_current_palette[BACKDROP_COLOR]; |
| 867 | | line_buffer[1] = smsvdp->m_current_palette[BACKDROP_COLOR]; |
| 868 | | line_buffer[2] = smsvdp->m_current_palette[BACKDROP_COLOR]; |
| 869 | | line_buffer[3] = smsvdp->m_current_palette[BACKDROP_COLOR]; |
| 870 | | line_buffer[4] = smsvdp->m_current_palette[BACKDROP_COLOR]; |
| 871 | | line_buffer[5] = smsvdp->m_current_palette[BACKDROP_COLOR]; |
| 872 | | line_buffer[6] = smsvdp->m_current_palette[BACKDROP_COLOR]; |
| 873 | | line_buffer[7] = smsvdp->m_current_palette[BACKDROP_COLOR]; |
| 1032 | line_buffer[0] = m_current_palette[BACKDROP_COLOR]; |
| 1033 | line_buffer[1] = m_current_palette[BACKDROP_COLOR]; |
| 1034 | line_buffer[2] = m_current_palette[BACKDROP_COLOR]; |
| 1035 | line_buffer[3] = m_current_palette[BACKDROP_COLOR]; |
| 1036 | line_buffer[4] = m_current_palette[BACKDROP_COLOR]; |
| 1037 | line_buffer[5] = m_current_palette[BACKDROP_COLOR]; |
| 1038 | line_buffer[6] = m_current_palette[BACKDROP_COLOR]; |
| 1039 | line_buffer[7] = m_current_palette[BACKDROP_COLOR]; |
| 874 | 1040 | } |
| 875 | 1041 | } |
| 876 | 1042 | |
| 877 | 1043 | |
| 878 | | static void sms_refresh_tms9918_sprites( running_machine &machine, smsvdp_t *smsvdp, int *line_buffer, int pixel_plot_y, int line ) |
| 1044 | void sega315_5124_device::refresh_tms9918_sprites( int *line_buffer, int pixel_plot_y, int line ) |
| 879 | 1045 | { |
| 880 | 1046 | int pixel_plot_x; |
| 881 | 1047 | int sprite_col_occurred, sprite_col_x; |
| r13435 | r13436 | |
| 883 | 1049 | UINT8 *sprite_table, *sprite_pattern_table; |
| 884 | 1050 | |
| 885 | 1051 | /* Draw sprite layer */ |
| 886 | | sprite_table = smsvdp->m_VRAM->base() + ((smsvdp->m_reg[0x05] & 0x7f) << 7); |
| 887 | | sprite_pattern_table = smsvdp->m_VRAM->base() + ((smsvdp->m_reg[0x06] & 0x07) << 11); |
| 1052 | sprite_table = m_VRAM->base() + ((m_reg[0x05] & 0x7f) << 7); |
| 1053 | sprite_pattern_table = m_VRAM->base() + ((m_reg[0x06] & 0x07) << 11); |
| 888 | 1054 | sprite_height = 8; |
| 889 | 1055 | |
| 890 | | if (smsvdp->m_reg[0x01] & 0x02) /* Check if SI is set */ |
| 1056 | if (m_reg[0x01] & 0x02) /* Check if SI is set */ |
| 891 | 1057 | sprite_height = sprite_height * 2; |
| 892 | | if (smsvdp->m_reg[0x01] & 0x01) /* Check if MAG is set */ |
| 1058 | if (m_reg[0x01] & 0x01) /* Check if MAG is set */ |
| 893 | 1059 | sprite_height = sprite_height * 2; |
| 894 | 1060 | |
| 895 | 1061 | sprite_buffer_count = 0; |
| r13435 | r13436 | |
| 906 | 1072 | { |
| 907 | 1073 | sprite_buffer[sprite_buffer_count] = sprite_index; |
| 908 | 1074 | } |
| 909 | | else if (line >= 0 && line < smsvdp->m_sms_frame_timing[ACTIVE_DISPLAY_V]) |
| 1075 | else if (line >= 0 && line < m_frame_timing[ACTIVE_DISPLAY_V]) |
| 910 | 1076 | { |
| 911 | 1077 | /* Too many sprites per line */ |
| 912 | | machine.scheduler().timer_set(smsvdp->m_screen->time_until_pos(pixel_plot_y + line, SPROVR_HPOS), FUNC(smsvdp_set_status), (int)STATUS_SPROVR, smsvdp); |
| 1078 | m_set_status_sprovr_timer->adjust( m_screen->time_until_pos( pixel_plot_y + line, SPROVR_HPOS ) ); |
| 913 | 1079 | } |
| 914 | 1080 | sprite_buffer_count++; |
| 915 | 1081 | } |
| 916 | 1082 | } |
| 917 | 1083 | |
| 918 | 1084 | /* Check if display is disabled */ |
| 919 | | if (!(smsvdp->m_reg[0x01] & 0x40)) |
| 1085 | if (!(m_reg[0x01] & 0x40)) |
| 920 | 1086 | return; |
| 921 | 1087 | |
| 922 | 1088 | if (sprite_buffer_count > 4) |
| 923 | 1089 | sprite_buffer_count = 4; |
| 924 | 1090 | |
| 925 | | memset(smsvdp->m_collision_buffer, 0, SMS_X_PIXELS); |
| 1091 | memset(m_collision_buffer, 0, SMS_X_PIXELS); |
| 926 | 1092 | sprite_buffer_count--; |
| 927 | 1093 | |
| 928 | 1094 | for (sprite_buffer_index = sprite_buffer_count; sprite_buffer_index >= 0; sprite_buffer_index--) |
| r13435 | r13436 | |
| 939 | 1105 | sprite_y -= 256; |
| 940 | 1106 | |
| 941 | 1107 | sprite_x = sprite_table[sprite_index + 1]; |
| 942 | | pen_selected = sprite_table[sprite_index + 3] & 0x0f; |
| 1108 | pen_selected = m_palette_offset + ( sprite_table[sprite_index + 3] & 0x0f ); |
| 943 | 1109 | |
| 944 | | if (IS_GAMEGEAR_VDP) |
| 945 | | pen_selected |= 0x10; |
| 946 | | |
| 947 | 1110 | if (sprite_table[sprite_index + 3] & 0x80) |
| 948 | 1111 | sprite_x -= 32; |
| 949 | 1112 | |
| 950 | 1113 | sprite_tile_selected = sprite_table[sprite_index + 2]; |
| 951 | 1114 | sprite_line = line - sprite_y; |
| 952 | 1115 | |
| 953 | | if (smsvdp->m_reg[0x01] & 0x01) |
| 1116 | if (m_reg[0x01] & 0x01) |
| 954 | 1117 | sprite_line >>= 1; |
| 955 | 1118 | |
| 956 | | if (smsvdp->m_reg[0x01] & 0x02) |
| 1119 | if (m_reg[0x01] & 0x02) |
| 957 | 1120 | { |
| 958 | 1121 | sprite_tile_selected &= 0xfc; |
| 959 | 1122 | |
| r13435 | r13436 | |
| 971 | 1134 | |
| 972 | 1135 | for (pixel_x = 0; pixel_x < 8; pixel_x++) |
| 973 | 1136 | { |
| 974 | | if (smsvdp->m_reg[0x01] & 0x01) |
| 1137 | if (m_reg[0x01] & 0x01) |
| 975 | 1138 | { |
| 976 | 1139 | pixel_plot_x = sprite_x + pixel_x * 2; |
| 977 | 1140 | if (pixel_plot_x < 0 || pixel_plot_x > 255) |
| r13435 | r13436 | |
| 981 | 1144 | |
| 982 | 1145 | if (pen_selected && (pattern & (1 << (7 - pixel_x)))) |
| 983 | 1146 | { |
| 984 | | line_buffer[pixel_plot_x] = smsvdp->m_current_palette[pen_selected]; |
| 1147 | line_buffer[pixel_plot_x] = m_current_palette[pen_selected]; |
| 985 | 1148 | |
| 986 | | if (smsvdp->m_collision_buffer[pixel_plot_x] != 1) |
| 1149 | if (m_collision_buffer[pixel_plot_x] != 1) |
| 987 | 1150 | { |
| 988 | | smsvdp->m_collision_buffer[pixel_plot_x] = 1; |
| 1151 | m_collision_buffer[pixel_plot_x] = 1; |
| 989 | 1152 | } |
| 990 | 1153 | else |
| 991 | 1154 | { |
| r13435 | r13436 | |
| 996 | 1159 | } |
| 997 | 1160 | } |
| 998 | 1161 | |
| 999 | | line_buffer[pixel_plot_x+1] = smsvdp->m_current_palette[pen_selected]; |
| 1162 | line_buffer[pixel_plot_x+1] = m_current_palette[pen_selected]; |
| 1000 | 1163 | |
| 1001 | | if (smsvdp->m_collision_buffer[pixel_plot_x + 1] != 1) |
| 1164 | if (m_collision_buffer[pixel_plot_x + 1] != 1) |
| 1002 | 1165 | { |
| 1003 | | smsvdp->m_collision_buffer[pixel_plot_x + 1] = 1; |
| 1166 | m_collision_buffer[pixel_plot_x + 1] = 1; |
| 1004 | 1167 | } |
| 1005 | 1168 | else |
| 1006 | 1169 | { |
| r13435 | r13436 | |
| 1023 | 1186 | |
| 1024 | 1187 | if (pen_selected && (pattern & (1 << (7 - pixel_x)))) |
| 1025 | 1188 | { |
| 1026 | | line_buffer[pixel_plot_x] = smsvdp->m_current_palette[pen_selected]; |
| 1189 | line_buffer[pixel_plot_x] = m_current_palette[pen_selected]; |
| 1027 | 1190 | |
| 1028 | | if (smsvdp->m_collision_buffer[pixel_plot_x] != 1) |
| 1191 | if (m_collision_buffer[pixel_plot_x] != 1) |
| 1029 | 1192 | { |
| 1030 | | smsvdp->m_collision_buffer[pixel_plot_x] = 1; |
| 1193 | m_collision_buffer[pixel_plot_x] = 1; |
| 1031 | 1194 | } |
| 1032 | 1195 | else |
| 1033 | 1196 | { |
| r13435 | r13436 | |
| 1041 | 1204 | } |
| 1042 | 1205 | } |
| 1043 | 1206 | |
| 1044 | | if (smsvdp->m_reg[0x01] & 0x02) |
| 1207 | if (m_reg[0x01] & 0x02) |
| 1045 | 1208 | { |
| 1046 | 1209 | sprite_tile_selected += 2; |
| 1047 | 1210 | pattern = sprite_pattern_table[sprite_tile_selected * 8 + sprite_line]; |
| 1048 | | sprite_x += (smsvdp->m_reg[0x01] & 0x01 ? 16 : 8); |
| 1211 | sprite_x += (m_reg[0x01] & 0x01 ? 16 : 8); |
| 1049 | 1212 | |
| 1050 | 1213 | for (pixel_x = 0; pixel_x < 8; pixel_x++) |
| 1051 | 1214 | { |
| 1052 | | if (smsvdp->m_reg[0x01] & 0x01) |
| 1215 | if (m_reg[0x01] & 0x01) |
| 1053 | 1216 | { |
| 1054 | 1217 | pixel_plot_x = sprite_x + pixel_x * 2; |
| 1055 | 1218 | |
| r13435 | r13436 | |
| 1060 | 1223 | |
| 1061 | 1224 | if (pen_selected && (pattern & (1 << (7 - pixel_x)))) |
| 1062 | 1225 | { |
| 1063 | | line_buffer[pixel_plot_x] = smsvdp->m_current_palette[pen_selected]; |
| 1226 | line_buffer[pixel_plot_x] = m_current_palette[pen_selected]; |
| 1064 | 1227 | |
| 1065 | | if (smsvdp->m_collision_buffer[pixel_plot_x] != 1) |
| 1228 | if (m_collision_buffer[pixel_plot_x] != 1) |
| 1066 | 1229 | { |
| 1067 | | smsvdp->m_collision_buffer[pixel_plot_x] = 1; |
| 1230 | m_collision_buffer[pixel_plot_x] = 1; |
| 1068 | 1231 | } |
| 1069 | 1232 | else |
| 1070 | 1233 | { |
| r13435 | r13436 | |
| 1075 | 1238 | } |
| 1076 | 1239 | } |
| 1077 | 1240 | |
| 1078 | | line_buffer[pixel_plot_x+1] = smsvdp->m_current_palette[pen_selected]; |
| 1241 | line_buffer[pixel_plot_x+1] = m_current_palette[pen_selected]; |
| 1079 | 1242 | |
| 1080 | | if (smsvdp->m_collision_buffer[pixel_plot_x + 1] != 1) |
| 1243 | if (m_collision_buffer[pixel_plot_x + 1] != 1) |
| 1081 | 1244 | { |
| 1082 | | smsvdp->m_collision_buffer[pixel_plot_x + 1] = 1; |
| 1245 | m_collision_buffer[pixel_plot_x + 1] = 1; |
| 1083 | 1246 | } |
| 1084 | 1247 | else |
| 1085 | 1248 | { |
| r13435 | r13436 | |
| 1102 | 1265 | |
| 1103 | 1266 | if (pen_selected && (pattern & (1 << (7 - pixel_x)))) |
| 1104 | 1267 | { |
| 1105 | | line_buffer[pixel_plot_x] = smsvdp->m_current_palette[pen_selected]; |
| 1268 | line_buffer[pixel_plot_x] = m_current_palette[pen_selected]; |
| 1106 | 1269 | |
| 1107 | | if (smsvdp->m_collision_buffer[pixel_plot_x] != 1) |
| 1270 | if (m_collision_buffer[pixel_plot_x] != 1) |
| 1108 | 1271 | { |
| 1109 | | smsvdp->m_collision_buffer[pixel_plot_x] = 1; |
| 1272 | m_collision_buffer[pixel_plot_x] = 1; |
| 1110 | 1273 | } |
| 1111 | 1274 | else |
| 1112 | 1275 | { |
| r13435 | r13436 | |
| 1121 | 1284 | } |
| 1122 | 1285 | } |
| 1123 | 1286 | if (sprite_col_occurred) |
| 1124 | | machine.scheduler().timer_set(smsvdp->m_screen->time_until_pos(pixel_plot_y + line, SPRCOL_BASEHPOS + sprite_col_x), FUNC(smsvdp_set_status), (int)STATUS_SPRCOL, smsvdp); |
| 1287 | { |
| 1288 | m_set_status_sprovr_timer->adjust( m_screen->time_until_pos( pixel_plot_y + line, SPRCOL_BASEHPOS + sprite_col_x ) ); |
| 1289 | } |
| 1125 | 1290 | } |
| 1126 | 1291 | } |
| 1127 | 1292 | |
| 1128 | 1293 | |
| 1129 | | static void sms_refresh_line_mode2( smsvdp_t *smsvdp, int *line_buffer, int line ) |
| 1294 | void sega315_5124_device::refresh_line_mode2( int *line_buffer, int line ) |
| 1130 | 1295 | { |
| 1131 | 1296 | int tile_column; |
| 1132 | 1297 | int pixel_x, pixel_plot_x; |
| r13435 | r13436 | |
| 1134 | 1299 | int pattern_mask, color_mask, pattern_offset; |
| 1135 | 1300 | |
| 1136 | 1301 | /* Draw background layer */ |
| 1137 | | name_table = smsvdp->m_VRAM->base() + ((smsvdp->m_reg[0x02] & 0x0f) << 10) + ((line >> 3) * 32); |
| 1138 | | color_table = smsvdp->m_VRAM->base() + ((smsvdp->m_reg[0x03] & 0x80) << 6); |
| 1139 | | color_mask = ((smsvdp->m_reg[0x03] & 0x7f) << 3) | 0x07; |
| 1140 | | pattern_table = smsvdp->m_VRAM->base() + ((smsvdp->m_reg[0x04] & 0x04) << 11); |
| 1141 | | pattern_mask = ((smsvdp->m_reg[0x04] & 0x03) << 8) | 0xff; |
| 1302 | name_table = m_VRAM->base() + ((m_reg[0x02] & 0x0f) << 10) + ((line >> 3) * 32); |
| 1303 | color_table = m_VRAM->base() + ((m_reg[0x03] & 0x80) << 6); |
| 1304 | color_mask = ((m_reg[0x03] & 0x7f) << 3) | 0x07; |
| 1305 | pattern_table = m_VRAM->base() + ((m_reg[0x04] & 0x04) << 11); |
| 1306 | pattern_mask = ((m_reg[0x04] & 0x03) << 8) | 0xff; |
| 1142 | 1307 | pattern_offset = (line & 0xc0) << 2; |
| 1143 | 1308 | |
| 1144 | 1309 | for (tile_column = 0; tile_column < 32; tile_column++) |
| r13435 | r13436 | |
| 1167 | 1332 | |
| 1168 | 1333 | pixel_plot_x = (tile_column << 3) + pixel_x; |
| 1169 | 1334 | |
| 1170 | | if (IS_GAMEGEAR_VDP) |
| 1171 | | pen_selected |= 0x10; |
| 1335 | pen_selected += m_palette_offset; |
| 1172 | 1336 | |
| 1173 | | line_buffer[pixel_plot_x] = smsvdp->m_current_palette[pen_selected]; |
| 1337 | line_buffer[pixel_plot_x] = m_current_palette[pen_selected]; |
| 1174 | 1338 | } |
| 1175 | 1339 | } |
| 1176 | 1340 | } |
| 1177 | 1341 | |
| 1178 | 1342 | |
| 1179 | | static void sms_refresh_line_mode0( smsvdp_t *smsvdp, int *line_buffer, int line) |
| 1343 | void sega315_5124_device::refresh_line_mode0( int *line_buffer, int line ) |
| 1180 | 1344 | { |
| 1181 | 1345 | int tile_column; |
| 1182 | 1346 | int pixel_x, pixel_plot_x; |
| 1183 | 1347 | UINT8 *name_table, *color_table, *pattern_table; |
| 1184 | 1348 | |
| 1185 | 1349 | /* Draw background layer */ |
| 1186 | | name_table = smsvdp->m_VRAM->base() + ((smsvdp->m_reg[0x02] & 0x0f) << 10) + ((line >> 3) * 32); |
| 1187 | | color_table = smsvdp->m_VRAM->base() + ((smsvdp->m_reg[0x03] << 6) & (VRAM_SIZE - 1)); |
| 1188 | | pattern_table = smsvdp->m_VRAM->base() + ((smsvdp->m_reg[0x04] << 11) & (VRAM_SIZE - 1)); |
| 1350 | name_table = m_VRAM->base() + ((m_reg[0x02] & 0x0f) << 10) + ((line >> 3) * 32); |
| 1351 | color_table = m_VRAM->base() + ((m_reg[0x03] << 6) & (VRAM_SIZE - 1)); |
| 1352 | pattern_table = m_VRAM->base() + ((m_reg[0x04] << 11) & (VRAM_SIZE - 1)); |
| 1189 | 1353 | |
| 1190 | 1354 | for (tile_column = 0; tile_column < 32; tile_column++) |
| 1191 | 1355 | { |
| r13435 | r13436 | |
| 1204 | 1368 | else |
| 1205 | 1369 | pen_selected = colors & 0x0f; |
| 1206 | 1370 | |
| 1207 | | if (IS_GAMEGEAR_VDP) |
| 1208 | | pen_selected |= 0x10; |
| 1371 | pen_selected += m_palette_offset; |
| 1209 | 1372 | |
| 1210 | 1373 | pixel_plot_x = (tile_column << 3) + pixel_x; |
| 1211 | | line_buffer[pixel_plot_x] = smsvdp->m_current_palette[pen_selected]; |
| 1374 | line_buffer[pixel_plot_x] = m_current_palette[pen_selected]; |
| 1212 | 1375 | } |
| 1213 | 1376 | } |
| 1214 | 1377 | } |
| 1215 | 1378 | |
| 1216 | 1379 | |
| 1217 | | static void sms_refresh_line( running_machine &machine, smsvdp_t *smsvdp, bitmap_t *bitmap, int pixel_offset_x, int pixel_plot_y, int line ) |
| 1380 | void sega315_5124_device::refresh_line( int pixel_offset_x, int pixel_plot_y, int line ) |
| 1218 | 1381 | { |
| 1219 | 1382 | int x; |
| 1220 | | int *blitline_buffer = smsvdp->m_line_buffer; |
| 1383 | int *blitline_buffer = m_line_buffer; |
| 1221 | 1384 | int priority_selected[256]; |
| 1222 | 1385 | |
| 1223 | | switch( smsvdp->m_vdp_mode ) |
| 1386 | switch( m_vdp_mode ) |
| 1224 | 1387 | { |
| 1225 | 1388 | case 0: |
| 1226 | | if (line >= 0 && line < smsvdp->m_sms_frame_timing[ACTIVE_DISPLAY_V]) |
| 1227 | | sms_refresh_line_mode0(smsvdp, blitline_buffer, line); |
| 1228 | | sms_refresh_tms9918_sprites(machine, smsvdp, blitline_buffer, pixel_plot_y, line); |
| 1389 | if (line >= 0 && line < m_frame_timing[ACTIVE_DISPLAY_V]) |
| 1390 | { |
| 1391 | refresh_line_mode0( blitline_buffer, line ); |
| 1392 | } |
| 1393 | refresh_tms9918_sprites( blitline_buffer, pixel_plot_y, line ); |
| 1229 | 1394 | break; |
| 1230 | 1395 | |
| 1231 | 1396 | case 2: |
| 1232 | | if (line >= 0 && line < smsvdp->m_sms_frame_timing[ACTIVE_DISPLAY_V]) |
| 1233 | | sms_refresh_line_mode2(smsvdp, blitline_buffer, line); |
| 1234 | | sms_refresh_tms9918_sprites(machine, smsvdp, blitline_buffer, pixel_plot_y, line); |
| 1397 | if (line >= 0 && line < m_frame_timing[ACTIVE_DISPLAY_V]) |
| 1398 | { |
| 1399 | refresh_line_mode2( blitline_buffer, line ); |
| 1400 | } |
| 1401 | refresh_tms9918_sprites( blitline_buffer, pixel_plot_y, line ); |
| 1235 | 1402 | break; |
| 1236 | 1403 | |
| 1237 | 1404 | case 4: |
| 1238 | 1405 | default: |
| 1239 | 1406 | memset(priority_selected, 0, sizeof(priority_selected)); |
| 1240 | | if (line >= 0 && line < smsvdp->m_sms_frame_timing[ACTIVE_DISPLAY_V]) |
| 1241 | | sms_refresh_line_mode4(smsvdp, blitline_buffer, priority_selected, line); |
| 1242 | | sms_refresh_mode4_sprites(machine, smsvdp, blitline_buffer, priority_selected, pixel_plot_y, line); |
| 1407 | if (line >= 0 && line < m_frame_timing[ACTIVE_DISPLAY_V]) |
| 1408 | { |
| 1409 | refresh_line_mode4( blitline_buffer, priority_selected, line ); |
| 1410 | } |
| 1411 | refresh_mode4_sprites( blitline_buffer, priority_selected, pixel_plot_y, line ); |
| 1243 | 1412 | break; |
| 1244 | 1413 | } |
| 1245 | 1414 | |
| 1246 | 1415 | /* Check if display is disabled or we're below/above active area */ |
| 1247 | | if (!(smsvdp->m_reg[0x01] & 0x40) || line < 0 || line >= smsvdp->m_sms_frame_timing[ACTIVE_DISPLAY_V]) |
| 1416 | if (!(m_reg[0x01] & 0x40) || line < 0 || line >= m_frame_timing[ACTIVE_DISPLAY_V]) |
| 1248 | 1417 | { |
| 1249 | 1418 | for (x = 0; x < 256; x++) |
| 1250 | 1419 | { |
| 1251 | | blitline_buffer[x] = smsvdp->m_current_palette[BACKDROP_COLOR]; |
| 1420 | blitline_buffer[x] = m_current_palette[BACKDROP_COLOR]; |
| 1252 | 1421 | } |
| 1253 | 1422 | } |
| 1254 | 1423 | |
| 1255 | | if (IS_GAMEGEAR_VDP && smsvdp->m_gg_sms_mode) |
| 1424 | for (x = 0; x < 256; x++) |
| 1256 | 1425 | { |
| 1257 | | int *combineline_buffer = smsvdp->m_line_buffer + ((line & 0x03) + 1) * 256; |
| 1426 | *BITMAP_ADDR32(m_tmpbitmap, pixel_plot_y + line, pixel_offset_x + x) = machine().pens[blitline_buffer[x]]; |
| 1427 | } |
| 1428 | } |
| 1429 | |
| 1430 | |
| 1431 | void sega315_5378_device::refresh_line( int pixel_offset_x, int pixel_plot_y, int line ) |
| 1432 | { |
| 1433 | int x; |
| 1434 | int *blitline_buffer = m_line_buffer; |
| 1435 | int priority_selected[256]; |
| 1436 | |
| 1437 | switch( m_vdp_mode ) |
| 1438 | { |
| 1439 | case 0: |
| 1440 | if (line >= 0 && line < m_frame_timing[ACTIVE_DISPLAY_V]) |
| 1441 | { |
| 1442 | refresh_line_mode0( blitline_buffer, line ); |
| 1443 | } |
| 1444 | refresh_tms9918_sprites( blitline_buffer, pixel_plot_y, line ); |
| 1445 | break; |
| 1446 | |
| 1447 | case 2: |
| 1448 | if (line >= 0 && line < m_frame_timing[ACTIVE_DISPLAY_V]) |
| 1449 | { |
| 1450 | refresh_line_mode2( blitline_buffer, line ); |
| 1451 | } |
| 1452 | refresh_tms9918_sprites( blitline_buffer, pixel_plot_y, line ); |
| 1453 | break; |
| 1454 | |
| 1455 | case 4: |
| 1456 | default: |
| 1457 | memset(priority_selected, 0, sizeof(priority_selected)); |
| 1458 | if (line >= 0 && line < m_frame_timing[ACTIVE_DISPLAY_V]) |
| 1459 | { |
| 1460 | refresh_line_mode4( blitline_buffer, priority_selected, line ); |
| 1461 | } |
| 1462 | refresh_mode4_sprites( blitline_buffer, priority_selected, pixel_plot_y, line ); |
| 1463 | break; |
| 1464 | } |
| 1465 | |
| 1466 | /* Check if display is disabled or we're below/above active area */ |
| 1467 | if (!(m_reg[0x01] & 0x40) || line < 0 || line >= m_frame_timing[ACTIVE_DISPLAY_V]) |
| 1468 | { |
| 1469 | for (x = 0; x < 256; x++) |
| 1470 | { |
| 1471 | blitline_buffer[x] = m_current_palette[BACKDROP_COLOR]; |
| 1472 | } |
| 1473 | } |
| 1474 | |
| 1475 | if (m_gg_sms_mode) |
| 1476 | { |
| 1477 | int *combineline_buffer = m_line_buffer + ((line & 0x03) + 1) * 256; |
| 1258 | 1478 | int plot_x = 48; |
| 1259 | 1479 | |
| 1260 | 1480 | /* Do horizontal scaling */ |
| r13435 | r13436 | |
| 1309 | 1529 | pixel_plot_y = SMS_TBORDER_START + SMS_NTSC_192_TBORDER_Y_PIXELS + 24 + gg_line; |
| 1310 | 1530 | |
| 1311 | 1531 | /* Setup our source lines */ |
| 1312 | | line1 = smsvdp->m_line_buffer + (((my_line - 3) & 0x03) + 1) * 256; |
| 1313 | | line2 = smsvdp->m_line_buffer + (((my_line - 2) & 0x03) + 1) * 256; |
| 1314 | | line3 = smsvdp->m_line_buffer + (((my_line - 1) & 0x03) + 1) * 256; |
| 1315 | | line4 = smsvdp->m_line_buffer + (((my_line - 0) & 0x03) + 1) * 256; |
| 1532 | line1 = m_line_buffer + (((my_line - 3) & 0x03) + 1) * 256; |
| 1533 | line2 = m_line_buffer + (((my_line - 2) & 0x03) + 1) * 256; |
| 1534 | line3 = m_line_buffer + (((my_line - 1) & 0x03) + 1) * 256; |
| 1535 | line4 = m_line_buffer + (((my_line - 0) & 0x03) + 1) * 256; |
| 1316 | 1536 | |
| 1317 | 1537 | for (x = 0 + 48; x < 160 + 48; x++) |
| 1318 | 1538 | { |
| 1319 | | rgb_t c1 = machine.pens[line1[x]]; |
| 1320 | | rgb_t c2 = machine.pens[line2[x]]; |
| 1321 | | rgb_t c3 = machine.pens[line3[x]]; |
| 1322 | | rgb_t c4 = machine.pens[line4[x]]; |
| 1323 | | *BITMAP_ADDR32(bitmap, pixel_plot_y, pixel_offset_x + x) = |
| 1539 | rgb_t c1 = machine().pens[line1[x]]; |
| 1540 | rgb_t c2 = machine().pens[line2[x]]; |
| 1541 | rgb_t c3 = machine().pens[line3[x]]; |
| 1542 | rgb_t c4 = machine().pens[line4[x]]; |
| 1543 | *BITMAP_ADDR32(m_tmpbitmap, pixel_plot_y, pixel_offset_x + x) = |
| 1324 | 1544 | MAKE_RGB((RGB_RED(c1) / 6 + RGB_RED(c2) / 3 + RGB_RED(c3) / 3 + RGB_RED(c4) / 6 ), |
| 1325 | 1545 | (RGB_GREEN(c1) / 6 + RGB_GREEN(c2) / 3 + RGB_GREEN(c3) / 3 + RGB_GREEN(c4) / 6 ), |
| 1326 | 1546 | (RGB_BLUE(c1) / 6 + RGB_BLUE(c2) / 3 + RGB_BLUE(c3) / 3 + RGB_BLUE(c4) / 6 ) ); |
| r13435 | r13436 | |
| 1332 | 1552 | |
| 1333 | 1553 | for (x = 0; x < 256; x++) |
| 1334 | 1554 | { |
| 1335 | | *BITMAP_ADDR32(bitmap, pixel_plot_y + line, pixel_offset_x + x) = machine.pens[blitline_buffer[x]]; |
| 1555 | *BITMAP_ADDR32(m_tmpbitmap, pixel_plot_y + line, pixel_offset_x + x) = machine().pens[blitline_buffer[x]]; |
| 1336 | 1556 | } |
| 1337 | 1557 | } |
| 1338 | 1558 | |
| 1339 | | |
| 1340 | 1559 | // This is only used by Light Phaser. Should it be moved elsewhere? |
| 1341 | | int sms_vdp_check_brightness(device_t *device, int x, int y) |
| 1560 | int sega315_5124_device::check_brightness(int x, int y) |
| 1342 | 1561 | { |
| 1343 | 1562 | /* brightness of the lightgray color in the frame drawn by Light Phaser games */ |
| 1344 | 1563 | const UINT8 sensor_min_brightness = 0x7f; |
| r13435 | r13436 | |
| 1348 | 1567 | if (x < SMS_LBORDER_START + SMS_LBORDER_X_PIXELS || x >= SMS_LBORDER_START + SMS_LBORDER_X_PIXELS + 256) |
| 1349 | 1568 | return 0; |
| 1350 | 1569 | |
| 1351 | | smsvdp_t *smsvdp = get_safe_token(device); |
| 1352 | | rgb_t color = *BITMAP_ADDR32(smsvdp->m_tmpbitmap, y, x); |
| 1570 | rgb_t color = *BITMAP_ADDR32(m_tmpbitmap, y, x); |
| 1353 | 1571 | |
| 1354 | 1572 | /* reference: http://www.w3.org/TR/AERT#color-contrast */ |
| 1355 | 1573 | UINT8 brightness = (RGB_RED(color) * 0.299) + (RGB_GREEN(color) * 0.587) + (RGB_BLUE(color) * 0.114); |
| r13435 | r13436 | |
| 1359 | 1577 | } |
| 1360 | 1578 | |
| 1361 | 1579 | |
| 1362 | | static void sms_update_palette( smsvdp_t *smsvdp ) |
| 1580 | void sega315_5124_device::update_palette() |
| 1363 | 1581 | { |
| 1364 | 1582 | int i; |
| 1365 | 1583 | |
| 1366 | 1584 | /* Exit if palette is has no changes */ |
| 1367 | | if (smsvdp->m_cram_dirty == 0) |
| 1585 | if (m_cram_dirty == 0) |
| 1368 | 1586 | { |
| 1369 | 1587 | return; |
| 1370 | 1588 | } |
| 1371 | | smsvdp->m_cram_dirty = 0; |
| 1589 | m_cram_dirty = 0; |
| 1372 | 1590 | |
| 1373 | | if (smsvdp->m_vdp_mode != 4 && ! IS_GAMEGEAR_VDP) |
| 1591 | if (m_vdp_mode != 4) |
| 1374 | 1592 | { |
| 1375 | 1593 | for(i = 0; i < 16; i++) |
| 1376 | 1594 | { |
| 1377 | | smsvdp->m_current_palette[i] = 64 + i; |
| 1595 | m_current_palette[i] = 64 + i; |
| 1378 | 1596 | } |
| 1379 | 1597 | return; |
| 1380 | 1598 | } |
| 1381 | 1599 | |
| 1382 | | if (IS_GAMEGEAR_VDP) |
| 1600 | for (i = 0; i < 32; i++) |
| 1383 | 1601 | { |
| 1384 | | if (smsvdp->m_gg_sms_mode) |
| 1602 | m_current_palette[i] = m_CRAM->u8(i) & 0x3f; |
| 1603 | } |
| 1604 | } |
| 1605 | |
| 1606 | |
| 1607 | void sega315_5378_device::update_palette() |
| 1608 | { |
| 1609 | int i; |
| 1610 | |
| 1611 | /* Exit if palette is has no changes */ |
| 1612 | if (m_cram_dirty == 0) |
| 1613 | { |
| 1614 | return; |
| 1615 | } |
| 1616 | m_cram_dirty = 0; |
| 1617 | |
| 1618 | if (m_gg_sms_mode) |
| 1619 | { |
| 1620 | for (i = 0; i < 32; i++) |
| 1385 | 1621 | { |
| 1386 | | for (i = 0; i < 32; i++) |
| 1387 | | { |
| 1388 | | smsvdp->m_current_palette[i] = ((smsvdp->m_CRAM->u8(i) & 0x30) << 6) | ((smsvdp->m_CRAM->u8(i) & 0x0c ) << 4) | ((smsvdp->m_CRAM->u8(i) & 0x03) << 2); |
| 1389 | | } |
| 1622 | m_current_palette[i] = ((m_CRAM->u8(i) & 0x30) << 6) | ((m_CRAM->u8(i) & 0x0c ) << 4) | ((m_CRAM->u8(i) & 0x03) << 2); |
| 1390 | 1623 | } |
| 1391 | | else |
| 1392 | | { |
| 1393 | | for (i = 0; i < 32; i++) |
| 1394 | | { |
| 1395 | | smsvdp->m_current_palette[i] = ((smsvdp->m_CRAM->u8(i * 2 + 1) << 8) | smsvdp->m_CRAM->u8(i * 2)) & 0x0fff; |
| 1396 | | } |
| 1397 | | } |
| 1398 | 1624 | } |
| 1399 | 1625 | else |
| 1400 | 1626 | { |
| 1401 | 1627 | for (i = 0; i < 32; i++) |
| 1402 | 1628 | { |
| 1403 | | smsvdp->m_current_palette[i] = smsvdp->m_CRAM->u8(i) & 0x3f; |
| 1629 | m_current_palette[i] = ((m_CRAM->u8(i * 2 + 1) << 8) | m_CRAM->u8(i * 2)) & 0x0fff; |
| 1404 | 1630 | } |
| 1405 | 1631 | } |
| 1406 | 1632 | } |
| 1407 | 1633 | |
| 1408 | 1634 | |
| 1409 | | UINT32 sms_vdp_update( device_t *device, bitmap_t *bitmap, const rectangle *cliprect ) |
| 1635 | void sega315_5124_device::update_video( bitmap_t *bitmap, const rectangle *cliprect ) |
| 1410 | 1636 | { |
| 1411 | | smsvdp_t *smsvdp = get_safe_token(device); |
| 1412 | | copybitmap(bitmap, smsvdp->m_tmpbitmap, 0, 0, 0, 0, cliprect); |
| 1413 | | return 0; |
| 1637 | copybitmap(bitmap, m_tmpbitmap, 0, 0, 0, 0, cliprect); |
| 1414 | 1638 | } |
| 1415 | 1639 | |
| 1416 | 1640 | |
| r13435 | r13436 | |
| 1418 | 1642 | DEVICE INTERFACE |
| 1419 | 1643 | *****************************************************************************/ |
| 1420 | 1644 | |
| 1421 | | static DEVICE_START( smsvdp ) |
| 1645 | void sega315_5124_device::device_config_complete() |
| 1422 | 1646 | { |
| 1423 | | smsvdp_t *smsvdp = get_safe_token(device); |
| 1424 | | const smsvdp_interface *intf = get_interface(device); |
| 1647 | const smsvdp_interface *intf = reinterpret_cast<const smsvdp_interface *>(static_config()); |
| 1425 | 1648 | |
| 1426 | | smsvdp->m_screen = device->machine().device<screen_device>( intf->screen_tag ); |
| 1427 | | int width = smsvdp->m_screen->width(); |
| 1428 | | int height = smsvdp->m_screen->height(); |
| 1649 | if ( intf != NULL ) |
| 1650 | { |
| 1651 | *static_cast<smsvdp_interface *>(this) = *intf; |
| 1652 | } |
| 1653 | else |
| 1654 | { |
| 1655 | fatalerror("No smsvdp_interface supplied\n"); |
| 1656 | } |
| 1657 | } |
| 1429 | 1658 | |
| 1430 | | smsvdp->m_features = intf->model; |
| 1431 | 1659 | |
| 1660 | void sega315_5124_device::device_start() |
| 1661 | { |
| 1662 | m_screen = machine().device<screen_device>( m_screen_tag ); |
| 1663 | int width = m_screen->width(); |
| 1664 | int height = m_screen->height(); |
| 1665 | |
| 1432 | 1666 | /* Resolve callbacks */ |
| 1433 | | smsvdp->m_int_callback.resolve( intf->int_callback, *device ); |
| 1434 | | smsvdp->m_pause_callback.resolve( intf->pause_callback, *device ); |
| 1667 | m_cb_int.resolve( m_int_callback, *this ); |
| 1668 | m_cb_pause.resolve( m_pause_callback, *this ); |
| 1435 | 1669 | |
| 1436 | 1670 | /* Allocate video RAM */ |
| 1437 | | smsvdp->m_VRAM = device->machine().region_alloc("vdp_vram", VRAM_SIZE, 1, ENDIANNESS_LITTLE); |
| 1438 | | smsvdp->m_CRAM = device->machine().region_alloc("vdp_cram", MAX_CRAM_SIZE, 1, ENDIANNESS_LITTLE); |
| 1439 | | smsvdp->m_line_buffer = auto_alloc_array(device->machine(), int, 256 * 5); |
| 1671 | astring tempstring; |
| 1672 | m_VRAM = machine().region_alloc(subtag(tempstring,"vdp_vram"), VRAM_SIZE, 1, ENDIANNESS_LITTLE); |
| 1673 | m_CRAM = machine().region_alloc(subtag(tempstring,"vdp_cram"), SEGA315_5378_CRAM_SIZE, 1, ENDIANNESS_LITTLE); |
| 1674 | m_line_buffer = auto_alloc_array(machine(), int, 256 * 5); |
| 1440 | 1675 | |
| 1441 | | smsvdp->m_collision_buffer = auto_alloc_array(device->machine(), UINT8, SMS_X_PIXELS); |
| 1442 | | smsvdp->m_sms_frame_timing = sms_ntsc_192; |
| 1676 | m_collision_buffer = auto_alloc_array(machine(), UINT8, SMS_X_PIXELS); |
| 1677 | m_frame_timing = (m_is_pal) ? pal_192 : ntsc_192; |
| 1443 | 1678 | |
| 1444 | 1679 | /* Make temp bitmap for rendering */ |
| 1445 | | smsvdp->m_tmpbitmap = auto_bitmap_alloc(device->machine(), width, height, BITMAP_FORMAT_INDEXED32); |
| 1680 | m_tmpbitmap = auto_bitmap_alloc(machine(), width, height, BITMAP_FORMAT_INDEXED32); |
| 1446 | 1681 | |
| 1447 | | smsvdp->m_smsvdp_display_timer = device->machine().scheduler().timer_alloc(FUNC(smsvdp_display_callback), smsvdp); |
| 1448 | | smsvdp->m_smsvdp_display_timer->adjust(smsvdp->m_screen->time_until_pos(0, DISPLAY_CB_HPOS), 0, smsvdp->m_screen->scan_period()); |
| 1682 | m_smsvdp_display_timer = timer_alloc(TIMER_LINE); |
| 1683 | m_smsvdp_display_timer->adjust(m_screen->time_until_pos(0, DISPLAY_CB_HPOS), 0, m_screen->scan_period()); |
| 1684 | m_set_status_vint_timer = timer_alloc( TIMER_SET_STATUS_VINT ); |
| 1685 | m_set_status_sprovr_timer = timer_alloc( TIMER_SET_STATUS_SPROVR ); |
| 1686 | m_check_hint_timer = timer_alloc( TIMER_CHECK_HINT ); |
| 1687 | m_check_vint_timer = timer_alloc( TIMER_CHECK_VINT ); |
| 1449 | 1688 | |
| 1450 | | device->save_item(NAME(smsvdp->m_status)); |
| 1451 | | device->save_item(NAME(smsvdp->m_reg9copy)); |
| 1452 | | device->save_item(NAME(smsvdp->m_addrmode)); |
| 1453 | | device->save_item(NAME(smsvdp->m_addr)); |
| 1454 | | device->save_item(NAME(smsvdp->m_cram_mask)); |
| 1455 | | device->save_item(NAME(smsvdp->m_cram_dirty)); |
| 1456 | | device->save_item(NAME(smsvdp->m_pending)); |
| 1457 | | device->save_item(NAME(smsvdp->m_buffer)); |
| 1458 | | device->save_item(NAME(smsvdp->m_gg_sms_mode)); |
| 1459 | | device->save_item(NAME(smsvdp->m_irq_state)); |
| 1460 | | device->save_item(NAME(smsvdp->m_vdp_mode)); |
| 1461 | | device->save_item(NAME(smsvdp->m_y_pixels)); |
| 1462 | | device->save_item(NAME(smsvdp->m_line_counter)); |
| 1463 | | device->save_item(NAME(smsvdp->m_hcounter)); |
| 1464 | | device->save_item(NAME(smsvdp->m_reg)); |
| 1465 | | device->save_item(NAME(smsvdp->m_current_palette)); |
| 1466 | | device->save_pointer(NAME(smsvdp->m_line_buffer), 256 * 5); |
| 1467 | | device->save_pointer(NAME(smsvdp->m_collision_buffer), SMS_X_PIXELS); |
| 1468 | | device->save_item(NAME(*smsvdp->m_tmpbitmap)); |
| 1689 | save_item(NAME(m_status)); |
| 1690 | save_item(NAME(m_reg9copy)); |
| 1691 | save_item(NAME(m_addrmode)); |
| 1692 | save_item(NAME(m_addr)); |
| 1693 | save_item(NAME(m_cram_mask)); |
| 1694 | save_item(NAME(m_cram_dirty)); |
| 1695 | save_item(NAME(m_pending)); |
| 1696 | save_item(NAME(m_buffer)); |
| 1697 | save_item(NAME(m_gg_sms_mode)); |
| 1698 | save_item(NAME(m_irq_state)); |
| 1699 | save_item(NAME(m_vdp_mode)); |
| 1700 | save_item(NAME(m_y_pixels)); |
| 1701 | save_item(NAME(m_line_counter)); |
| 1702 | save_item(NAME(m_hcounter)); |
| 1703 | save_item(NAME(m_reg)); |
| 1704 | save_item(NAME(m_current_palette)); |
| 1705 | save_pointer(NAME(m_line_buffer), 256 * 5); |
| 1706 | save_pointer(NAME(m_collision_buffer), SMS_X_PIXELS); |
| 1707 | save_item(NAME(*m_tmpbitmap)); |
| 1469 | 1708 | } |
| 1470 | 1709 | |
| 1471 | | static DEVICE_RESET( smsvdp ) |
| 1710 | |
| 1711 | void sega315_5124_device::device_reset() |
| 1472 | 1712 | { |
| 1473 | | smsvdp_t *smsvdp = get_safe_token(device); |
| 1474 | 1713 | int i; |
| 1475 | 1714 | |
| 1476 | 1715 | /* Most register are 0x00 at power-up */ |
| 1477 | | for (i = 0; i < NUM_OF_REGISTER; i++) |
| 1478 | | smsvdp->m_reg[i] = 0x00; |
| 1716 | for (i = 0; i < 16; i++) |
| 1717 | m_reg[i] = 0x00; |
| 1479 | 1718 | |
| 1480 | | smsvdp->m_reg[0x02] = 0x0e; |
| 1481 | | smsvdp->m_reg[0x0a] = 0xff; |
| 1719 | m_reg[0x02] = 0x0e; |
| 1720 | m_reg[0x0a] = 0xff; |
| 1482 | 1721 | |
| 1483 | | smsvdp->m_status = 0; |
| 1484 | | smsvdp->m_reg9copy = 0; |
| 1485 | | smsvdp->m_addrmode = 0; |
| 1486 | | smsvdp->m_addr = 0; |
| 1487 | | smsvdp->m_gg_sms_mode = 0; |
| 1488 | | smsvdp->m_cram_mask = (IS_GAMEGEAR_VDP && !smsvdp->m_gg_sms_mode) ? (GG_CRAM_SIZE - 1) : (SMS_CRAM_SIZE - 1); |
| 1489 | | smsvdp->m_cram_dirty = 1; |
| 1490 | | smsvdp->m_pending = 0; |
| 1491 | | smsvdp->m_buffer = 0; |
| 1492 | | smsvdp->m_irq_state = 0; |
| 1493 | | smsvdp->m_line_counter = 0; |
| 1494 | | smsvdp->m_hcounter = 0; |
| 1722 | m_status = 0; |
| 1723 | m_reg9copy = 0; |
| 1724 | m_addrmode = 0; |
| 1725 | m_addr = 0; |
| 1726 | m_gg_sms_mode = 0; |
| 1727 | m_cram_mask = m_cram_size - 1; |
| 1728 | m_cram_dirty = 1; |
| 1729 | m_pending = 0; |
| 1730 | m_buffer = 0; |
| 1731 | m_irq_state = 0; |
| 1732 | m_line_counter = 0; |
| 1733 | m_hcounter = 0; |
| 1495 | 1734 | |
| 1496 | 1735 | for (i = 0; i < 0x20; i++) |
| 1497 | | smsvdp->m_current_palette[i] = 0; |
| 1736 | m_current_palette[i] = 0; |
| 1498 | 1737 | |
| 1499 | | set_display_settings(device); |
| 1738 | set_display_settings(); |
| 1500 | 1739 | |
| 1501 | 1740 | /* Clear RAM */ |
| 1502 | | memset(smsvdp->m_VRAM->base(), 0, VRAM_SIZE); |
| 1503 | | memset(smsvdp->m_CRAM->base(), 0, MAX_CRAM_SIZE); |
| 1504 | | memset(smsvdp->m_line_buffer, 0, 256 * 5 * sizeof(int)); |
| 1741 | memset(m_VRAM->base(), 0, VRAM_SIZE); |
| 1742 | memset(m_CRAM->base(), 0, SEGA315_5378_CRAM_SIZE); |
| 1743 | memset(m_line_buffer, 0, 256 * 5 * sizeof(int)); |
| 1505 | 1744 | } |
| 1506 | 1745 | |
| 1507 | | DEVICE_GET_INFO( smsvdp ) |
| 1508 | | { |
| 1509 | | switch (state) |
| 1510 | | { |
| 1511 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 1512 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(smsvdp_t); break; |
| 1513 | | |
| 1514 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 1515 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(smsvdp); break; |
| 1516 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 1517 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(smsvdp); break; |
| 1518 | | |
| 1519 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 1520 | | case DEVINFO_STR_NAME: strcpy(info->s, "Sega Master SYstem / Game Gear VDP"); break; |
| 1521 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "Sega MS VDP"); break; |
| 1522 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 1523 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 1524 | | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright MAME / MESS Team"); break; |
| 1525 | | } |
| 1526 | | } |
| 1527 | | |
| 1528 | | DEFINE_LEGACY_DEVICE(SMSVDP, smsvdp); |