src/mess/video/smsvdp.c
| r13341 | r13342 | |
| 50 | 50 | #include "emu.h" |
| 51 | 51 | #include "video/smsvdp.h" |
| 52 | 52 | |
| 53 | | #define IS_SMS1_VDP (smsvdp->features & MODEL_315_5124) |
| 54 | | #define IS_SMS2_VDP (smsvdp->features & MODEL_315_5246) |
| 55 | | #define IS_GAMEGEAR_VDP (smsvdp->features & MODEL_315_5378) |
| 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 | 56 | |
| 57 | 57 | #define STATUS_VINT 0x80 /* Pending vertical interrupt flag */ |
| 58 | 58 | #define STATUS_SPROVR 0x40 /* Sprite overflow flag */ |
| r13341 | r13342 | |
| 74 | 74 | #define VRAM_SIZE 0x4000 |
| 75 | 75 | |
| 76 | 76 | #define PRIORITY_BIT 0x1000 |
| 77 | | #define BACKDROP_COLOR ((smsvdp->vdp_mode == 4 ? 0x10 : 0x00) + (smsvdp->reg[0x07] & 0x0f)) |
| 77 | #define BACKDROP_COLOR ((smsvdp->m_vdp_mode == 4 ? 0x10 : 0x00) + (smsvdp->m_reg[0x07] & 0x0f)) |
| 78 | 78 | |
| 79 | 79 | #define NUM_OF_REGISTER 0x10 /* 16 registers */ |
| 80 | 80 | |
| r13341 | r13342 | |
| 97 | 97 | typedef struct _smsvdp_t smsvdp_t; |
| 98 | 98 | struct _smsvdp_t |
| 99 | 99 | { |
| 100 | | UINT32 features; |
| 101 | | UINT8 reg[NUM_OF_REGISTER]; /* All the registers */ |
| 102 | | UINT8 status; /* Status register */ |
| 103 | | UINT8 reg9copy; /* Internal copy of register 9 */ |
| 104 | | UINT8 addrmode; /* Type of VDP action */ |
| 105 | | UINT16 addr; /* Contents of internal VDP address register */ |
| 106 | | UINT8 cram_mask; /* Mask to switch between SMS and GG CRAM sizes */ |
| 107 | | int cram_dirty; /* Have there been any changes to the CRAM area */ |
| 108 | | int pending; |
| 109 | | UINT8 buffer; |
| 110 | | int gg_sms_mode; /* Shrunk SMS screen on GG lcd mode flag */ |
| 111 | | int irq_state; /* The status of the IRQ line of the VDP */ |
| 112 | | int vdp_mode; /* Current mode of the VDP: 0,1,2,3,4 */ |
| 113 | | int y_pixels; /* 192, 224, 240 */ |
| 114 | | UINT8 line_counter; |
| 115 | | UINT8 hcounter; |
| 116 | | memory_region *VRAM; /* Pointer to VRAM */ |
| 117 | | memory_region *CRAM; /* Pointer to CRAM */ |
| 118 | | const UINT8 *sms_frame_timing; |
| 119 | | bitmap_t *tmpbitmap; |
| 120 | | UINT8 *collision_buffer; |
| 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; |
| 121 | 121 | |
| 122 | 122 | /* line_buffer will be used to hold 5 lines of line data. Line #0 is the regular blitting area. |
| 123 | 123 | Lines #1-#4 will be used as a kind of cache to be used for vertical scaling in the gamegear |
| 124 | 124 | sms compatibility mode. */ |
| 125 | | int *line_buffer; |
| 126 | | int current_palette[32]; |
| 127 | | smsvdp_int_cb int_callback; |
| 128 | | smsvdp_pause_cb pause_callback; |
| 129 | | emu_timer *smsvdp_display_timer; |
| 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 | 130 | }; |
| 131 | 131 | |
| 132 | 132 | static TIMER_CALLBACK( smsvdp_display_callback ); |
| r13341 | r13342 | |
| 166 | 166 | screen_device *screen = device->machine().first_screen(); |
| 167 | 167 | int height = screen->height(); |
| 168 | 168 | int M1, M2, M3, M4; |
| 169 | | M1 = smsvdp->reg[0x01] & 0x10; |
| 170 | | M2 = smsvdp->reg[0x00] & 0x02; |
| 171 | | M3 = smsvdp->reg[0x01] & 0x08; |
| 172 | | M4 = smsvdp->reg[0x00] & 0x04; |
| 173 | | smsvdp->y_pixels = 192; |
| 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; |
| 174 | 174 | if (M4) |
| 175 | 175 | { |
| 176 | 176 | /* mode 4 */ |
| 177 | | smsvdp->vdp_mode = 4; |
| 177 | smsvdp->m_vdp_mode = 4; |
| 178 | 178 | if (M2 && (IS_SMS2_VDP || IS_GAMEGEAR_VDP)) |
| 179 | 179 | { |
| 180 | 180 | if (M1 && !M3) |
| 181 | | smsvdp->y_pixels = 224; /* 224-line display */ |
| 181 | smsvdp->m_y_pixels = 224; /* 224-line display */ |
| 182 | 182 | else if (!M1 && M3) |
| 183 | | smsvdp->y_pixels = 240; /* 240-line display */ |
| 183 | smsvdp->m_y_pixels = 240; /* 240-line display */ |
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | else |
| r13341 | r13342 | |
| 188 | 188 | /* original TMS9918 mode */ |
| 189 | 189 | if (!M1 && !M2 && !M3) |
| 190 | 190 | { |
| 191 | | smsvdp->vdp_mode = 0; |
| 191 | smsvdp->m_vdp_mode = 0; |
| 192 | 192 | } |
| 193 | 193 | else |
| 194 | 194 | // if (M1 && !M2 && !M3) |
| 195 | 195 | // { |
| 196 | | // smsvdp->vdp_mode = 1; |
| 196 | // smsvdp->m_vdp_mode = 1; |
| 197 | 197 | // } |
| 198 | 198 | // else |
| 199 | 199 | if (!M1 && M2 && !M3) |
| 200 | 200 | { |
| 201 | | smsvdp->vdp_mode = 2; |
| 201 | smsvdp->m_vdp_mode = 2; |
| 202 | 202 | // } |
| 203 | 203 | // else |
| 204 | 204 | // if (!M1 && !M2 && M3) |
| 205 | 205 | // { |
| 206 | | // smsvdp->vdp_mode = 3; |
| 206 | // smsvdp->m_vdp_mode = 3; |
| 207 | 207 | } |
| 208 | 208 | else |
| 209 | 209 | { |
| r13341 | r13342 | |
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | | switch (smsvdp->y_pixels) |
| 214 | switch (smsvdp->m_y_pixels) |
| 215 | 215 | { |
| 216 | 216 | case 192: |
| 217 | | smsvdp->sms_frame_timing = (height == PAL_Y_PIXELS) ? sms_pal_192 : sms_ntsc_192; |
| 217 | smsvdp->m_sms_frame_timing = (height == SMS_PAL_Y_PIXELS) ? sms_pal_192 : sms_ntsc_192; |
| 218 | 218 | break; |
| 219 | 219 | |
| 220 | 220 | case 224: |
| 221 | | smsvdp->sms_frame_timing = (height == PAL_Y_PIXELS) ? sms_pal_224 : sms_ntsc_224; |
| 221 | smsvdp->m_sms_frame_timing = (height == SMS_PAL_Y_PIXELS) ? sms_pal_224 : sms_ntsc_224; |
| 222 | 222 | break; |
| 223 | 223 | |
| 224 | 224 | case 240: |
| 225 | | smsvdp->sms_frame_timing = (height == PAL_Y_PIXELS) ? sms_pal_240 : sms_ntsc_240; |
| 225 | smsvdp->m_sms_frame_timing = (height == SMS_PAL_Y_PIXELS) ? sms_pal_240 : sms_ntsc_240; |
| 226 | 226 | break; |
| 227 | 227 | } |
| 228 | | smsvdp->cram_dirty = 1; |
| 228 | smsvdp->m_cram_dirty = 1; |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | |
| r13341 | r13342 | |
| 241 | 241 | vpos += device->machine().primary_screen->height(); |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | | return (smsvdp->sms_frame_timing[INIT_VCOUNT] + vpos) & 0xff; |
| 244 | return (smsvdp->m_sms_frame_timing[INIT_VCOUNT] + vpos) & 0xff; |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | |
| r13341 | r13342 | |
| 249 | 249 | { |
| 250 | 250 | smsvdp_t *smsvdp = get_safe_token(device); |
| 251 | 251 | |
| 252 | | return smsvdp->hcounter; |
| 252 | return smsvdp->m_hcounter; |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | WRITE8_DEVICE_HANDLER( sms_vdp_hcount_latch_w ) |
| 256 | 256 | { |
| 257 | 257 | smsvdp_t *smsvdp = get_safe_token(device); |
| 258 | 258 | |
| 259 | | smsvdp->hcounter = data; |
| 259 | smsvdp->m_hcounter = data; |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | |
| r13341 | r13342 | |
| 264 | 264 | { |
| 265 | 265 | smsvdp_t *smsvdp = get_safe_token(device); |
| 266 | 266 | |
| 267 | | smsvdp->gg_sms_mode = mode; |
| 268 | | smsvdp->cram_mask = (IS_GAMEGEAR_VDP && !smsvdp->gg_sms_mode) ? (GG_CRAM_SIZE - 1) : (SMS_CRAM_SIZE - 1); |
| 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); |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | |
| r13341 | r13342 | |
| 273 | 273 | { |
| 274 | 274 | smsvdp_t *smsvdp = (smsvdp_t *) ptr; |
| 275 | 275 | |
| 276 | | smsvdp->status |= (UINT8) param; |
| 276 | smsvdp->m_status |= (UINT8) param; |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | |
| r13341 | r13342 | |
| 281 | 281 | { |
| 282 | 282 | smsvdp_t *smsvdp = (smsvdp_t *) ptr; |
| 283 | 283 | |
| 284 | | if (smsvdp->line_counter == 0x00) |
| 284 | if (smsvdp->m_line_counter == 0x00) |
| 285 | 285 | { |
| 286 | | smsvdp->line_counter = smsvdp->reg[0x0a]; |
| 287 | | smsvdp->status |= STATUS_HINT; |
| 286 | smsvdp->m_line_counter = smsvdp->m_reg[0x0a]; |
| 287 | smsvdp->m_status |= STATUS_HINT; |
| 288 | 288 | } |
| 289 | 289 | else |
| 290 | 290 | { |
| 291 | | smsvdp->line_counter--; |
| 291 | smsvdp->m_line_counter--; |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | | if ((smsvdp->status & STATUS_HINT) && (smsvdp->reg[0x00] & 0x10)) |
| 294 | if ((smsvdp->m_status & STATUS_HINT) && (smsvdp->m_reg[0x00] & 0x10)) |
| 295 | 295 | { |
| 296 | | smsvdp->irq_state = 1; |
| 296 | smsvdp->m_irq_state = 1; |
| 297 | 297 | |
| 298 | | if (smsvdp->int_callback) |
| 299 | | smsvdp->int_callback(machine, ASSERT_LINE); |
| 298 | smsvdp->m_int_callback(ASSERT_LINE); |
| 300 | 299 | } |
| 301 | 300 | } |
| 302 | 301 | |
| r13341 | r13342 | |
| 305 | 304 | { |
| 306 | 305 | smsvdp_t *smsvdp = (smsvdp_t *) ptr; |
| 307 | 306 | |
| 308 | | if ((smsvdp->status & STATUS_VINT) && (smsvdp->reg[0x01] & 0x20)) |
| 307 | if ((smsvdp->m_status & STATUS_VINT) && (smsvdp->m_reg[0x01] & 0x20)) |
| 309 | 308 | { |
| 310 | | smsvdp->irq_state = 1; |
| 309 | smsvdp->m_irq_state = 1; |
| 311 | 310 | |
| 312 | | if (smsvdp->int_callback) |
| 313 | | smsvdp->int_callback(machine, ASSERT_LINE); |
| 311 | smsvdp->m_int_callback(ASSERT_LINE); |
| 314 | 312 | } |
| 315 | 313 | } |
| 316 | 314 | |
| r13341 | r13342 | |
| 321 | 319 | |
| 322 | 320 | rectangle rec; |
| 323 | 321 | int vpos = machine.primary_screen->vpos(); |
| 324 | | int vpos_limit = smsvdp->sms_frame_timing[VERTICAL_BLANKING] + smsvdp->sms_frame_timing[TOP_BLANKING] |
| 325 | | + smsvdp->sms_frame_timing[TOP_BORDER] + smsvdp->sms_frame_timing[ACTIVE_DISPLAY_V] |
| 326 | | + smsvdp->sms_frame_timing[BOTTOM_BORDER] + smsvdp->sms_frame_timing[BOTTOM_BLANKING]; |
| 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]; |
| 327 | 325 | |
| 328 | 326 | rec.min_y = rec.max_y = vpos; |
| 329 | 327 | |
| 330 | 328 | /* Check if we're on the last line of a frame */ |
| 331 | 329 | if (vpos == vpos_limit - 1) |
| 332 | 330 | { |
| 333 | | smsvdp->line_counter = smsvdp->reg[0x0a]; |
| 334 | | if (smsvdp->pause_callback) |
| 335 | | smsvdp->pause_callback(machine); |
| 331 | smsvdp->m_line_counter = smsvdp->m_reg[0x0a]; |
| 332 | smsvdp->m_pause_callback(0); |
| 336 | 333 | |
| 337 | 334 | return; |
| 338 | 335 | } |
| 339 | 336 | |
| 340 | | vpos_limit -= smsvdp->sms_frame_timing[BOTTOM_BLANKING]; |
| 337 | vpos_limit -= smsvdp->m_sms_frame_timing[BOTTOM_BLANKING]; |
| 341 | 338 | |
| 342 | 339 | /* Check if we're below the bottom border */ |
| 343 | 340 | if (vpos >= vpos_limit) |
| 344 | 341 | { |
| 345 | | smsvdp->line_counter = smsvdp->reg[0x0a]; |
| 342 | smsvdp->m_line_counter = smsvdp->m_reg[0x0a]; |
| 346 | 343 | return; |
| 347 | 344 | } |
| 348 | 345 | |
| 349 | | vpos_limit -= smsvdp->sms_frame_timing[BOTTOM_BORDER]; |
| 346 | vpos_limit -= smsvdp->m_sms_frame_timing[BOTTOM_BORDER]; |
| 350 | 347 | |
| 351 | 348 | /* Check if we're in the bottom border area */ |
| 352 | 349 | if (vpos >= vpos_limit) |
| r13341 | r13342 | |
| 357 | 354 | } |
| 358 | 355 | else |
| 359 | 356 | { |
| 360 | | smsvdp->line_counter = smsvdp->reg[0x0a]; |
| 357 | smsvdp->m_line_counter = smsvdp->m_reg[0x0a]; |
| 361 | 358 | } |
| 362 | 359 | |
| 363 | 360 | if (vpos == vpos_limit + 1) |
| r13341 | r13342 | |
| 369 | 366 | sms_update_palette(smsvdp); |
| 370 | 367 | |
| 371 | 368 | /* Draw left border */ |
| 372 | | rec.min_x = LBORDER_START; |
| 373 | | rec.max_x = LBORDER_START + LBORDER_X_PIXELS - 1; |
| 374 | | bitmap_fill(smsvdp->tmpbitmap, &rec, machine.pens[smsvdp->current_palette[BACKDROP_COLOR]]); |
| 369 | rec.min_x = SMS_LBORDER_START; |
| 370 | 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]]); |
| 375 | 372 | |
| 376 | 373 | /* Draw right border */ |
| 377 | | rec.min_x = LBORDER_START + LBORDER_X_PIXELS + 256; |
| 378 | | rec.max_x = rec.min_x + RBORDER_X_PIXELS - 1; |
| 379 | | bitmap_fill(smsvdp->tmpbitmap, &rec, machine.pens[smsvdp->current_palette[BACKDROP_COLOR]]); |
| 374 | rec.min_x = SMS_LBORDER_START + SMS_LBORDER_X_PIXELS + 256; |
| 375 | 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]]); |
| 380 | 377 | |
| 381 | 378 | /* Draw middle of the border */ |
| 382 | 379 | /* We need to do this through the regular drawing function so it will */ |
| 383 | 380 | /* be included in the gamegear scaling functions */ |
| 384 | | sms_refresh_line(machine, smsvdp, smsvdp->tmpbitmap, LBORDER_START + LBORDER_X_PIXELS, vpos_limit - smsvdp->sms_frame_timing[ACTIVE_DISPLAY_V], vpos - (vpos_limit - smsvdp->sms_frame_timing[ACTIVE_DISPLAY_V])); |
| 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])); |
| 385 | 382 | return; |
| 386 | 383 | } |
| 387 | 384 | |
| 388 | | vpos_limit -= smsvdp->sms_frame_timing[ACTIVE_DISPLAY_V]; |
| 385 | vpos_limit -= smsvdp->m_sms_frame_timing[ACTIVE_DISPLAY_V]; |
| 389 | 386 | |
| 390 | 387 | /* Check if we're in the active display area */ |
| 391 | 388 | if (vpos >= vpos_limit) |
| 392 | 389 | { |
| 393 | 390 | if (vpos == vpos_limit) |
| 394 | 391 | { |
| 395 | | smsvdp->reg9copy = smsvdp->reg[0x09]; |
| 392 | smsvdp->m_reg9copy = smsvdp->m_reg[0x09]; |
| 396 | 393 | } |
| 397 | 394 | |
| 398 | 395 | machine.scheduler().timer_set(machine.primary_screen->time_until_pos(vpos, HINT_HPOS), FUNC(smsvdp_check_hint),0, smsvdp); |
| r13341 | r13342 | |
| 400 | 397 | sms_update_palette(smsvdp); |
| 401 | 398 | |
| 402 | 399 | /* Draw left border */ |
| 403 | | rec.min_x = LBORDER_START; |
| 404 | | rec.max_x = LBORDER_START + LBORDER_X_PIXELS - 1; |
| 405 | | bitmap_fill(smsvdp->tmpbitmap, &rec, machine.pens[smsvdp->current_palette[BACKDROP_COLOR]]); |
| 400 | rec.min_x = SMS_LBORDER_START; |
| 401 | 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]]); |
| 406 | 403 | |
| 407 | 404 | /* Draw right border */ |
| 408 | | rec.min_x = LBORDER_START + LBORDER_X_PIXELS + 256; |
| 409 | | rec.max_x = rec.min_x + RBORDER_X_PIXELS - 1; |
| 410 | | bitmap_fill(smsvdp->tmpbitmap, &rec, machine.pens[smsvdp->current_palette[BACKDROP_COLOR]]); |
| 405 | rec.min_x = SMS_LBORDER_START + SMS_LBORDER_X_PIXELS + 256; |
| 406 | 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]]); |
| 411 | 408 | |
| 412 | | sms_refresh_line(machine, smsvdp, smsvdp->tmpbitmap, LBORDER_START + LBORDER_X_PIXELS, vpos_limit, vpos - vpos_limit); |
| 409 | sms_refresh_line(machine, smsvdp, smsvdp->m_tmpbitmap, SMS_LBORDER_START + SMS_LBORDER_X_PIXELS, vpos_limit, vpos - vpos_limit); |
| 413 | 410 | |
| 414 | 411 | return; |
| 415 | 412 | } |
| 416 | 413 | |
| 417 | | vpos_limit -= smsvdp->sms_frame_timing[TOP_BORDER]; |
| 414 | vpos_limit -= smsvdp->m_sms_frame_timing[TOP_BORDER]; |
| 418 | 415 | |
| 419 | 416 | /* Check if we're in the top border area */ |
| 420 | 417 | if (vpos >= vpos_limit) |
| 421 | 418 | { |
| 422 | | smsvdp->line_counter = smsvdp->reg[0x0a]; |
| 419 | smsvdp->m_line_counter = smsvdp->m_reg[0x0a]; |
| 423 | 420 | sms_update_palette(smsvdp); |
| 424 | 421 | |
| 425 | 422 | /* Draw left border */ |
| 426 | | rec.min_x = LBORDER_START; |
| 427 | | rec.max_x = LBORDER_START + LBORDER_X_PIXELS - 1; |
| 428 | | bitmap_fill(smsvdp->tmpbitmap, &rec, machine.pens[smsvdp->current_palette[BACKDROP_COLOR]]); |
| 423 | rec.min_x = SMS_LBORDER_START; |
| 424 | 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]]); |
| 429 | 426 | |
| 430 | 427 | /* Draw right border */ |
| 431 | | rec.min_x = LBORDER_START + LBORDER_X_PIXELS + 256; |
| 432 | | rec.max_x = rec.min_x + RBORDER_X_PIXELS - 1; |
| 433 | | bitmap_fill(smsvdp->tmpbitmap, &rec, machine.pens[smsvdp->current_palette[BACKDROP_COLOR]]); |
| 428 | rec.min_x = SMS_LBORDER_START + SMS_LBORDER_X_PIXELS + 256; |
| 429 | 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]]); |
| 434 | 431 | |
| 435 | 432 | /* Draw middle of the border */ |
| 436 | 433 | /* We need to do this through the regular drawing function so it will */ |
| 437 | 434 | /* be included in the gamegear scaling functions */ |
| 438 | | sms_refresh_line(machine, smsvdp, smsvdp->tmpbitmap, LBORDER_START + LBORDER_X_PIXELS, vpos_limit + smsvdp->sms_frame_timing[TOP_BORDER], vpos - (vpos_limit + smsvdp->sms_frame_timing[TOP_BORDER])); |
| 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])); |
| 439 | 436 | return; |
| 440 | 437 | } |
| 441 | 438 | |
| 442 | 439 | /* we're in the vertical or top blanking area */ |
| 443 | | smsvdp->line_counter = smsvdp->reg[0x0a]; |
| 440 | smsvdp->m_line_counter = smsvdp->m_reg[0x0a]; |
| 444 | 441 | } |
| 445 | 442 | |
| 446 | 443 | |
| r13341 | r13342 | |
| 453 | 450 | /* to the address register when in the middle of doing a command. */ |
| 454 | 451 | /* Cosmic Spacehead needs this, among others */ |
| 455 | 452 | /* Clear pending write flag */ |
| 456 | | smsvdp->pending = 0; |
| 453 | smsvdp->m_pending = 0; |
| 457 | 454 | |
| 458 | 455 | /* Return read buffer contents */ |
| 459 | | temp = smsvdp->buffer; |
| 456 | temp = smsvdp->m_buffer; |
| 460 | 457 | |
| 461 | 458 | /* Load read buffer */ |
| 462 | | smsvdp->buffer = smsvdp->VRAM->u8((smsvdp->addr & 0x3fff)); |
| 459 | smsvdp->m_buffer = smsvdp->m_VRAM->u8((smsvdp->m_addr & 0x3fff)); |
| 463 | 460 | |
| 464 | 461 | /* Bump internal address register */ |
| 465 | | smsvdp->addr += 1; |
| 462 | smsvdp->m_addr += 1; |
| 466 | 463 | return temp; |
| 467 | 464 | } |
| 468 | 465 | |
| r13341 | r13342 | |
| 471 | 468 | { |
| 472 | 469 | smsvdp_t *smsvdp = get_safe_token(device); |
| 473 | 470 | |
| 474 | | UINT8 temp = smsvdp->status; |
| 471 | UINT8 temp = smsvdp->m_status; |
| 475 | 472 | |
| 476 | 473 | /* Clear pending write flag */ |
| 477 | | smsvdp->pending = 0; |
| 474 | smsvdp->m_pending = 0; |
| 478 | 475 | |
| 479 | | smsvdp->status &= ~(STATUS_VINT | STATUS_SPROVR | STATUS_SPRCOL | STATUS_HINT); |
| 476 | smsvdp->m_status &= ~(STATUS_VINT | STATUS_SPROVR | STATUS_SPRCOL | STATUS_HINT); |
| 480 | 477 | |
| 481 | | if (smsvdp->irq_state == 1) |
| 478 | if (smsvdp->m_irq_state == 1) |
| 482 | 479 | { |
| 483 | | smsvdp->irq_state = 0; |
| 480 | smsvdp->m_irq_state = 0; |
| 484 | 481 | |
| 485 | | if (smsvdp->int_callback) |
| 486 | | smsvdp->int_callback(device->machine(), CLEAR_LINE); |
| 482 | smsvdp->m_int_callback(CLEAR_LINE); |
| 487 | 483 | } |
| 488 | 484 | |
| 489 | 485 | /* low 5 bits return non-zero data (it fixes PGA Tour Golf course map introduction) */ |
| r13341 | r13342 | |
| 500 | 496 | /* to the address register when in the middle of doing a command. */ |
| 501 | 497 | /* Cosmic Spacehead needs this, among others */ |
| 502 | 498 | /* Clear pending write flag */ |
| 503 | | smsvdp->pending = 0; |
| 499 | smsvdp->m_pending = 0; |
| 504 | 500 | |
| 505 | | switch(smsvdp->addrmode) |
| 501 | switch(smsvdp->m_addrmode) |
| 506 | 502 | { |
| 507 | 503 | case 0x00: |
| 508 | 504 | case 0x01: |
| 509 | 505 | case 0x02: |
| 510 | | address = (smsvdp->addr & 0x3fff); |
| 511 | | smsvdp->VRAM->u8(address) = data; |
| 506 | address = (smsvdp->m_addr & 0x3fff); |
| 507 | smsvdp->m_VRAM->u8(address) = data; |
| 512 | 508 | break; |
| 513 | 509 | |
| 514 | 510 | case 0x03: |
| 515 | | address = smsvdp->addr & smsvdp->cram_mask; |
| 516 | | if (data != smsvdp->CRAM->u8(address)) |
| 511 | address = smsvdp->m_addr & smsvdp->m_cram_mask; |
| 512 | if (data != smsvdp->m_CRAM->u8(address)) |
| 517 | 513 | { |
| 518 | | smsvdp->CRAM->u8(address) = data; |
| 519 | | smsvdp->cram_dirty = 1; |
| 514 | smsvdp->m_CRAM->u8(address) = data; |
| 515 | smsvdp->m_cram_dirty = 1; |
| 520 | 516 | } |
| 521 | 517 | break; |
| 522 | 518 | } |
| 523 | 519 | |
| 524 | | smsvdp->buffer = data; |
| 525 | | smsvdp->addr += 1; |
| 520 | smsvdp->m_buffer = data; |
| 521 | smsvdp->m_addr += 1; |
| 526 | 522 | } |
| 527 | 523 | |
| 528 | 524 | |
| r13341 | r13342 | |
| 532 | 528 | |
| 533 | 529 | int reg_num; |
| 534 | 530 | |
| 535 | | if (smsvdp->pending == 0) |
| 531 | if (smsvdp->m_pending == 0) |
| 536 | 532 | { |
| 537 | | smsvdp->addr = (smsvdp->addr & 0xff00) | data; |
| 538 | | smsvdp->pending = 1; |
| 533 | smsvdp->m_addr = (smsvdp->m_addr & 0xff00) | data; |
| 534 | smsvdp->m_pending = 1; |
| 539 | 535 | } |
| 540 | 536 | else |
| 541 | 537 | { |
| 542 | 538 | /* Clear pending write flag */ |
| 543 | | smsvdp->pending = 0; |
| 539 | smsvdp->m_pending = 0; |
| 544 | 540 | |
| 545 | | smsvdp->addrmode = (data >> 6) & 0x03; |
| 546 | | smsvdp->addr = (data << 8) | (smsvdp->addr & 0xff); |
| 547 | | switch (smsvdp->addrmode) |
| 541 | smsvdp->m_addrmode = (data >> 6) & 0x03; |
| 542 | smsvdp->m_addr = (data << 8) | (smsvdp->m_addr & 0xff); |
| 543 | switch (smsvdp->m_addrmode) |
| 548 | 544 | { |
| 549 | 545 | case 0: /* VRAM reading mode */ |
| 550 | | smsvdp->buffer = smsvdp->VRAM->u8(smsvdp->addr & 0x3fff); |
| 551 | | smsvdp->addr += 1; |
| 546 | smsvdp->m_buffer = smsvdp->m_VRAM->u8(smsvdp->m_addr & 0x3fff); |
| 547 | smsvdp->m_addr += 1; |
| 552 | 548 | break; |
| 553 | 549 | |
| 554 | 550 | case 1: /* VRAM writing mode */ |
| r13341 | r13342 | |
| 556 | 552 | |
| 557 | 553 | case 2: /* VDP register write */ |
| 558 | 554 | reg_num = data & 0x0f; |
| 559 | | smsvdp->reg[reg_num] = smsvdp->addr & 0xff; |
| 560 | | if (reg_num == 0 && smsvdp->addr & 0x02) |
| 555 | smsvdp->m_reg[reg_num] = smsvdp->m_addr & 0xff; |
| 556 | if (reg_num == 0 && smsvdp->m_addr & 0x02) |
| 561 | 557 | logerror("overscan enabled.\n"); |
| 562 | 558 | |
| 563 | 559 | if (reg_num == 0 || reg_num == 1) |
| r13341 | r13342 | |
| 567 | 563 | { |
| 568 | 564 | device->machine().scheduler().timer_set(device->machine().primary_screen->time_until_pos(device->machine().primary_screen->vpos(), VINT_HPOS), FUNC(smsvdp_check_vint),0 ,smsvdp); |
| 569 | 565 | } |
| 570 | | smsvdp->addrmode = 0; |
| 566 | smsvdp->m_addrmode = 0; |
| 571 | 567 | break; |
| 572 | 568 | |
| 573 | 569 | case 3: /* CRAM writing mode */ |
| r13341 | r13342 | |
| 587 | 583 | UINT16 name_table_address; |
| 588 | 584 | UINT8 *name_table; |
| 589 | 585 | |
| 590 | | if (smsvdp->y_pixels != 192) |
| 586 | if (smsvdp->m_y_pixels != 192) |
| 591 | 587 | { |
| 592 | | name_table_address = ((smsvdp->reg[0x02] & 0x0c) << 10) | 0x0700; |
| 588 | name_table_address = ((smsvdp->m_reg[0x02] & 0x0c) << 10) | 0x0700; |
| 593 | 589 | scroll_mod = 256; |
| 594 | 590 | } |
| 595 | 591 | else |
| 596 | 592 | { |
| 597 | | name_table_address = (smsvdp->reg[0x02] << 10) & 0x3800; |
| 593 | name_table_address = (smsvdp->m_reg[0x02] << 10) & 0x3800; |
| 598 | 594 | scroll_mod = 224; |
| 599 | 595 | } |
| 600 | 596 | |
| 601 | 597 | if (IS_SMS1_VDP) |
| 602 | | name_table_address = name_table_address & (((smsvdp->reg[0x02] & 0x01) << 10) | 0x3bff); |
| 598 | name_table_address = name_table_address & (((smsvdp->m_reg[0x02] & 0x01) << 10) | 0x3bff); |
| 603 | 599 | |
| 604 | 600 | /* if top 2 rows of screen not affected by horizontal scrolling, then x_scroll = 0 */ |
| 605 | | /* else x_scroll = reg[0x08] */ |
| 606 | | x_scroll = (((smsvdp->reg[0x00] & 0x40) && (line < 16)) ? 0 : 0x0100 - smsvdp->reg[0x08]); |
| 601 | /* else x_scroll = m_reg[0x08] */ |
| 602 | x_scroll = (((smsvdp->m_reg[0x00] & 0x40) && (line < 16)) ? 0 : 0x0100 - smsvdp->m_reg[0x08]); |
| 607 | 603 | |
| 608 | 604 | x_scroll_start_column = (x_scroll >> 3); /* x starting column tile */ |
| 609 | 605 | |
| r13341 | r13342 | |
| 616 | 612 | |
| 617 | 613 | /* Rightmost 8 columns for SMS (or 2 columns for GG) not affected by */ |
| 618 | 614 | /* vertical scrolling when bit 7 of reg[0x00] is set */ |
| 619 | | y_scroll = ((smsvdp->reg[0x00] & 0x80) && (tile_column > 23)) ? 0 : smsvdp->reg9copy; |
| 615 | y_scroll = ((smsvdp->m_reg[0x00] & 0x80) && (tile_column > 23)) ? 0 : smsvdp->m_reg9copy; |
| 620 | 616 | |
| 621 | | name_table = smsvdp->VRAM->base() + name_table_address + ((((line + y_scroll) % scroll_mod) >> 3) << 6); |
| 617 | name_table = smsvdp->m_VRAM->base() + name_table_address + ((((line + y_scroll) % scroll_mod) >> 3) << 6); |
| 622 | 618 | |
| 623 | 619 | tile_line = ((tile_column + x_scroll_start_column) & 0x1f) * 2; |
| 624 | 620 | tile_data = name_table[tile_line] | (name_table[tile_line + 1] << 8); |
| r13341 | r13342 | |
| 633 | 629 | if (vert_selected) |
| 634 | 630 | tile_line = 0x07 - tile_line; |
| 635 | 631 | |
| 636 | | bit_plane_0 = smsvdp->VRAM->u8(((tile_selected << 5) + ((tile_line & 0x07) << 2)) + 0x00); |
| 637 | | bit_plane_1 = smsvdp->VRAM->u8(((tile_selected << 5) + ((tile_line & 0x07) << 2)) + 0x01); |
| 638 | | bit_plane_2 = smsvdp->VRAM->u8(((tile_selected << 5) + ((tile_line & 0x07) << 2)) + 0x02); |
| 639 | | bit_plane_3 = smsvdp->VRAM->u8(((tile_selected << 5) + ((tile_line & 0x07) << 2)) + 0x03); |
| 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); |
| 640 | 636 | |
| 641 | 637 | for (pixel_x = 0; pixel_x < 8 ; pixel_x++) |
| 642 | 638 | { |
| r13341 | r13342 | |
| 665 | 661 | if (pixel_plot_x >= 0 && pixel_plot_x < 256) |
| 666 | 662 | { |
| 667 | 663 | // logerror("%x %x\n", pixel_plot_x + pixel_offset_x, pixel_plot_y); |
| 668 | | line_buffer[pixel_plot_x] = smsvdp->current_palette[pen_selected]; |
| 664 | line_buffer[pixel_plot_x] = smsvdp->m_current_palette[pen_selected]; |
| 669 | 665 | priority_selected[pixel_plot_x] = priority_select | (pen_selected & 0x0f); |
| 670 | 666 | } |
| 671 | 667 | } |
| r13341 | r13342 | |
| 680 | 676 | int sprite_col_occurred, sprite_col_x; |
| 681 | 677 | int sprite_buffer[8], sprite_buffer_count, sprite_buffer_index; |
| 682 | 678 | int bit_plane_0, bit_plane_1, bit_plane_2, bit_plane_3; |
| 683 | | UINT8 *sprite_table = smsvdp->VRAM->base() + ((smsvdp->reg[0x05] << 7) & 0x3f00); |
| 679 | UINT8 *sprite_table = smsvdp->m_VRAM->base() + ((smsvdp->m_reg[0x05] << 7) & 0x3f00); |
| 684 | 680 | |
| 685 | 681 | /* Draw sprite layer */ |
| 686 | | sprite_height = (smsvdp->reg[0x01] & 0x02 ? 16 : 8); |
| 682 | sprite_height = (smsvdp->m_reg[0x01] & 0x02 ? 16 : 8); |
| 687 | 683 | sprite_zoom = 1; |
| 688 | 684 | |
| 689 | | if (smsvdp->reg[0x01] & 0x01) /* sprite doubling */ |
| 685 | if (smsvdp->m_reg[0x01] & 0x01) /* sprite doubling */ |
| 690 | 686 | sprite_zoom = 2; |
| 691 | 687 | |
| 692 | 688 | sprite_buffer_count = 0; |
| 693 | | for (sprite_index = 0; (sprite_index < 64) && (sprite_table[sprite_index] != 0xd0 || smsvdp->y_pixels != 192) && (sprite_buffer_count < 9); sprite_index++) |
| 689 | for (sprite_index = 0; (sprite_index < 64) && (sprite_table[sprite_index] != 0xd0 || smsvdp->m_y_pixels != 192) && (sprite_buffer_count < 9); sprite_index++) |
| 694 | 690 | { |
| 695 | 691 | sprite_y = sprite_table[sprite_index] + 1; /* sprite y position starts at line 1 */ |
| 696 | 692 | |
| r13341 | r13342 | |
| 703 | 699 | { |
| 704 | 700 | sprite_buffer[sprite_buffer_count] = sprite_index; |
| 705 | 701 | } |
| 706 | | else if (line >= 0 && line < smsvdp->sms_frame_timing[ACTIVE_DISPLAY_V]) |
| 702 | else if (line >= 0 && line < smsvdp->m_sms_frame_timing[ACTIVE_DISPLAY_V]) |
| 707 | 703 | { |
| 708 | 704 | /* Too many sprites per line */ |
| 709 | 705 | machine.scheduler().timer_set(machine.primary_screen->time_until_pos(pixel_plot_y + line, SPROVR_HPOS), FUNC(smsvdp_set_status), (int)STATUS_SPROVR, smsvdp); |
| r13341 | r13342 | |
| 713 | 709 | } |
| 714 | 710 | |
| 715 | 711 | /* Check if display is disabled */ |
| 716 | | if (!(smsvdp->reg[0x01] & 0x40)) |
| 712 | if (!(smsvdp->m_reg[0x01] & 0x40)) |
| 717 | 713 | return; |
| 718 | 714 | |
| 719 | 715 | if (sprite_buffer_count > 8) |
| 720 | 716 | sprite_buffer_count = 8; |
| 721 | 717 | |
| 722 | | memset(smsvdp->collision_buffer, 0, SMS_X_PIXELS); |
| 718 | memset(smsvdp->m_collision_buffer, 0, SMS_X_PIXELS); |
| 723 | 719 | sprite_buffer_count--; |
| 724 | 720 | |
| 725 | 721 | for (sprite_buffer_index = sprite_buffer_count; sprite_buffer_index >= 0; sprite_buffer_index--) |
| r13341 | r13342 | |
| 732 | 728 | |
| 733 | 729 | sprite_x = sprite_table[0x80 + (sprite_index << 1)]; |
| 734 | 730 | |
| 735 | | if (smsvdp->reg[0x00] & 0x08) |
| 731 | if (smsvdp->m_reg[0x00] & 0x08) |
| 736 | 732 | sprite_x -= 0x08; /* sprite shift */ |
| 737 | 733 | |
| 738 | 734 | sprite_tile_selected = sprite_table[0x81 + (sprite_index << 1)]; |
| 739 | 735 | |
| 740 | | if (smsvdp->reg[0x06] & 0x04) |
| 736 | if (smsvdp->m_reg[0x06] & 0x04) |
| 741 | 737 | sprite_tile_selected += 256; /* pattern table select */ |
| 742 | 738 | |
| 743 | | if (smsvdp->reg[0x01] & 0x02) |
| 739 | if (smsvdp->m_reg[0x01] & 0x02) |
| 744 | 740 | sprite_tile_selected &= 0x01fe; /* force even index */ |
| 745 | 741 | |
| 746 | 742 | sprite_line = (line - sprite_y) / sprite_zoom; |
| r13341 | r13342 | |
| 748 | 744 | if (sprite_line > 0x07) |
| 749 | 745 | sprite_tile_selected += 1; |
| 750 | 746 | |
| 751 | | bit_plane_0 = smsvdp->VRAM->u8(((sprite_tile_selected << 5) + ((sprite_line & 0x07) << 2)) + 0x00); |
| 752 | | bit_plane_1 = smsvdp->VRAM->u8(((sprite_tile_selected << 5) + ((sprite_line & 0x07) << 2)) + 0x01); |
| 753 | | bit_plane_2 = smsvdp->VRAM->u8(((sprite_tile_selected << 5) + ((sprite_line & 0x07) << 2)) + 0x02); |
| 754 | | bit_plane_3 = smsvdp->VRAM->u8(((sprite_tile_selected << 5) + ((sprite_line & 0x07) << 2)) + 0x03); |
| 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); |
| 755 | 751 | |
| 756 | 752 | sprite_col_occurred = 0; |
| 757 | 753 | sprite_col_x = 0; |
| r13341 | r13342 | |
| 773 | 769 | continue; |
| 774 | 770 | } |
| 775 | 771 | |
| 776 | | if (smsvdp->reg[0x01] & 0x01) |
| 772 | if (smsvdp->m_reg[0x01] & 0x01) |
| 777 | 773 | { |
| 778 | 774 | /* sprite doubling is enabled */ |
| 779 | 775 | pixel_plot_x = sprite_x + (pixel_x << 1); |
| r13341 | r13342 | |
| 786 | 782 | |
| 787 | 783 | if (!(priority_selected[pixel_plot_x] & PRIORITY_BIT)) |
| 788 | 784 | { |
| 789 | | line_buffer[pixel_plot_x] = smsvdp->current_palette[pen_selected]; |
| 790 | | line_buffer[pixel_plot_x + 1] = smsvdp->current_palette[pen_selected]; |
| 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]; |
| 791 | 787 | } |
| 792 | 788 | else |
| 793 | 789 | { |
| 794 | 790 | if (priority_selected[pixel_plot_x] == PRIORITY_BIT) |
| 795 | 791 | { |
| 796 | | line_buffer[pixel_plot_x] = smsvdp->current_palette[pen_selected]; |
| 792 | line_buffer[pixel_plot_x] = smsvdp->m_current_palette[pen_selected]; |
| 797 | 793 | } |
| 798 | 794 | if (priority_selected[pixel_plot_x + 1] == PRIORITY_BIT) |
| 799 | 795 | { |
| 800 | | line_buffer[pixel_plot_x + 1] = smsvdp->current_palette[pen_selected]; |
| 796 | line_buffer[pixel_plot_x + 1] = smsvdp->m_current_palette[pen_selected]; |
| 801 | 797 | } |
| 802 | 798 | } |
| 803 | | if (smsvdp->collision_buffer[pixel_plot_x] != 1) |
| 799 | if (smsvdp->m_collision_buffer[pixel_plot_x] != 1) |
| 804 | 800 | { |
| 805 | | smsvdp->collision_buffer[pixel_plot_x] = 1; |
| 801 | smsvdp->m_collision_buffer[pixel_plot_x] = 1; |
| 806 | 802 | } |
| 807 | 803 | else |
| 808 | 804 | { |
| r13341 | r13342 | |
| 812 | 808 | sprite_col_x = pixel_plot_x; |
| 813 | 809 | } |
| 814 | 810 | } |
| 815 | | if (smsvdp->collision_buffer[pixel_plot_x + 1] != 1) |
| 811 | if (smsvdp->m_collision_buffer[pixel_plot_x + 1] != 1) |
| 816 | 812 | { |
| 817 | | smsvdp->collision_buffer[pixel_plot_x + 1] = 1; |
| 813 | smsvdp->m_collision_buffer[pixel_plot_x + 1] = 1; |
| 818 | 814 | } |
| 819 | 815 | else |
| 820 | 816 | { |
| r13341 | r13342 | |
| 837 | 833 | |
| 838 | 834 | if (!(priority_selected[pixel_plot_x] & PRIORITY_BIT)) |
| 839 | 835 | { |
| 840 | | line_buffer[pixel_plot_x] = smsvdp->current_palette[pen_selected]; |
| 836 | line_buffer[pixel_plot_x] = smsvdp->m_current_palette[pen_selected]; |
| 841 | 837 | } |
| 842 | 838 | else |
| 843 | 839 | { |
| 844 | 840 | if (priority_selected[pixel_plot_x] == PRIORITY_BIT) |
| 845 | 841 | { |
| 846 | | line_buffer[pixel_plot_x] = smsvdp->current_palette[pen_selected]; |
| 842 | line_buffer[pixel_plot_x] = smsvdp->m_current_palette[pen_selected]; |
| 847 | 843 | } |
| 848 | 844 | } |
| 849 | | if (smsvdp->collision_buffer[pixel_plot_x] != 1) |
| 845 | if (smsvdp->m_collision_buffer[pixel_plot_x] != 1) |
| 850 | 846 | { |
| 851 | | smsvdp->collision_buffer[pixel_plot_x] = 1; |
| 847 | smsvdp->m_collision_buffer[pixel_plot_x] = 1; |
| 852 | 848 | } |
| 853 | 849 | else |
| 854 | 850 | { |
| r13341 | r13342 | |
| 864 | 860 | machine.scheduler().timer_set(machine.primary_screen->time_until_pos(pixel_plot_y + line, SPRCOL_BASEHPOS + sprite_col_x), FUNC(smsvdp_set_status), (int)STATUS_SPRCOL, smsvdp); |
| 865 | 861 | } |
| 866 | 862 | |
| 867 | | /* Fill column 0 with overscan color from reg[0x07] */ |
| 868 | | if (smsvdp->reg[0x00] & 0x20) |
| 863 | /* Fill column 0 with overscan color from m_reg[0x07] */ |
| 864 | if (smsvdp->m_reg[0x00] & 0x20) |
| 869 | 865 | { |
| 870 | | line_buffer[0] = smsvdp->current_palette[BACKDROP_COLOR]; |
| 871 | | line_buffer[1] = smsvdp->current_palette[BACKDROP_COLOR]; |
| 872 | | line_buffer[2] = smsvdp->current_palette[BACKDROP_COLOR]; |
| 873 | | line_buffer[3] = smsvdp->current_palette[BACKDROP_COLOR]; |
| 874 | | line_buffer[4] = smsvdp->current_palette[BACKDROP_COLOR]; |
| 875 | | line_buffer[5] = smsvdp->current_palette[BACKDROP_COLOR]; |
| 876 | | line_buffer[6] = smsvdp->current_palette[BACKDROP_COLOR]; |
| 877 | | line_buffer[7] = smsvdp->current_palette[BACKDROP_COLOR]; |
| 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]; |
| 878 | 874 | } |
| 879 | 875 | } |
| 880 | 876 | |
| r13341 | r13342 | |
| 887 | 883 | UINT8 *sprite_table, *sprite_pattern_table; |
| 888 | 884 | |
| 889 | 885 | /* Draw sprite layer */ |
| 890 | | sprite_table = smsvdp->VRAM->base() + ((smsvdp->reg[0x05] & 0x7f) << 7); |
| 891 | | sprite_pattern_table = smsvdp->VRAM->base() + ((smsvdp->reg[0x06] & 0x07) << 11); |
| 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); |
| 892 | 888 | sprite_height = 8; |
| 893 | 889 | |
| 894 | | if (smsvdp->reg[0x01] & 0x02) /* Check if SI is set */ |
| 890 | if (smsvdp->m_reg[0x01] & 0x02) /* Check if SI is set */ |
| 895 | 891 | sprite_height = sprite_height * 2; |
| 896 | | if (smsvdp->reg[0x01] & 0x01) /* Check if MAG is set */ |
| 892 | if (smsvdp->m_reg[0x01] & 0x01) /* Check if MAG is set */ |
| 897 | 893 | sprite_height = sprite_height * 2; |
| 898 | 894 | |
| 899 | 895 | sprite_buffer_count = 0; |
| r13341 | r13342 | |
| 910 | 906 | { |
| 911 | 907 | sprite_buffer[sprite_buffer_count] = sprite_index; |
| 912 | 908 | } |
| 913 | | else if (line >= 0 && line < smsvdp->sms_frame_timing[ACTIVE_DISPLAY_V]) |
| 909 | else if (line >= 0 && line < smsvdp->m_sms_frame_timing[ACTIVE_DISPLAY_V]) |
| 914 | 910 | { |
| 915 | 911 | /* Too many sprites per line */ |
| 916 | 912 | machine.scheduler().timer_set(machine.primary_screen->time_until_pos(pixel_plot_y + line, SPROVR_HPOS), FUNC(smsvdp_set_status), (int)STATUS_SPROVR, smsvdp); |
| r13341 | r13342 | |
| 920 | 916 | } |
| 921 | 917 | |
| 922 | 918 | /* Check if display is disabled */ |
| 923 | | if (!(smsvdp->reg[0x01] & 0x40)) |
| 919 | if (!(smsvdp->m_reg[0x01] & 0x40)) |
| 924 | 920 | return; |
| 925 | 921 | |
| 926 | 922 | if (sprite_buffer_count > 4) |
| 927 | 923 | sprite_buffer_count = 4; |
| 928 | 924 | |
| 929 | | memset(smsvdp->collision_buffer, 0, SMS_X_PIXELS); |
| 925 | memset(smsvdp->m_collision_buffer, 0, SMS_X_PIXELS); |
| 930 | 926 | sprite_buffer_count--; |
| 931 | 927 | |
| 932 | 928 | for (sprite_buffer_index = sprite_buffer_count; sprite_buffer_index >= 0; sprite_buffer_index--) |
| r13341 | r13342 | |
| 954 | 950 | sprite_tile_selected = sprite_table[sprite_index + 2]; |
| 955 | 951 | sprite_line = line - sprite_y; |
| 956 | 952 | |
| 957 | | if (smsvdp->reg[0x01] & 0x01) |
| 953 | if (smsvdp->m_reg[0x01] & 0x01) |
| 958 | 954 | sprite_line >>= 1; |
| 959 | 955 | |
| 960 | | if (smsvdp->reg[0x01] & 0x02) |
| 956 | if (smsvdp->m_reg[0x01] & 0x02) |
| 961 | 957 | { |
| 962 | 958 | sprite_tile_selected &= 0xfc; |
| 963 | 959 | |
| r13341 | r13342 | |
| 975 | 971 | |
| 976 | 972 | for (pixel_x = 0; pixel_x < 8; pixel_x++) |
| 977 | 973 | { |
| 978 | | if (smsvdp->reg[0x01] & 0x01) |
| 974 | if (smsvdp->m_reg[0x01] & 0x01) |
| 979 | 975 | { |
| 980 | 976 | pixel_plot_x = sprite_x + pixel_x * 2; |
| 981 | 977 | if (pixel_plot_x < 0 || pixel_plot_x > 255) |
| r13341 | r13342 | |
| 985 | 981 | |
| 986 | 982 | if (pen_selected && (pattern & (1 << (7 - pixel_x)))) |
| 987 | 983 | { |
| 988 | | line_buffer[pixel_plot_x] = smsvdp->current_palette[pen_selected]; |
| 984 | line_buffer[pixel_plot_x] = smsvdp->m_current_palette[pen_selected]; |
| 989 | 985 | |
| 990 | | if (smsvdp->collision_buffer[pixel_plot_x] != 1) |
| 986 | if (smsvdp->m_collision_buffer[pixel_plot_x] != 1) |
| 991 | 987 | { |
| 992 | | smsvdp->collision_buffer[pixel_plot_x] = 1; |
| 988 | smsvdp->m_collision_buffer[pixel_plot_x] = 1; |
| 993 | 989 | } |
| 994 | 990 | else |
| 995 | 991 | { |
| r13341 | r13342 | |
| 1000 | 996 | } |
| 1001 | 997 | } |
| 1002 | 998 | |
| 1003 | | line_buffer[pixel_plot_x+1] = smsvdp->current_palette[pen_selected]; |
| 999 | line_buffer[pixel_plot_x+1] = smsvdp->m_current_palette[pen_selected]; |
| 1004 | 1000 | |
| 1005 | | if (smsvdp->collision_buffer[pixel_plot_x + 1] != 1) |
| 1001 | if (smsvdp->m_collision_buffer[pixel_plot_x + 1] != 1) |
| 1006 | 1002 | { |
| 1007 | | smsvdp->collision_buffer[pixel_plot_x + 1] = 1; |
| 1003 | smsvdp->m_collision_buffer[pixel_plot_x + 1] = 1; |
| 1008 | 1004 | } |
| 1009 | 1005 | else |
| 1010 | 1006 | { |
| r13341 | r13342 | |
| 1027 | 1023 | |
| 1028 | 1024 | if (pen_selected && (pattern & (1 << (7 - pixel_x)))) |
| 1029 | 1025 | { |
| 1030 | | line_buffer[pixel_plot_x] = smsvdp->current_palette[pen_selected]; |
| 1026 | line_buffer[pixel_plot_x] = smsvdp->m_current_palette[pen_selected]; |
| 1031 | 1027 | |
| 1032 | | if (smsvdp->collision_buffer[pixel_plot_x] != 1) |
| 1028 | if (smsvdp->m_collision_buffer[pixel_plot_x] != 1) |
| 1033 | 1029 | { |
| 1034 | | smsvdp->collision_buffer[pixel_plot_x] = 1; |
| 1030 | smsvdp->m_collision_buffer[pixel_plot_x] = 1; |
| 1035 | 1031 | } |
| 1036 | 1032 | else |
| 1037 | 1033 | { |
| r13341 | r13342 | |
| 1045 | 1041 | } |
| 1046 | 1042 | } |
| 1047 | 1043 | |
| 1048 | | if (smsvdp->reg[0x01] & 0x02) |
| 1044 | if (smsvdp->m_reg[0x01] & 0x02) |
| 1049 | 1045 | { |
| 1050 | 1046 | sprite_tile_selected += 2; |
| 1051 | 1047 | pattern = sprite_pattern_table[sprite_tile_selected * 8 + sprite_line]; |
| 1052 | | sprite_x += (smsvdp->reg[0x01] & 0x01 ? 16 : 8); |
| 1048 | sprite_x += (smsvdp->m_reg[0x01] & 0x01 ? 16 : 8); |
| 1053 | 1049 | |
| 1054 | 1050 | for (pixel_x = 0; pixel_x < 8; pixel_x++) |
| 1055 | 1051 | { |
| 1056 | | if (smsvdp->reg[0x01] & 0x01) |
| 1052 | if (smsvdp->m_reg[0x01] & 0x01) |
| 1057 | 1053 | { |
| 1058 | 1054 | pixel_plot_x = sprite_x + pixel_x * 2; |
| 1059 | 1055 | |
| r13341 | r13342 | |
| 1064 | 1060 | |
| 1065 | 1061 | if (pen_selected && (pattern & (1 << (7 - pixel_x)))) |
| 1066 | 1062 | { |
| 1067 | | line_buffer[pixel_plot_x] = smsvdp->current_palette[pen_selected]; |
| 1063 | line_buffer[pixel_plot_x] = smsvdp->m_current_palette[pen_selected]; |
| 1068 | 1064 | |
| 1069 | | if (smsvdp->collision_buffer[pixel_plot_x] != 1) |
| 1065 | if (smsvdp->m_collision_buffer[pixel_plot_x] != 1) |
| 1070 | 1066 | { |
| 1071 | | smsvdp->collision_buffer[pixel_plot_x] = 1; |
| 1067 | smsvdp->m_collision_buffer[pixel_plot_x] = 1; |
| 1072 | 1068 | } |
| 1073 | 1069 | else |
| 1074 | 1070 | { |
| r13341 | r13342 | |
| 1079 | 1075 | } |
| 1080 | 1076 | } |
| 1081 | 1077 | |
| 1082 | | line_buffer[pixel_plot_x+1] = smsvdp->current_palette[pen_selected]; |
| 1078 | line_buffer[pixel_plot_x+1] = smsvdp->m_current_palette[pen_selected]; |
| 1083 | 1079 | |
| 1084 | | if (smsvdp->collision_buffer[pixel_plot_x + 1] != 1) |
| 1080 | if (smsvdp->m_collision_buffer[pixel_plot_x + 1] != 1) |
| 1085 | 1081 | { |
| 1086 | | smsvdp->collision_buffer[pixel_plot_x + 1] = 1; |
| 1082 | smsvdp->m_collision_buffer[pixel_plot_x + 1] = 1; |
| 1087 | 1083 | } |
| 1088 | 1084 | else |
| 1089 | 1085 | { |
| r13341 | r13342 | |
| 1106 | 1102 | |
| 1107 | 1103 | if (pen_selected && (pattern & (1 << (7 - pixel_x)))) |
| 1108 | 1104 | { |
| 1109 | | line_buffer[pixel_plot_x] = smsvdp->current_palette[pen_selected]; |
| 1105 | line_buffer[pixel_plot_x] = smsvdp->m_current_palette[pen_selected]; |
| 1110 | 1106 | |
| 1111 | | if (smsvdp->collision_buffer[pixel_plot_x] != 1) |
| 1107 | if (smsvdp->m_collision_buffer[pixel_plot_x] != 1) |
| 1112 | 1108 | { |
| 1113 | | smsvdp->collision_buffer[pixel_plot_x] = 1; |
| 1109 | smsvdp->m_collision_buffer[pixel_plot_x] = 1; |
| 1114 | 1110 | } |
| 1115 | 1111 | else |
| 1116 | 1112 | { |
| r13341 | r13342 | |
| 1138 | 1134 | int pattern_mask, color_mask, pattern_offset; |
| 1139 | 1135 | |
| 1140 | 1136 | /* Draw background layer */ |
| 1141 | | name_table = smsvdp->VRAM->base() + ((smsvdp->reg[0x02] & 0x0f) << 10) + ((line >> 3) * 32); |
| 1142 | | color_table = smsvdp->VRAM->base() + ((smsvdp->reg[0x03] & 0x80) << 6); |
| 1143 | | color_mask = ((smsvdp->reg[0x03] & 0x7f) << 3) | 0x07; |
| 1144 | | pattern_table = smsvdp->VRAM->base() + ((smsvdp->reg[0x04] & 0x04) << 11); |
| 1145 | | pattern_mask = ((smsvdp->reg[0x04] & 0x03) << 8) | 0xff; |
| 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; |
| 1146 | 1142 | pattern_offset = (line & 0xc0) << 2; |
| 1147 | 1143 | |
| 1148 | 1144 | for (tile_column = 0; tile_column < 32; tile_column++) |
| r13341 | r13342 | |
| 1174 | 1170 | if (IS_GAMEGEAR_VDP) |
| 1175 | 1171 | pen_selected |= 0x10; |
| 1176 | 1172 | |
| 1177 | | line_buffer[pixel_plot_x] = smsvdp->current_palette[pen_selected]; |
| 1173 | line_buffer[pixel_plot_x] = smsvdp->m_current_palette[pen_selected]; |
| 1178 | 1174 | } |
| 1179 | 1175 | } |
| 1180 | 1176 | } |
| r13341 | r13342 | |
| 1187 | 1183 | UINT8 *name_table, *color_table, *pattern_table; |
| 1188 | 1184 | |
| 1189 | 1185 | /* Draw background layer */ |
| 1190 | | name_table = smsvdp->VRAM->base() + ((smsvdp->reg[0x02] & 0x0f) << 10) + ((line >> 3) * 32); |
| 1191 | | color_table = smsvdp->VRAM->base() + ((smsvdp->reg[0x03] << 6) & (VRAM_SIZE - 1)); |
| 1192 | | pattern_table = smsvdp->VRAM->base() + ((smsvdp->reg[0x04] << 11) & (VRAM_SIZE - 1)); |
| 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)); |
| 1193 | 1189 | |
| 1194 | 1190 | for (tile_column = 0; tile_column < 32; tile_column++) |
| 1195 | 1191 | { |
| r13341 | r13342 | |
| 1212 | 1208 | pen_selected |= 0x10; |
| 1213 | 1209 | |
| 1214 | 1210 | pixel_plot_x = (tile_column << 3) + pixel_x; |
| 1215 | | line_buffer[pixel_plot_x] = smsvdp->current_palette[pen_selected]; |
| 1211 | line_buffer[pixel_plot_x] = smsvdp->m_current_palette[pen_selected]; |
| 1216 | 1212 | } |
| 1217 | 1213 | } |
| 1218 | 1214 | } |
| r13341 | r13342 | |
| 1221 | 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 ) |
| 1222 | 1218 | { |
| 1223 | 1219 | int x; |
| 1224 | | int *blitline_buffer = smsvdp->line_buffer; |
| 1220 | int *blitline_buffer = smsvdp->m_line_buffer; |
| 1225 | 1221 | int priority_selected[256]; |
| 1226 | 1222 | |
| 1227 | | switch( smsvdp->vdp_mode ) |
| 1223 | switch( smsvdp->m_vdp_mode ) |
| 1228 | 1224 | { |
| 1229 | 1225 | case 0: |
| 1230 | | if (line >= 0 && line < smsvdp->sms_frame_timing[ACTIVE_DISPLAY_V]) |
| 1226 | if (line >= 0 && line < smsvdp->m_sms_frame_timing[ACTIVE_DISPLAY_V]) |
| 1231 | 1227 | sms_refresh_line_mode0(smsvdp, blitline_buffer, line); |
| 1232 | 1228 | sms_refresh_tms9918_sprites(machine, smsvdp, blitline_buffer, pixel_plot_y, line); |
| 1233 | 1229 | break; |
| 1234 | 1230 | |
| 1235 | 1231 | case 2: |
| 1236 | | if (line >= 0 && line < smsvdp->sms_frame_timing[ACTIVE_DISPLAY_V]) |
| 1232 | if (line >= 0 && line < smsvdp->m_sms_frame_timing[ACTIVE_DISPLAY_V]) |
| 1237 | 1233 | sms_refresh_line_mode2(smsvdp, blitline_buffer, line); |
| 1238 | 1234 | sms_refresh_tms9918_sprites(machine, smsvdp, blitline_buffer, pixel_plot_y, line); |
| 1239 | 1235 | break; |
| r13341 | r13342 | |
| 1241 | 1237 | case 4: |
| 1242 | 1238 | default: |
| 1243 | 1239 | memset(priority_selected, 0, sizeof(priority_selected)); |
| 1244 | | if (line >= 0 && line < smsvdp->sms_frame_timing[ACTIVE_DISPLAY_V]) |
| 1240 | if (line >= 0 && line < smsvdp->m_sms_frame_timing[ACTIVE_DISPLAY_V]) |
| 1245 | 1241 | sms_refresh_line_mode4(smsvdp, blitline_buffer, priority_selected, line); |
| 1246 | 1242 | sms_refresh_mode4_sprites(machine, smsvdp, blitline_buffer, priority_selected, pixel_plot_y, line); |
| 1247 | 1243 | break; |
| 1248 | 1244 | } |
| 1249 | 1245 | |
| 1250 | 1246 | /* Check if display is disabled or we're below/above active area */ |
| 1251 | | if (!(smsvdp->reg[0x01] & 0x40) || line < 0 || line >= smsvdp->sms_frame_timing[ACTIVE_DISPLAY_V]) |
| 1247 | if (!(smsvdp->m_reg[0x01] & 0x40) || line < 0 || line >= smsvdp->m_sms_frame_timing[ACTIVE_DISPLAY_V]) |
| 1252 | 1248 | { |
| 1253 | 1249 | for (x = 0; x < 256; x++) |
| 1254 | 1250 | { |
| 1255 | | blitline_buffer[x] = smsvdp->current_palette[BACKDROP_COLOR]; |
| 1251 | blitline_buffer[x] = smsvdp->m_current_palette[BACKDROP_COLOR]; |
| 1256 | 1252 | } |
| 1257 | 1253 | } |
| 1258 | 1254 | |
| 1259 | | if (IS_GAMEGEAR_VDP && smsvdp->gg_sms_mode) |
| 1255 | if (IS_GAMEGEAR_VDP && smsvdp->m_gg_sms_mode) |
| 1260 | 1256 | { |
| 1261 | | int *combineline_buffer = smsvdp->line_buffer + ((line & 0x03) + 1) * 256; |
| 1257 | int *combineline_buffer = smsvdp->m_line_buffer + ((line & 0x03) + 1) * 256; |
| 1262 | 1258 | int plot_x = 48; |
| 1263 | 1259 | |
| 1264 | 1260 | /* Do horizontal scaling */ |
| r13341 | r13342 | |
| 1291 | 1287 | */ |
| 1292 | 1288 | { |
| 1293 | 1289 | int gg_line; |
| 1294 | | int my_line = pixel_plot_y + line - (TBORDER_START + NTSC_224_TBORDER_Y_PIXELS); |
| 1290 | int my_line = pixel_plot_y + line - (SMS_TBORDER_START + SMS_NTSC_224_TBORDER_Y_PIXELS); |
| 1295 | 1291 | int *line1, *line2, *line3, *line4; |
| 1296 | 1292 | |
| 1297 | 1293 | /* First make sure there's enough data to draw anything */ |
| r13341 | r13342 | |
| 1310 | 1306 | } |
| 1311 | 1307 | |
| 1312 | 1308 | /* Calculate the line we will be drawing on */ |
| 1313 | | pixel_plot_y = TBORDER_START + NTSC_192_TBORDER_Y_PIXELS + 24 + gg_line; |
| 1309 | pixel_plot_y = SMS_TBORDER_START + SMS_NTSC_192_TBORDER_Y_PIXELS + 24 + gg_line; |
| 1314 | 1310 | |
| 1315 | 1311 | /* Setup our source lines */ |
| 1316 | | line1 = smsvdp->line_buffer + (((my_line - 3) & 0x03) + 1) * 256; |
| 1317 | | line2 = smsvdp->line_buffer + (((my_line - 2) & 0x03) + 1) * 256; |
| 1318 | | line3 = smsvdp->line_buffer + (((my_line - 1) & 0x03) + 1) * 256; |
| 1319 | | line4 = smsvdp->line_buffer + (((my_line - 0) & 0x03) + 1) * 256; |
| 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; |
| 1320 | 1316 | |
| 1321 | 1317 | for (x = 0 + 48; x < 160 + 48; x++) |
| 1322 | 1318 | { |
| r13341 | r13342 | |
| 1349 | 1345 | |
| 1350 | 1346 | /* TODO: Check how Light Phaser behaves for border areas. For Gangster Town, should */ |
| 1351 | 1347 | /* a shot at right border (HC~=0x90) really appear at active scr, near to left border? */ |
| 1352 | | if (x < LBORDER_START + LBORDER_X_PIXELS || x >= LBORDER_START + LBORDER_X_PIXELS + 256) |
| 1348 | if (x < SMS_LBORDER_START + SMS_LBORDER_X_PIXELS || x >= SMS_LBORDER_START + SMS_LBORDER_X_PIXELS + 256) |
| 1353 | 1349 | return 0; |
| 1354 | 1350 | |
| 1355 | 1351 | smsvdp_t *smsvdp = get_safe_token(device); |
| 1356 | | rgb_t color = *BITMAP_ADDR32(smsvdp->tmpbitmap, y, x); |
| 1352 | rgb_t color = *BITMAP_ADDR32(smsvdp->m_tmpbitmap, y, x); |
| 1357 | 1353 | |
| 1358 | 1354 | /* reference: http://www.w3.org/TR/AERT#color-contrast */ |
| 1359 | 1355 | UINT8 brightness = (RGB_RED(color) * 0.299) + (RGB_GREEN(color) * 0.587) + (RGB_BLUE(color) * 0.114); |
| r13341 | r13342 | |
| 1368 | 1364 | int i; |
| 1369 | 1365 | |
| 1370 | 1366 | /* Exit if palette is has no changes */ |
| 1371 | | if (smsvdp->cram_dirty == 0) |
| 1367 | if (smsvdp->m_cram_dirty == 0) |
| 1372 | 1368 | { |
| 1373 | 1369 | return; |
| 1374 | 1370 | } |
| 1375 | | smsvdp->cram_dirty = 0; |
| 1371 | smsvdp->m_cram_dirty = 0; |
| 1376 | 1372 | |
| 1377 | | if (smsvdp->vdp_mode != 4 && ! IS_GAMEGEAR_VDP) |
| 1373 | if (smsvdp->m_vdp_mode != 4 && ! IS_GAMEGEAR_VDP) |
| 1378 | 1374 | { |
| 1379 | 1375 | for(i = 0; i < 16; i++) |
| 1380 | 1376 | { |
| 1381 | | smsvdp->current_palette[i] = 64 + i; |
| 1377 | smsvdp->m_current_palette[i] = 64 + i; |
| 1382 | 1378 | } |
| 1383 | 1379 | return; |
| 1384 | 1380 | } |
| 1385 | 1381 | |
| 1386 | 1382 | if (IS_GAMEGEAR_VDP) |
| 1387 | 1383 | { |
| 1388 | | if (smsvdp->gg_sms_mode) |
| 1384 | if (smsvdp->m_gg_sms_mode) |
| 1389 | 1385 | { |
| 1390 | 1386 | for (i = 0; i < 32; i++) |
| 1391 | 1387 | { |
| 1392 | | smsvdp->current_palette[i] = ((smsvdp->CRAM->u8(i) & 0x30) << 6) | ((smsvdp->CRAM->u8(i) & 0x0c ) << 4) | ((smsvdp->CRAM->u8(i) & 0x03) << 2); |
| 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); |
| 1393 | 1389 | } |
| 1394 | 1390 | } |
| 1395 | 1391 | else |
| 1396 | 1392 | { |
| 1397 | 1393 | for (i = 0; i < 32; i++) |
| 1398 | 1394 | { |
| 1399 | | smsvdp->current_palette[i] = ((smsvdp->CRAM->u8(i * 2 + 1) << 8) | smsvdp->CRAM->u8(i * 2)) & 0x0fff; |
| 1395 | smsvdp->m_current_palette[i] = ((smsvdp->m_CRAM->u8(i * 2 + 1) << 8) | smsvdp->m_CRAM->u8(i * 2)) & 0x0fff; |
| 1400 | 1396 | } |
| 1401 | 1397 | } |
| 1402 | 1398 | } |
| r13341 | r13342 | |
| 1404 | 1400 | { |
| 1405 | 1401 | for (i = 0; i < 32; i++) |
| 1406 | 1402 | { |
| 1407 | | smsvdp->current_palette[i] = smsvdp->CRAM->u8(i) & 0x3f; |
| 1403 | smsvdp->m_current_palette[i] = smsvdp->m_CRAM->u8(i) & 0x3f; |
| 1408 | 1404 | } |
| 1409 | 1405 | } |
| 1410 | 1406 | } |
| r13341 | r13342 | |
| 1413 | 1409 | UINT32 sms_vdp_update( device_t *device, bitmap_t *bitmap, const rectangle *cliprect ) |
| 1414 | 1410 | { |
| 1415 | 1411 | smsvdp_t *smsvdp = get_safe_token(device); |
| 1416 | | copybitmap(bitmap, smsvdp->tmpbitmap, 0, 0, 0, 0, cliprect); |
| 1412 | copybitmap(bitmap, smsvdp->m_tmpbitmap, 0, 0, 0, 0, cliprect); |
| 1417 | 1413 | return 0; |
| 1418 | 1414 | } |
| 1419 | 1415 | |
| r13341 | r13342 | |
| 1431 | 1427 | int width = screen->width(); |
| 1432 | 1428 | int height = screen->height(); |
| 1433 | 1429 | |
| 1434 | | smsvdp->features = intf->model; |
| 1435 | | smsvdp->int_callback = intf->int_callback; |
| 1436 | | smsvdp->pause_callback = intf->pause_callback; |
| 1430 | smsvdp->m_features = intf->model; |
| 1437 | 1431 | |
| 1432 | /* Resolve callbacks */ |
| 1433 | smsvdp->m_int_callback.resolve( intf->int_callback, *device ); |
| 1434 | smsvdp->m_pause_callback.resolve( intf->pause_callback, *device ); |
| 1435 | |
| 1438 | 1436 | /* Allocate video RAM */ |
| 1439 | | smsvdp->VRAM = device->machine().region_alloc("vdp_vram", VRAM_SIZE, 1, ENDIANNESS_LITTLE); |
| 1440 | | smsvdp->CRAM = device->machine().region_alloc("vdp_cram", MAX_CRAM_SIZE, 1, ENDIANNESS_LITTLE); |
| 1441 | | smsvdp->line_buffer = auto_alloc_array(device->machine(), int, 256 * 5); |
| 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); |
| 1442 | 1440 | |
| 1443 | | smsvdp->collision_buffer = auto_alloc_array(device->machine(), UINT8, SMS_X_PIXELS); |
| 1444 | | smsvdp->sms_frame_timing = auto_alloc_array(device->machine(), UINT8, 7); |
| 1441 | smsvdp->m_collision_buffer = auto_alloc_array(device->machine(), UINT8, SMS_X_PIXELS); |
| 1442 | smsvdp->m_sms_frame_timing = auto_alloc_array(device->machine(), UINT8, 7); |
| 1445 | 1443 | |
| 1446 | 1444 | /* Make temp bitmap for rendering */ |
| 1447 | | smsvdp->tmpbitmap = auto_bitmap_alloc(device->machine(), width, height, BITMAP_FORMAT_INDEXED32); |
| 1445 | smsvdp->m_tmpbitmap = auto_bitmap_alloc(device->machine(), width, height, BITMAP_FORMAT_INDEXED32); |
| 1448 | 1446 | |
| 1449 | | smsvdp->smsvdp_display_timer = device->machine().scheduler().timer_alloc(FUNC(smsvdp_display_callback), smsvdp); |
| 1450 | | smsvdp->smsvdp_display_timer->adjust(screen->time_until_pos(0, DISPLAY_CB_HPOS), 0, screen->scan_period()); |
| 1447 | smsvdp->m_smsvdp_display_timer = device->machine().scheduler().timer_alloc(FUNC(smsvdp_display_callback), smsvdp); |
| 1448 | smsvdp->m_smsvdp_display_timer->adjust(screen->time_until_pos(0, DISPLAY_CB_HPOS), 0, screen->scan_period()); |
| 1451 | 1449 | |
| 1452 | | device->save_item(NAME(smsvdp->status)); |
| 1453 | | device->save_item(NAME(smsvdp->reg9copy)); |
| 1454 | | device->save_item(NAME(smsvdp->addrmode)); |
| 1455 | | device->save_item(NAME(smsvdp->addr)); |
| 1456 | | device->save_item(NAME(smsvdp->cram_mask)); |
| 1457 | | device->save_item(NAME(smsvdp->cram_dirty)); |
| 1458 | | device->save_item(NAME(smsvdp->pending)); |
| 1459 | | device->save_item(NAME(smsvdp->buffer)); |
| 1460 | | device->save_item(NAME(smsvdp->gg_sms_mode)); |
| 1461 | | device->save_item(NAME(smsvdp->irq_state)); |
| 1462 | | device->save_item(NAME(smsvdp->vdp_mode)); |
| 1463 | | device->save_item(NAME(smsvdp->y_pixels)); |
| 1464 | | device->save_item(NAME(smsvdp->line_counter)); |
| 1465 | | device->save_item(NAME(smsvdp->hcounter)); |
| 1466 | | device->save_item(NAME(smsvdp->reg)); |
| 1467 | | device->save_item(NAME(smsvdp->current_palette)); |
| 1468 | | device->save_pointer(NAME(smsvdp->line_buffer), 256 * 5); |
| 1469 | | device->save_pointer(NAME(smsvdp->collision_buffer), SMS_X_PIXELS); |
| 1470 | | device->save_item(NAME(*smsvdp->tmpbitmap)); |
| 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)); |
| 1471 | 1469 | } |
| 1472 | 1470 | |
| 1473 | 1471 | static DEVICE_RESET( smsvdp ) |
| r13341 | r13342 | |
| 1477 | 1475 | |
| 1478 | 1476 | /* Most register are 0x00 at power-up */ |
| 1479 | 1477 | for (i = 0; i < NUM_OF_REGISTER; i++) |
| 1480 | | smsvdp->reg[i] = 0x00; |
| 1478 | smsvdp->m_reg[i] = 0x00; |
| 1481 | 1479 | |
| 1482 | | smsvdp->reg[0x02] = 0x0e; |
| 1483 | | smsvdp->reg[0x0a] = 0xff; |
| 1480 | smsvdp->m_reg[0x02] = 0x0e; |
| 1481 | smsvdp->m_reg[0x0a] = 0xff; |
| 1484 | 1482 | |
| 1485 | | smsvdp->status = 0; |
| 1486 | | smsvdp->reg9copy = 0; |
| 1487 | | smsvdp->addrmode = 0; |
| 1488 | | smsvdp->addr = 0; |
| 1489 | | smsvdp->gg_sms_mode = 0; |
| 1490 | | smsvdp->cram_mask = (IS_GAMEGEAR_VDP && !smsvdp->gg_sms_mode) ? (GG_CRAM_SIZE - 1) : (SMS_CRAM_SIZE - 1); |
| 1491 | | smsvdp->cram_dirty = 1; |
| 1492 | | smsvdp->pending = 0; |
| 1493 | | smsvdp->buffer = 0; |
| 1494 | | smsvdp->irq_state = 0; |
| 1495 | | smsvdp->line_counter = 0; |
| 1496 | | smsvdp->hcounter = 0; |
| 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; |
| 1497 | 1495 | |
| 1498 | 1496 | for (i = 0; i < 0x20; i++) |
| 1499 | | smsvdp->current_palette[i] = 0; |
| 1497 | smsvdp->m_current_palette[i] = 0; |
| 1500 | 1498 | |
| 1501 | 1499 | set_display_settings(device); |
| 1502 | 1500 | |
| 1503 | 1501 | /* Clear RAM */ |
| 1504 | | memset(smsvdp->VRAM->base(), 0, VRAM_SIZE); |
| 1505 | | memset(smsvdp->CRAM->base(), 0, MAX_CRAM_SIZE); |
| 1506 | | memset(smsvdp->line_buffer, 0, 256 * 5 * sizeof(int)); |
| 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)); |
| 1507 | 1505 | } |
| 1508 | 1506 | |
| 1509 | 1507 | DEVICE_GET_INFO( smsvdp ) |