src/mess/machine/sms.c
| r9579 | r9580 | |
| 17 | 17 | #define CF_ONCART_RAM 0x20 |
| 18 | 18 | #define CF_GG_SMS_MODE 0x40 |
| 19 | 19 | |
| 20 | | #define MAX_CARTRIDGES 16 |
| 21 | | |
| 22 | 20 | #define LGUN_RADIUS 6 |
| 23 | 21 | #define LGUN_X_INTERVAL 4 |
| 24 | 22 | |
| 25 | | typedef struct _sms_driver_data sms_driver_data; |
| 26 | | struct _sms_driver_data { |
| 27 | | UINT8 bios_page_count; |
| 28 | | UINT8 fm_detect; |
| 29 | | UINT8 ctrl_reg; |
| 30 | | int paused; |
| 31 | | UINT8 bios_port; |
| 32 | | UINT8 *BIOS; |
| 33 | | UINT8 *mapper_ram; |
| 34 | | UINT8 mapper[4]; |
| 35 | | // we are going to use 1-6, same as bank numbers. Notice, though, that most mappers |
| 36 | | // only work on 16K banks and, hence, banks 4-6 are not always directly set |
| 37 | | // (they often use bank3 + 0x2000 and bank5 + 0x2000) |
| 38 | | UINT8 *banking_bios[7]; |
| 39 | | UINT8 *banking_cart[7]; |
| 40 | | UINT8 *banking_none[7]; |
| 41 | | UINT8 gg_sio[5]; |
| 42 | | UINT8 store_control; |
| 43 | | UINT8 input_port0; |
| 44 | | UINT8 input_port1; |
| 45 | 23 | |
| 46 | | // for gamegear LCD persistence hack |
| 47 | | bitmap_t *tmp_bitmap; |
| 48 | | bitmap_t *prev_bitmap; |
| 49 | | |
| 50 | | // for 3D glass binocular hack |
| 51 | | bitmap_t *prevleft_bitmap; |
| 52 | | bitmap_t *prevright_bitmap; |
| 53 | | |
| 54 | | /* Model identifiers */ |
| 55 | | UINT8 is_gamegear; |
| 56 | | UINT8 is_region_japan; |
| 57 | | UINT8 has_bios_0400; |
| 58 | | UINT8 has_bios_2000; |
| 59 | | UINT8 has_bios_full; |
| 60 | | UINT8 has_bios; |
| 61 | | UINT8 has_fm; |
| 62 | | |
| 63 | | /* Data needed for Rapid Fire Unit support */ |
| 64 | | emu_timer *rapid_fire_timer; |
| 65 | | UINT8 rapid_fire_state_1; |
| 66 | | UINT8 rapid_fire_state_2; |
| 67 | | |
| 68 | | /* Data needed for Paddle Control controller */ |
| 69 | | UINT32 last_paddle_read_time; |
| 70 | | UINT8 paddle_read_state; |
| 71 | | |
| 72 | | /* Data needed for Sports Pad controller */ |
| 73 | | UINT32 last_sports_pad_time_1; |
| 74 | | UINT32 last_sports_pad_time_2; |
| 75 | | UINT8 sports_pad_state_1; |
| 76 | | UINT8 sports_pad_state_2; |
| 77 | | UINT8 sports_pad_last_data_1; |
| 78 | | UINT8 sports_pad_last_data_2; |
| 79 | | UINT8 sports_pad_1_x; |
| 80 | | UINT8 sports_pad_1_y; |
| 81 | | UINT8 sports_pad_2_x; |
| 82 | | UINT8 sports_pad_2_y; |
| 83 | | |
| 84 | | /* Data needed for Light Phaser */ |
| 85 | | emu_timer *lphaser_1_timer; |
| 86 | | emu_timer *lphaser_2_timer; |
| 87 | | UINT8 lphaser_1_latch; |
| 88 | | UINT8 lphaser_2_latch; |
| 89 | | int lphaser_x_offs; /* Needed to 'calibrate' lphaser; set at cart loading */ |
| 90 | | |
| 91 | | /* Data needed for SegaScope (3D glasses) */ |
| 92 | | UINT8 sscope_state; |
| 93 | | |
| 94 | | /* Data needed for Terebi Oekaki (TV Draw) */ |
| 95 | | UINT8 tvdraw_data; |
| 96 | | |
| 97 | | /* Cartridge slot info */ |
| 98 | | UINT8 current_cartridge; |
| 99 | | struct |
| 100 | | { |
| 101 | | UINT8 *ROM; /* Pointer to ROM image data */ |
| 102 | | UINT32 size; /* Size of the ROM image */ |
| 103 | | UINT8 features; /* on-cartridge special hardware */ |
| 104 | | UINT8 *cartSRAM; /* on-cartridge SRAM */ |
| 105 | | UINT8 sram_save; /* should be the contents of the on-cartridge SRAM be saved */ |
| 106 | | UINT8 *cartRAM; /* additional on-cartridge RAM (64KB for Ernie Els Golf) */ |
| 107 | | UINT32 ram_size; /* size of the on-cartridge RAM */ |
| 108 | | UINT8 ram_page; /* currently swapped in cartridge RAM */ |
| 109 | | } cartridge[MAX_CARTRIDGES]; |
| 110 | | }; |
| 111 | | |
| 112 | | static sms_driver_data sms_state; |
| 113 | | |
| 114 | | |
| 115 | 24 | static void setup_rom(address_space *space); |
| 116 | 25 | |
| 117 | 26 | |
| 118 | 27 | static TIMER_CALLBACK( rapid_fire_callback ) |
| 119 | 28 | { |
| 120 | | sms_state.rapid_fire_state_1 ^= 0xff; |
| 121 | | sms_state.rapid_fire_state_2 ^= 0xff; |
| 29 | sms_state *state = machine->driver_data<sms_state>(); |
| 30 | state->rapid_fire_state_1 ^= 0xff; |
| 31 | state->rapid_fire_state_2 ^= 0xff; |
| 122 | 32 | } |
| 123 | 33 | |
| 124 | 34 | |
| 125 | 35 | static WRITE8_HANDLER( sms_input_write ) |
| 126 | 36 | { |
| 37 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 38 | |
| 127 | 39 | switch (offset) |
| 128 | 40 | { |
| 129 | 41 | case 0: |
| 130 | 42 | switch (input_port_read_safe(space->machine, "CTRLSEL", 0x00) & 0x0f) |
| 131 | 43 | { |
| 132 | 44 | case 0x03: /* Sports Pad */ |
| 133 | | if (data != sms_state.sports_pad_last_data_1) |
| 45 | if (data != state->sports_pad_last_data_1) |
| 134 | 46 | { |
| 135 | 47 | UINT32 cpu_cycles = downcast<cpu_device *>(space->cpu)->total_cycles(); |
| 136 | 48 | |
| 137 | | sms_state.sports_pad_last_data_1 = data; |
| 138 | | if (cpu_cycles - sms_state.last_sports_pad_time_1 > 512) |
| 49 | state->sports_pad_last_data_1 = data; |
| 50 | if (cpu_cycles - state->last_sports_pad_time_1 > 512) |
| 139 | 51 | { |
| 140 | | sms_state.sports_pad_state_1 = 3; |
| 141 | | sms_state.sports_pad_1_x = input_port_read(space->machine, "SPORT0"); |
| 142 | | sms_state.sports_pad_1_y = input_port_read(space->machine, "SPORT1"); |
| 52 | state->sports_pad_state_1 = 3; |
| 53 | state->sports_pad_1_x = input_port_read(space->machine, "SPORT0"); |
| 54 | state->sports_pad_1_y = input_port_read(space->machine, "SPORT1"); |
| 143 | 55 | } |
| 144 | | sms_state.last_sports_pad_time_1 = cpu_cycles; |
| 145 | | sms_state.sports_pad_state_1 = (sms_state.sports_pad_state_1 + 1) & 3; |
| 56 | state->last_sports_pad_time_1 = cpu_cycles; |
| 57 | state->sports_pad_state_1 = (state->sports_pad_state_1 + 1) & 3; |
| 146 | 58 | } |
| 147 | 59 | break; |
| 148 | 60 | } |
| r9579 | r9580 | |
| 152 | 64 | switch (input_port_read_safe(space->machine, "CTRLSEL", 0x00) >> 4) |
| 153 | 65 | { |
| 154 | 66 | case 0x03: /* Sports Pad */ |
| 155 | | if (data != sms_state.sports_pad_last_data_2) |
| 67 | if (data != state->sports_pad_last_data_2) |
| 156 | 68 | { |
| 157 | 69 | UINT32 cpu_cycles = downcast<cpu_device *>(space->cpu)->total_cycles(); |
| 158 | 70 | |
| 159 | | sms_state.sports_pad_last_data_2 = data; |
| 160 | | if (cpu_cycles - sms_state.last_sports_pad_time_2 > 2048) |
| 71 | state->sports_pad_last_data_2 = data; |
| 72 | if (cpu_cycles - state->last_sports_pad_time_2 > 2048) |
| 161 | 73 | { |
| 162 | | sms_state.sports_pad_state_2 = 3; |
| 163 | | sms_state.sports_pad_2_x = input_port_read(space->machine, "SPORT2"); |
| 164 | | sms_state.sports_pad_2_y = input_port_read(space->machine, "SPORT3"); |
| 74 | state->sports_pad_state_2 = 3; |
| 75 | state->sports_pad_2_x = input_port_read(space->machine, "SPORT2"); |
| 76 | state->sports_pad_2_y = input_port_read(space->machine, "SPORT3"); |
| 165 | 77 | } |
| 166 | | sms_state.last_sports_pad_time_2 = cpu_cycles; |
| 167 | | sms_state.sports_pad_state_2 = (sms_state.sports_pad_state_2 + 1) & 3; |
| 78 | state->last_sports_pad_time_2 = cpu_cycles; |
| 79 | state->sports_pad_state_2 = (state->sports_pad_state_2 + 1) & 3; |
| 168 | 80 | } |
| 169 | 81 | break; |
| 170 | 82 | } |
| r9579 | r9580 | |
| 177 | 89 | position for unknown reason (timing?) */ |
| 178 | 90 | static void sms_vdp_hcount_lphaser( running_machine *machine, int hpos ) |
| 179 | 91 | { |
| 180 | | running_device *smsvdp = machine->device("sms_vdp"); |
| 181 | | int hpos_tmp = hpos + sms_state.lphaser_x_offs; |
| 92 | sms_state *state = machine->driver_data<sms_state>(); |
| 93 | int hpos_tmp = hpos + state->lphaser_x_offs; |
| 182 | 94 | UINT8 tmp = ((hpos_tmp - 46) >> 1) & 0xff; |
| 183 | 95 | |
| 184 | 96 | //printf ("sms_vdp_hcount_lphaser: hpos %3d hpos_tmp %3d => hcount %2X\n", hpos, hpos_tmp, tmp); |
| 185 | | sms_vdp_hcount_latch_w(smsvdp, 0, tmp); |
| 97 | sms_vdp_hcount_latch_w(state->vdp, 0, tmp); |
| 186 | 98 | } |
| 187 | 99 | |
| 188 | 100 | |
| r9579 | r9580 | |
| 210 | 122 | */ |
| 211 | 123 | static int lgun_bright_aim_area( running_machine *machine, emu_timer *timer, int lgun_x, int lgun_y ) |
| 212 | 124 | { |
| 125 | sms_state *state = machine->driver_data<sms_state>(); |
| 213 | 126 | const int r_x_r = LGUN_RADIUS * LGUN_RADIUS; |
| 214 | | running_device *smsvdp = machine->device("sms_vdp"); |
| 215 | 127 | screen_device *screen = screen_first(*machine); |
| 216 | 128 | const rectangle &visarea = screen->visible_area(); |
| 217 | 129 | int beam_x = screen->hpos(); |
| r9579 | r9580 | |
| 255 | 167 | |
| 256 | 168 | if (!pos_changed) |
| 257 | 169 | { |
| 258 | | result = sms_vdp_check_brightness(smsvdp, beam_x, beam_y); |
| 170 | result = sms_vdp_check_brightness(state->vdp, beam_x, beam_y); |
| 259 | 171 | /* next check at same line */ |
| 260 | 172 | beam_x += LGUN_X_INTERVAL; |
| 261 | 173 | pos_changed = 1; |
| r9579 | r9580 | |
| 300 | 212 | |
| 301 | 213 | static void sms_vdp_hcount_latch( running_machine *machine ) |
| 302 | 214 | { |
| 215 | sms_state *state = machine->driver_data<sms_state>(); |
| 303 | 216 | UINT8 value = sms_vdp_hcount(machine); |
| 304 | | running_device *smsvdp = machine->device("sms_vdp"); |
| 305 | 217 | |
| 306 | | sms_vdp_hcount_latch_w(smsvdp, 0, value); |
| 218 | sms_vdp_hcount_latch_w(state->vdp, 0, value); |
| 307 | 219 | } |
| 308 | 220 | |
| 309 | 221 | |
| r9579 | r9580 | |
| 325 | 237 | |
| 326 | 238 | static void lphaser1_sensor_check( running_machine *machine ) |
| 327 | 239 | { |
| 240 | sms_state *state = machine->driver_data<sms_state>(); |
| 328 | 241 | const int x = screen_hpos_nonscaled(screen_first(*machine), input_port_read(machine, "LPHASER0")); |
| 329 | 242 | const int y = screen_vpos_nonscaled(screen_first(*machine), input_port_read(machine, "LPHASER1")); |
| 330 | 243 | |
| 331 | | if (lgun_bright_aim_area(machine, sms_state.lphaser_1_timer, x, y)) |
| 244 | if (lgun_bright_aim_area(machine, state->lphaser_1_timer, x, y)) |
| 332 | 245 | { |
| 333 | | if (sms_state.lphaser_1_latch == 0) |
| 246 | if (state->lphaser_1_latch == 0) |
| 334 | 247 | { |
| 335 | | sms_state.lphaser_1_latch = 1; |
| 248 | state->lphaser_1_latch = 1; |
| 336 | 249 | sms_vdp_hcount_lphaser(machine, x); |
| 337 | 250 | } |
| 338 | 251 | } |
| r9579 | r9580 | |
| 340 | 253 | |
| 341 | 254 | static void lphaser2_sensor_check( running_machine *machine ) |
| 342 | 255 | { |
| 256 | sms_state *state = machine->driver_data<sms_state>(); |
| 343 | 257 | const int x = screen_hpos_nonscaled(screen_first(*machine), input_port_read(machine, "LPHASER2")); |
| 344 | 258 | const int y = screen_vpos_nonscaled(screen_first(*machine), input_port_read(machine, "LPHASER3")); |
| 345 | 259 | |
| 346 | | if (lgun_bright_aim_area(machine, sms_state.lphaser_2_timer, x, y)) |
| 260 | if (lgun_bright_aim_area(machine, state->lphaser_2_timer, x, y)) |
| 347 | 261 | { |
| 348 | | if (sms_state.lphaser_2_latch == 0) |
| 262 | if (state->lphaser_2_latch == 0) |
| 349 | 263 | { |
| 350 | | sms_state.lphaser_2_latch = 1; |
| 264 | state->lphaser_2_latch = 1; |
| 351 | 265 | sms_vdp_hcount_lphaser(machine, x); |
| 352 | 266 | } |
| 353 | 267 | } |
| r9579 | r9580 | |
| 358 | 272 | // if so, we turn on crosshair and the lightgun timer |
| 359 | 273 | static TIMER_CALLBACK( lightgun_tick ) |
| 360 | 274 | { |
| 275 | sms_state *state = machine->driver_data<sms_state>(); |
| 276 | |
| 361 | 277 | if ((input_port_read_safe(machine, "CTRLSEL", 0x00) & 0x0f) == 0x01) |
| 362 | 278 | { |
| 363 | 279 | /* enable crosshair */ |
| 364 | 280 | crosshair_set_screen(machine, 0, CROSSHAIR_SCREEN_ALL); |
| 365 | | if (!timer_enabled(sms_state.lphaser_1_timer)) |
| 281 | if (!timer_enabled(state->lphaser_1_timer)) |
| 366 | 282 | lphaser1_sensor_check(machine); |
| 367 | 283 | } |
| 368 | 284 | else |
| 369 | 285 | { |
| 370 | 286 | /* disable crosshair */ |
| 371 | 287 | crosshair_set_screen(machine, 0, CROSSHAIR_SCREEN_NONE); |
| 372 | | timer_enable(sms_state.lphaser_1_timer, 0); |
| 288 | timer_enable(state->lphaser_1_timer, 0); |
| 373 | 289 | } |
| 374 | 290 | |
| 375 | 291 | if ((input_port_read_safe(machine, "CTRLSEL", 0x00) & 0xf0) == 0x10) |
| 376 | 292 | { |
| 377 | 293 | /* enable crosshair */ |
| 378 | 294 | crosshair_set_screen(machine, 1, CROSSHAIR_SCREEN_ALL); |
| 379 | | if (!timer_enabled(sms_state.lphaser_2_timer)) |
| 295 | if (!timer_enabled(state->lphaser_2_timer)) |
| 380 | 296 | lphaser2_sensor_check(machine); |
| 381 | 297 | } |
| 382 | 298 | else |
| 383 | 299 | { |
| 384 | 300 | /* disable crosshair */ |
| 385 | 301 | crosshair_set_screen(machine, 1, CROSSHAIR_SCREEN_NONE); |
| 386 | | timer_enable(sms_state.lphaser_2_timer, 0); |
| 302 | timer_enable(state->lphaser_2_timer, 0); |
| 387 | 303 | } |
| 388 | 304 | } |
| 389 | 305 | |
| r9579 | r9580 | |
| 402 | 318 | |
| 403 | 319 | INPUT_CHANGED( lgun1_changed ) |
| 404 | 320 | { |
| 405 | | if (!sms_state.lphaser_1_timer || |
| 321 | sms_state *state = field->port->machine->driver_data<sms_state>(); |
| 322 | if (!state->lphaser_1_timer || |
| 406 | 323 | (input_port_read_safe(field->port->machine, "CTRLSEL", 0x00) & 0x0f) != 0x01) |
| 407 | 324 | return; |
| 408 | 325 | |
| r9579 | r9580 | |
| 412 | 329 | |
| 413 | 330 | INPUT_CHANGED( lgun2_changed ) |
| 414 | 331 | { |
| 415 | | if (!sms_state.lphaser_2_timer || |
| 332 | sms_state *state = field->port->machine->driver_data<sms_state>(); |
| 333 | if (!state->lphaser_2_timer || |
| 416 | 334 | (input_port_read_safe(field->port->machine, "CTRLSEL", 0x00) & 0xf0) != 0x10) |
| 417 | 335 | return; |
| 418 | 336 | |
| r9579 | r9580 | |
| 423 | 341 | |
| 424 | 342 | static void sms_get_inputs( address_space *space ) |
| 425 | 343 | { |
| 344 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 426 | 345 | UINT8 data = 0x00; |
| 427 | 346 | UINT32 cpu_cycles = downcast<cpu_device *>(space->cpu)->total_cycles(); |
| 428 | 347 | running_machine *machine = space->machine; |
| 429 | 348 | |
| 430 | | sms_state.input_port0 = 0xff; |
| 431 | | sms_state.input_port1 = 0xff; |
| 349 | state->input_port0 = 0xff; |
| 350 | state->input_port1 = 0xff; |
| 432 | 351 | |
| 433 | | if (cpu_cycles - sms_state.last_paddle_read_time > 256) |
| 352 | if (cpu_cycles - state->last_paddle_read_time > 256) |
| 434 | 353 | { |
| 435 | | sms_state.paddle_read_state ^= 0xff; |
| 436 | | sms_state.last_paddle_read_time = cpu_cycles; |
| 354 | state->paddle_read_state ^= 0xff; |
| 355 | state->last_paddle_read_time = cpu_cycles; |
| 437 | 356 | } |
| 438 | 357 | |
| 439 | 358 | /* Check if lightgun has been chosen as input: if so, enable crosshair */ |
| r9579 | r9580 | |
| 446 | 365 | data = input_port_read(machine, "PORT_DC"); |
| 447 | 366 | /* Check Rapid Fire setting for Button A */ |
| 448 | 367 | if (!(data & 0x10) && (input_port_read(machine, "RFU") & 0x01)) |
| 449 | | data |= sms_state.rapid_fire_state_1 & 0x10; |
| 368 | data |= state->rapid_fire_state_1 & 0x10; |
| 450 | 369 | |
| 451 | 370 | /* Check Rapid Fire setting for Button B */ |
| 452 | 371 | if (!(data & 0x20) && (input_port_read(machine, "RFU") & 0x02)) |
| 453 | | data |= sms_state.rapid_fire_state_1 & 0x20; |
| 372 | data |= state->rapid_fire_state_1 & 0x20; |
| 454 | 373 | |
| 455 | | sms_state.input_port0 = (sms_state.input_port0 & 0xc0) | (data & 0x3f); |
| 374 | state->input_port0 = (state->input_port0 & 0xc0) | (data & 0x3f); |
| 456 | 375 | break; |
| 457 | 376 | |
| 458 | 377 | case 0x01: /* Light Phaser */ |
| r9579 | r9580 | |
| 460 | 379 | if (!(data & 0x10)) |
| 461 | 380 | { |
| 462 | 381 | if (input_port_read(machine, "RFU") & 0x01) |
| 463 | | data |= sms_state.rapid_fire_state_1 & 0x10; |
| 382 | data |= state->rapid_fire_state_1 & 0x10; |
| 464 | 383 | } |
| 465 | 384 | /* just consider the button (trigger) bit */ |
| 466 | 385 | data |= ~0x10; |
| 467 | | sms_state.input_port0 = (sms_state.input_port0 & 0xc0) | (data & 0x3f); |
| 386 | state->input_port0 = (state->input_port0 & 0xc0) | (data & 0x3f); |
| 468 | 387 | break; |
| 469 | 388 | |
| 470 | 389 | case 0x02: /* Paddle Control */ |
| 471 | 390 | /* Get button A state */ |
| 472 | 391 | data = input_port_read(machine, "PADDLE0"); |
| 473 | 392 | |
| 474 | | if (sms_state.paddle_read_state) |
| 393 | if (state->paddle_read_state) |
| 475 | 394 | data = data >> 4; |
| 476 | 395 | |
| 477 | | sms_state.input_port0 = (sms_state.input_port0 & 0xc0) | (data & 0x0f) | (sms_state.paddle_read_state & 0x20) |
| 396 | state->input_port0 = (state->input_port0 & 0xc0) | (data & 0x0f) | (state->paddle_read_state & 0x20) |
| 478 | 397 | | ((input_port_read(machine, "CTRLIPT") & 0x02) << 3); |
| 479 | 398 | break; |
| 480 | 399 | |
| 481 | 400 | case 0x03: /* Sega Sports Pad */ |
| 482 | | switch (sms_state.sports_pad_state_1) |
| 401 | switch (state->sports_pad_state_1) |
| 483 | 402 | { |
| 484 | 403 | case 0: |
| 485 | | data = (sms_state.sports_pad_1_x >> 4) & 0x0f; |
| 404 | data = (state->sports_pad_1_x >> 4) & 0x0f; |
| 486 | 405 | break; |
| 487 | 406 | case 1: |
| 488 | | data = sms_state.sports_pad_1_x & 0x0f; |
| 407 | data = state->sports_pad_1_x & 0x0f; |
| 489 | 408 | break; |
| 490 | 409 | case 2: |
| 491 | | data = (sms_state.sports_pad_1_y >> 4) & 0x0f; |
| 410 | data = (state->sports_pad_1_y >> 4) & 0x0f; |
| 492 | 411 | break; |
| 493 | 412 | case 3: |
| 494 | | data = sms_state.sports_pad_1_y & 0x0f; |
| 413 | data = state->sports_pad_1_y & 0x0f; |
| 495 | 414 | break; |
| 496 | 415 | } |
| 497 | | sms_state.input_port0 = (sms_state.input_port0 & 0xc0) | data | ((input_port_read(machine, "CTRLIPT") & 0x0c) << 2); |
| 416 | state->input_port0 = (state->input_port0 & 0xc0) | data | ((input_port_read(machine, "CTRLIPT") & 0x0c) << 2); |
| 498 | 417 | break; |
| 499 | 418 | } |
| 500 | 419 | |
| r9579 | r9580 | |
| 503 | 422 | { |
| 504 | 423 | case 0x00: /* Joystick */ |
| 505 | 424 | data = input_port_read(machine, "PORT_DC"); |
| 506 | | sms_state.input_port0 = (sms_state.input_port0 & 0x3f) | (data & 0xc0); |
| 425 | state->input_port0 = (state->input_port0 & 0x3f) | (data & 0xc0); |
| 507 | 426 | |
| 508 | 427 | data = input_port_read(machine, "PORT_DD"); |
| 509 | 428 | /* Check Rapid Fire setting for Button A */ |
| 510 | 429 | if (!(data & 0x04) && (input_port_read(machine, "RFU") & 0x04)) |
| 511 | | data |= sms_state.rapid_fire_state_2 & 0x04; |
| 430 | data |= state->rapid_fire_state_2 & 0x04; |
| 512 | 431 | |
| 513 | 432 | /* Check Rapid Fire setting for Button B */ |
| 514 | 433 | if (!(data & 0x08) && (input_port_read(machine, "RFU") & 0x08)) |
| 515 | | data |= sms_state.rapid_fire_state_2 & 0x08; |
| 434 | data |= state->rapid_fire_state_2 & 0x08; |
| 516 | 435 | |
| 517 | | sms_state.input_port1 = (sms_state.input_port1 & 0xf0) | (data & 0x0f); |
| 436 | state->input_port1 = (state->input_port1 & 0xf0) | (data & 0x0f); |
| 518 | 437 | break; |
| 519 | 438 | |
| 520 | 439 | case 0x10: /* Light Phaser */ |
| r9579 | r9580 | |
| 522 | 441 | if (!(data & 0x04)) |
| 523 | 442 | { |
| 524 | 443 | if (input_port_read(machine, "RFU") & 0x04) |
| 525 | | data |= sms_state.rapid_fire_state_2 & 0x04; |
| 444 | data |= state->rapid_fire_state_2 & 0x04; |
| 526 | 445 | } |
| 527 | 446 | /* just consider the button (trigger) bit */ |
| 528 | 447 | data |= ~0x04; |
| 529 | | sms_state.input_port1 = (sms_state.input_port1 & 0xf0) | (data & 0x0f); |
| 448 | state->input_port1 = (state->input_port1 & 0xf0) | (data & 0x0f); |
| 530 | 449 | break; |
| 531 | 450 | |
| 532 | 451 | case 0x20: /* Paddle Control */ |
| 533 | 452 | /* Get button A state */ |
| 534 | 453 | data = input_port_read(machine, "PADDLE1"); |
| 535 | | if (sms_state.paddle_read_state) |
| 454 | if (state->paddle_read_state) |
| 536 | 455 | data = data >> 4; |
| 537 | 456 | |
| 538 | | sms_state.input_port0 = (sms_state.input_port0 & 0x3f) | ((data & 0x03) << 6); |
| 539 | | sms_state.input_port1 = (sms_state.input_port1 & 0xf0) | ((data & 0x0c) >> 2) | (sms_state.paddle_read_state & 0x08) |
| 457 | state->input_port0 = (state->input_port0 & 0x3f) | ((data & 0x03) << 6); |
| 458 | state->input_port1 = (state->input_port1 & 0xf0) | ((data & 0x0c) >> 2) | (state->paddle_read_state & 0x08) |
| 540 | 459 | | ((input_port_read(machine, "CTRLIPT") & 0x20) >> 3); |
| 541 | 460 | break; |
| 542 | 461 | |
| 543 | 462 | case 0x30: /* Sega Sports Pad */ |
| 544 | | switch (sms_state.sports_pad_state_2) |
| 463 | switch (state->sports_pad_state_2) |
| 545 | 464 | { |
| 546 | 465 | case 0: |
| 547 | | data = sms_state.sports_pad_2_x & 0x0f; |
| 466 | data = state->sports_pad_2_x & 0x0f; |
| 548 | 467 | break; |
| 549 | 468 | case 1: |
| 550 | | data = (sms_state.sports_pad_2_x >> 4) & 0x0f; |
| 469 | data = (state->sports_pad_2_x >> 4) & 0x0f; |
| 551 | 470 | break; |
| 552 | 471 | case 2: |
| 553 | | data = sms_state.sports_pad_2_y & 0x0f; |
| 472 | data = state->sports_pad_2_y & 0x0f; |
| 554 | 473 | break; |
| 555 | 474 | case 3: |
| 556 | | data = (sms_state.sports_pad_2_y >> 4) & 0x0f; |
| 475 | data = (state->sports_pad_2_y >> 4) & 0x0f; |
| 557 | 476 | break; |
| 558 | 477 | } |
| 559 | | sms_state.input_port0 = (sms_state.input_port0 & 0x3f) | ((data & 0x03) << 6); |
| 560 | | sms_state.input_port1 = (sms_state.input_port1 & 0xf0) | (data >> 2) | ((input_port_read(machine, "CTRLIPT") & 0xc0) >> 4); |
| 478 | state->input_port0 = (state->input_port0 & 0x3f) | ((data & 0x03) << 6); |
| 479 | state->input_port1 = (state->input_port1 & 0xf0) | (data >> 2) | ((input_port_read(machine, "CTRLIPT") & 0xc0) >> 4); |
| 561 | 480 | break; |
| 562 | 481 | } |
| 563 | 482 | } |
| r9579 | r9580 | |
| 565 | 484 | |
| 566 | 485 | WRITE8_HANDLER( sms_fm_detect_w ) |
| 567 | 486 | { |
| 568 | | if (sms_state.has_fm) |
| 569 | | sms_state.fm_detect = (data & 0x01); |
| 487 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 488 | |
| 489 | if (state->has_fm) |
| 490 | state->fm_detect = (data & 0x01); |
| 570 | 491 | } |
| 571 | 492 | |
| 572 | 493 | |
| 573 | 494 | READ8_HANDLER( sms_fm_detect_r ) |
| 574 | 495 | { |
| 575 | | if (sms_state.has_fm) |
| 496 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 497 | |
| 498 | if (state->has_fm) |
| 576 | 499 | { |
| 577 | | return sms_state.fm_detect; |
| 500 | return state->fm_detect; |
| 578 | 501 | } |
| 579 | 502 | else |
| 580 | 503 | { |
| 581 | | if (sms_state.bios_port & IO_CHIP) |
| 504 | if (state->bios_port & IO_CHIP) |
| 582 | 505 | { |
| 583 | 506 | return 0xff; |
| 584 | 507 | } |
| 585 | 508 | else |
| 586 | 509 | { |
| 587 | 510 | sms_get_inputs(space); |
| 588 | | return sms_state.input_port0; |
| 511 | return state->input_port0; |
| 589 | 512 | } |
| 590 | 513 | } |
| 591 | 514 | } |
| 592 | 515 | |
| 593 | 516 | WRITE8_HANDLER( sms_io_control_w ) |
| 594 | 517 | { |
| 518 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 519 | |
| 595 | 520 | if (data & 0x08) |
| 596 | 521 | { |
| 597 | 522 | /* check if TH pin level is high (1) and was low last time */ |
| 598 | | if (data & 0x80 && !(sms_state.ctrl_reg & 0x80)) |
| 523 | if (data & 0x80 && !(state->ctrl_reg & 0x80)) |
| 599 | 524 | { |
| 600 | 525 | sms_vdp_hcount_latch(space->machine); |
| 601 | 526 | } |
| r9579 | r9580 | |
| 604 | 529 | |
| 605 | 530 | if (data & 0x02) |
| 606 | 531 | { |
| 607 | | if (data & 0x20 && !(sms_state.ctrl_reg & 0x20)) |
| 532 | if (data & 0x20 && !(state->ctrl_reg & 0x20)) |
| 608 | 533 | { |
| 609 | 534 | sms_vdp_hcount_latch(space->machine); |
| 610 | 535 | } |
| 611 | 536 | sms_input_write(space, 1, (data & 0x80) >> 7); |
| 612 | 537 | } |
| 613 | 538 | |
| 614 | | sms_state.ctrl_reg = data; |
| 539 | state->ctrl_reg = data; |
| 615 | 540 | } |
| 616 | 541 | |
| 617 | 542 | |
| 618 | 543 | READ8_HANDLER( sms_count_r ) |
| 619 | 544 | { |
| 620 | | running_device *smsvdp = space->machine->device("sms_vdp"); |
| 545 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 621 | 546 | |
| 622 | 547 | if (offset & 0x01) |
| 623 | | return sms_vdp_hcount_latch_r(smsvdp, offset); |
| 548 | return sms_vdp_hcount_latch_r(state->vdp, offset); |
| 624 | 549 | else |
| 625 | | return sms_vdp_vcount_r(smsvdp, offset); |
| 550 | return sms_vdp_vcount_r(state->vdp, offset); |
| 626 | 551 | } |
| 627 | 552 | |
| 628 | 553 | |
| r9579 | r9580 | |
| 632 | 557 | */ |
| 633 | 558 | void sms_pause_callback( running_machine *machine ) |
| 634 | 559 | { |
| 635 | | if (sms_state.is_gamegear && !(sms_state.cartridge[sms_state.current_cartridge].features & CF_GG_SMS_MODE)) |
| 560 | sms_state *state = machine->driver_data<sms_state>(); |
| 561 | |
| 562 | if (state->is_gamegear && !(state->cartridge[state->current_cartridge].features & CF_GG_SMS_MODE)) |
| 636 | 563 | return; |
| 637 | 564 | |
| 638 | | if (!(input_port_read(machine, sms_state.is_gamegear ? "START" : "PAUSE") & 0x80)) |
| 565 | if (!(input_port_read(machine, state->is_gamegear ? "START" : "PAUSE") & 0x80)) |
| 639 | 566 | { |
| 640 | | if (!sms_state.paused) |
| 567 | if (!state->paused) |
| 641 | 568 | { |
| 642 | 569 | cputag_set_input_line(machine, "maincpu", INPUT_LINE_NMI, PULSE_LINE); |
| 643 | 570 | } |
| 644 | | sms_state.paused = 1; |
| 571 | state->paused = 1; |
| 645 | 572 | } |
| 646 | 573 | else |
| 647 | 574 | { |
| 648 | | sms_state.paused = 0; |
| 575 | state->paused = 0; |
| 649 | 576 | } |
| 650 | 577 | |
| 651 | 578 | /* clear Light Phaser latch flags for next frame */ |
| 652 | | sms_state.lphaser_1_latch = 0; |
| 653 | | sms_state.lphaser_2_latch = 0; |
| 579 | state->lphaser_1_latch = 0; |
| 580 | state->lphaser_2_latch = 0; |
| 654 | 581 | } |
| 655 | 582 | |
| 656 | 583 | READ8_HANDLER( sms_input_port_0_r ) |
| 657 | 584 | { |
| 658 | | if (sms_state.bios_port & IO_CHIP) |
| 585 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 586 | |
| 587 | if (state->bios_port & IO_CHIP) |
| 659 | 588 | { |
| 660 | 589 | return 0xff; |
| 661 | 590 | } |
| 662 | 591 | else |
| 663 | 592 | { |
| 664 | 593 | sms_get_inputs(space); |
| 665 | | return sms_state.input_port0; |
| 594 | return state->input_port0; |
| 666 | 595 | } |
| 667 | 596 | } |
| 668 | 597 | |
| 669 | 598 | |
| 670 | 599 | READ8_HANDLER( sms_input_port_1_r ) |
| 671 | 600 | { |
| 672 | | if (sms_state.bios_port & IO_CHIP) |
| 601 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 602 | |
| 603 | if (state->bios_port & IO_CHIP) |
| 673 | 604 | return 0xff; |
| 674 | 605 | |
| 675 | 606 | sms_get_inputs(space); |
| 676 | 607 | |
| 677 | 608 | /* Reset Button */ |
| 678 | | sms_state.input_port1 = (sms_state.input_port1 & 0xef) | (input_port_read_safe(space->machine, "RESET", 0x01) & 0x01) << 4; |
| 609 | state->input_port1 = (state->input_port1 & 0xef) | (input_port_read_safe(space->machine, "RESET", 0x01) & 0x01) << 4; |
| 679 | 610 | |
| 680 | 611 | /* Do region detection if TH of ports A and B are set to output (0) */ |
| 681 | | if (!(sms_state.ctrl_reg & 0x0a)) |
| 612 | if (!(state->ctrl_reg & 0x0a)) |
| 682 | 613 | { |
| 683 | 614 | /* Move bits 7,5 of IO control port into bits 7, 6 */ |
| 684 | | sms_state.input_port1 = (sms_state.input_port1 & 0x3f) | (sms_state.ctrl_reg & 0x80) | (sms_state.ctrl_reg & 0x20) << 1; |
| 615 | state->input_port1 = (state->input_port1 & 0x3f) | (state->ctrl_reg & 0x80) | (state->ctrl_reg & 0x20) << 1; |
| 685 | 616 | |
| 686 | 617 | /* Inverse region detect value for Japanese machines */ |
| 687 | | if (sms_state.is_region_japan) |
| 688 | | sms_state.input_port1 ^= 0xc0; |
| 618 | if (state->is_region_japan) |
| 619 | state->input_port1 ^= 0xc0; |
| 689 | 620 | } |
| 690 | 621 | else |
| 691 | 622 | { |
| 692 | | if (sms_state.ctrl_reg & 0x02 && sms_state.lphaser_1_latch) |
| 623 | if (state->ctrl_reg & 0x02 && state->lphaser_1_latch) |
| 693 | 624 | { |
| 694 | | sms_state.input_port1 &= ~0x40; |
| 695 | | sms_state.lphaser_1_latch = 0; |
| 625 | state->input_port1 &= ~0x40; |
| 626 | state->lphaser_1_latch = 0; |
| 696 | 627 | } |
| 697 | 628 | |
| 698 | | if (sms_state.ctrl_reg & 0x08 && sms_state.lphaser_2_latch) |
| 629 | if (state->ctrl_reg & 0x08 && state->lphaser_2_latch) |
| 699 | 630 | { |
| 700 | | sms_state.input_port1 &= ~0x80; |
| 701 | | sms_state.lphaser_2_latch = 0; |
| 631 | state->input_port1 &= ~0x80; |
| 632 | state->lphaser_2_latch = 0; |
| 702 | 633 | } |
| 703 | 634 | } |
| 704 | 635 | |
| 705 | | return sms_state.input_port1; |
| 636 | return state->input_port1; |
| 706 | 637 | } |
| 707 | 638 | |
| 708 | 639 | |
| 709 | 640 | |
| 710 | 641 | WRITE8_HANDLER( sms_ym2413_register_port_0_w ) |
| 711 | 642 | { |
| 712 | | if (sms_state.has_fm) |
| 713 | | { |
| 714 | | running_device *ym = space->machine->device("ym2413"); |
| 715 | | ym2413_w(ym, 0, (data & 0x3f)); |
| 716 | | } |
| 643 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 644 | |
| 645 | if (state->has_fm) |
| 646 | ym2413_w(state->ym, 0, (data & 0x3f)); |
| 717 | 647 | } |
| 718 | 648 | |
| 719 | 649 | |
| 720 | 650 | WRITE8_HANDLER( sms_ym2413_data_port_0_w ) |
| 721 | 651 | { |
| 722 | | if (sms_state.has_fm) |
| 652 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 653 | |
| 654 | if (state->has_fm) |
| 723 | 655 | { |
| 724 | | running_device *ym = space->machine->device("ym2413"); |
| 725 | 656 | logerror("data_port_0_w %x %x\n", offset, data); |
| 726 | | ym2413_w(ym, 1, data); |
| 657 | ym2413_w(state->ym, 1, data); |
| 727 | 658 | } |
| 728 | 659 | } |
| 729 | 660 | |
| 730 | 661 | |
| 731 | 662 | READ8_HANDLER( gg_input_port_2_r ) |
| 732 | 663 | { |
| 733 | | //logerror("joy 2 read, val: %02x, pc: %04x\n", ((sms_state.is_region_japan ? 0x00 : 0x40) | (input_port_read(machine, "START") & 0x80)), activecpu_get_pc()); |
| 734 | | return ((sms_state.is_region_japan ? 0x00 : 0x40) | (input_port_read(space->machine, "START") & 0x80)); |
| 664 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 665 | |
| 666 | //logerror("joy 2 read, val: %02x, pc: %04x\n", ((state->is_region_japan ? 0x00 : 0x40) | (input_port_read(machine, "START") & 0x80)), activecpu_get_pc()); |
| 667 | return ((state->is_region_japan ? 0x00 : 0x40) | (input_port_read(space->machine, "START") & 0x80)); |
| 735 | 668 | } |
| 736 | 669 | |
| 737 | 670 | |
| 738 | 671 | READ8_HANDLER( sms_sscope_r ) |
| 739 | 672 | { |
| 740 | | return sms_state.sscope_state; |
| 673 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 674 | return state->sscope_state; |
| 741 | 675 | } |
| 742 | 676 | |
| 743 | 677 | |
| 744 | 678 | WRITE8_HANDLER( sms_sscope_w ) |
| 745 | 679 | { |
| 746 | | sms_state.sscope_state = data; |
| 680 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 681 | state->sscope_state = data; |
| 747 | 682 | } |
| 748 | 683 | |
| 749 | 684 | |
| 750 | 685 | READ8_HANDLER( sms_mapper_r ) |
| 751 | 686 | { |
| 752 | | return sms_state.mapper[offset]; |
| 687 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 688 | return state->mapper[offset]; |
| 753 | 689 | } |
| 754 | 690 | |
| 755 | 691 | /* Terebi Oekaki */ |
| 756 | 692 | /* The following code comes from sg1000.c. We should eventually merge these TV Draw implementations */ |
| 757 | 693 | static WRITE8_HANDLER( sms_tvdraw_axis_w ) |
| 758 | 694 | { |
| 695 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 759 | 696 | UINT8 tvboard_on = input_port_read_safe(space->machine, "TVDRAW", 0x00); |
| 697 | |
| 760 | 698 | if (data & 0x01) |
| 761 | 699 | { |
| 762 | | sms_state.tvdraw_data = tvboard_on ? input_port_read(space->machine, "TVDRAW_X") : 0x80; |
| 700 | state->tvdraw_data = tvboard_on ? input_port_read(space->machine, "TVDRAW_X") : 0x80; |
| 763 | 701 | |
| 764 | | if (sms_state.tvdraw_data < 4) sms_state.tvdraw_data = 4; |
| 765 | | if (sms_state.tvdraw_data > 251) sms_state.tvdraw_data = 251; |
| 702 | if (state->tvdraw_data < 4) state->tvdraw_data = 4; |
| 703 | if (state->tvdraw_data > 251) state->tvdraw_data = 251; |
| 766 | 704 | } |
| 767 | 705 | else |
| 768 | 706 | { |
| 769 | | sms_state.tvdraw_data = tvboard_on ? input_port_read(space->machine, "TVDRAW_Y") + 0x20 : 0x80; |
| 707 | state->tvdraw_data = tvboard_on ? input_port_read(space->machine, "TVDRAW_Y") + 0x20 : 0x80; |
| 770 | 708 | } |
| 771 | 709 | } |
| 772 | 710 | |
| r9579 | r9580 | |
| 778 | 716 | |
| 779 | 717 | static READ8_HANDLER( sms_tvdraw_data_r ) |
| 780 | 718 | { |
| 781 | | return sms_state.tvdraw_data; |
| 719 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 720 | return state->tvdraw_data; |
| 782 | 721 | } |
| 783 | 722 | |
| 784 | 723 | |
| 785 | 724 | WRITE8_HANDLER( sms_mapper_w ) |
| 786 | 725 | { |
| 726 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 787 | 727 | int page; |
| 788 | 728 | UINT8 *SOURCE_BIOS; |
| 789 | 729 | UINT8 *SOURCE_CART; |
| 790 | 730 | UINT8 *SOURCE; |
| 791 | | UINT8 rom_page_count = sms_state.cartridge[sms_state.current_cartridge].size / 0x4000; |
| 731 | UINT8 rom_page_count = state->cartridge[state->current_cartridge].size / 0x4000; |
| 792 | 732 | |
| 793 | 733 | offset &= 3; |
| 794 | 734 | |
| 795 | | sms_state.mapper[offset] = data; |
| 796 | | sms_state.mapper_ram[offset] = data; |
| 735 | state->mapper[offset] = data; |
| 736 | state->mapper_ram[offset] = data; |
| 797 | 737 | |
| 798 | | if (sms_state.cartridge[sms_state.current_cartridge].ROM) |
| 738 | if (state->cartridge[state->current_cartridge].ROM) |
| 799 | 739 | { |
| 800 | | SOURCE_CART = sms_state.cartridge[sms_state.current_cartridge].ROM + (( rom_page_count > 0) ? data % rom_page_count : 0) * 0x4000; |
| 740 | SOURCE_CART = state->cartridge[state->current_cartridge].ROM + (( rom_page_count > 0) ? data % rom_page_count : 0) * 0x4000; |
| 801 | 741 | } |
| 802 | 742 | else |
| 803 | 743 | { |
| 804 | | SOURCE_CART = sms_state.banking_none[1]; |
| 744 | SOURCE_CART = state->banking_none[1]; |
| 805 | 745 | } |
| 806 | 746 | |
| 807 | | if (sms_state.BIOS) |
| 747 | if (state->BIOS) |
| 808 | 748 | { |
| 809 | | SOURCE_BIOS = sms_state.BIOS + ((sms_state.bios_page_count > 0) ? data % sms_state.bios_page_count : 0) * 0x4000; |
| 749 | SOURCE_BIOS = state->BIOS + ((state->bios_page_count > 0) ? data % state->bios_page_count : 0) * 0x4000; |
| 810 | 750 | } |
| 811 | 751 | else |
| 812 | 752 | { |
| 813 | | SOURCE_BIOS = sms_state.banking_none[1]; |
| 753 | SOURCE_BIOS = state->banking_none[1]; |
| 814 | 754 | } |
| 815 | 755 | |
| 816 | | if (sms_state.bios_port & IO_BIOS_ROM || (sms_state.is_gamegear && sms_state.BIOS == NULL)) |
| 756 | if (state->bios_port & IO_BIOS_ROM || (state->is_gamegear && state->BIOS == NULL)) |
| 817 | 757 | { |
| 818 | | if (!(sms_state.bios_port & IO_CARTRIDGE) || (sms_state.is_gamegear && sms_state.BIOS == NULL)) |
| 758 | if (!(state->bios_port & IO_CARTRIDGE) || (state->is_gamegear && state->BIOS == NULL)) |
| 819 | 759 | { |
| 820 | 760 | page = (rom_page_count > 0) ? data % rom_page_count : 0; |
| 821 | | if (!sms_state.cartridge[sms_state.current_cartridge].ROM) |
| 761 | if (!state->cartridge[state->current_cartridge].ROM) |
| 822 | 762 | return; |
| 823 | 763 | SOURCE = SOURCE_CART; |
| 824 | 764 | } |
| r9579 | r9580 | |
| 830 | 770 | } |
| 831 | 771 | else |
| 832 | 772 | { |
| 833 | | page = (sms_state.bios_page_count > 0) ? data % sms_state.bios_page_count : 0; |
| 834 | | if (!sms_state.BIOS) |
| 773 | page = (state->bios_page_count > 0) ? data % state->bios_page_count : 0; |
| 774 | if (!state->BIOS) |
| 835 | 775 | return; |
| 836 | 776 | SOURCE = SOURCE_BIOS; |
| 837 | 777 | } |
| r9579 | r9580 | |
| 842 | 782 | /* Is it ram or rom? */ |
| 843 | 783 | if (data & 0x08) /* it's ram */ |
| 844 | 784 | { |
| 845 | | sms_state.cartridge[sms_state.current_cartridge].sram_save = 1; /* SRAM should be saved on exit. */ |
| 785 | state->cartridge[state->current_cartridge].sram_save = 1; /* SRAM should be saved on exit. */ |
| 846 | 786 | if (data & 0x04) |
| 847 | 787 | { |
| 848 | 788 | LOG(("ram 1 paged.\n")); |
| 849 | | SOURCE = sms_state.cartridge[sms_state.current_cartridge].cartSRAM + 0x4000; |
| 789 | SOURCE = state->cartridge[state->current_cartridge].cartSRAM + 0x4000; |
| 850 | 790 | } |
| 851 | 791 | else |
| 852 | 792 | { |
| 853 | 793 | LOG(("ram 0 paged.\n")); |
| 854 | | SOURCE = sms_state.cartridge[sms_state.current_cartridge].cartSRAM; |
| 794 | SOURCE = state->cartridge[state->current_cartridge].cartSRAM; |
| 855 | 795 | } |
| 856 | 796 | memory_set_bankptr(space->machine, "bank5", SOURCE); |
| 857 | 797 | memory_set_bankptr(space->machine, "bank6", SOURCE + 0x2000); |
| 858 | 798 | } |
| 859 | 799 | else /* it's rom */ |
| 860 | 800 | { |
| 861 | | if (sms_state.bios_port & IO_BIOS_ROM || ! sms_state.has_bios) |
| 801 | if (state->bios_port & IO_BIOS_ROM || ! state->has_bios) |
| 862 | 802 | { |
| 863 | | page = (rom_page_count > 0) ? sms_state.mapper[3] % rom_page_count : 0; |
| 864 | | SOURCE = sms_state.banking_cart[5]; |
| 803 | page = (rom_page_count > 0) ? state->mapper[3] % rom_page_count : 0; |
| 804 | SOURCE = state->banking_cart[5]; |
| 865 | 805 | } |
| 866 | 806 | else |
| 867 | 807 | { |
| 868 | | page = (sms_state.bios_page_count > 0) ? sms_state.mapper[3] % sms_state.bios_page_count : 0; |
| 869 | | SOURCE = sms_state.banking_bios[5]; |
| 808 | page = (state->bios_page_count > 0) ? state->mapper[3] % state->bios_page_count : 0; |
| 809 | SOURCE = state->banking_bios[5]; |
| 870 | 810 | } |
| 871 | 811 | LOG(("rom 2 paged in %x.\n", page)); |
| 872 | 812 | memory_set_bankptr(space->machine, "bank5", SOURCE); |
| r9579 | r9580 | |
| 876 | 816 | |
| 877 | 817 | case 1: /* Select 16k ROM bank for 0400-3FFF */ |
| 878 | 818 | LOG(("rom 0 paged in %x.\n", page)); |
| 879 | | sms_state.banking_bios[2] = SOURCE_BIOS + 0x0400; |
| 880 | | sms_state.banking_cart[2] = SOURCE_CART + 0x0400; |
| 881 | | if (sms_state.is_gamegear) |
| 819 | state->banking_bios[2] = SOURCE_BIOS + 0x0400; |
| 820 | state->banking_cart[2] = SOURCE_CART + 0x0400; |
| 821 | if (state->is_gamegear) |
| 882 | 822 | SOURCE = SOURCE_CART; |
| 883 | 823 | |
| 884 | 824 | memory_set_bankptr(space->machine, "bank2", SOURCE + 0x0400); |
| r9579 | r9580 | |
| 886 | 826 | |
| 887 | 827 | case 2: /* Select 16k ROM bank for 4000-7FFF */ |
| 888 | 828 | LOG(("rom 1 paged in %x.\n", page)); |
| 889 | | sms_state.banking_bios[3] = SOURCE_BIOS; |
| 890 | | sms_state.banking_cart[3] = SOURCE_CART; |
| 891 | | if (sms_state.is_gamegear) |
| 829 | state->banking_bios[3] = SOURCE_BIOS; |
| 830 | state->banking_cart[3] = SOURCE_CART; |
| 831 | if (state->is_gamegear) |
| 892 | 832 | SOURCE = SOURCE_CART; |
| 893 | 833 | |
| 894 | 834 | memory_set_bankptr(space->machine, "bank3", SOURCE); |
| r9579 | r9580 | |
| 896 | 836 | break; |
| 897 | 837 | |
| 898 | 838 | case 3: /* Select 16k ROM bank for 8000-BFFF */ |
| 899 | | sms_state.banking_bios[5] = SOURCE_BIOS; |
| 900 | | if (sms_state.is_gamegear) |
| 839 | state->banking_bios[5] = SOURCE_BIOS; |
| 840 | if (state->is_gamegear) |
| 901 | 841 | SOURCE = SOURCE_CART; |
| 902 | 842 | |
| 903 | | if ( sms_state.cartridge[sms_state.current_cartridge].features & CF_CODEMASTERS_MAPPER) |
| 843 | if ( state->cartridge[state->current_cartridge].features & CF_CODEMASTERS_MAPPER) |
| 904 | 844 | { |
| 905 | 845 | if (SOURCE == SOURCE_CART) |
| 906 | 846 | { |
| 907 | | SOURCE = sms_state.banking_cart[5]; |
| 847 | SOURCE = state->banking_cart[5]; |
| 908 | 848 | } |
| 909 | 849 | } |
| 910 | 850 | else |
| 911 | 851 | { |
| 912 | | sms_state.banking_cart[5] = SOURCE_CART; |
| 852 | state->banking_cart[5] = SOURCE_CART; |
| 913 | 853 | } |
| 914 | 854 | |
| 915 | | if (!(sms_state.mapper[0] & 0x08)) /* is RAM disabled? */ |
| 855 | if (!(state->mapper[0] & 0x08)) /* is RAM disabled? */ |
| 916 | 856 | { |
| 917 | 857 | LOG(("rom 2 paged in %x.\n", page)); |
| 918 | 858 | memory_set_bankptr(space->machine, "bank5", SOURCE); |
| r9579 | r9580 | |
| 925 | 865 | |
| 926 | 866 | static WRITE8_HANDLER( sms_korean_zemina_banksw_w ) |
| 927 | 867 | { |
| 928 | | if (sms_state.cartridge[sms_state.current_cartridge].features & CF_KOREAN_ZEMINA_MAPPER) |
| 868 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 869 | |
| 870 | if (state->cartridge[state->current_cartridge].features & CF_KOREAN_ZEMINA_MAPPER) |
| 929 | 871 | { |
| 930 | | UINT8 rom_page_count = sms_state.cartridge[sms_state.current_cartridge].size / 0x2000; |
| 872 | UINT8 rom_page_count = state->cartridge[state->current_cartridge].size / 0x2000; |
| 931 | 873 | int page = (rom_page_count > 0) ? data % rom_page_count : 0; |
| 932 | 874 | |
| 933 | | if (!sms_state.cartridge[sms_state.current_cartridge].ROM) |
| 875 | if (!state->cartridge[state->current_cartridge].ROM) |
| 934 | 876 | return; |
| 935 | 877 | |
| 936 | 878 | switch (offset & 3) |
| 937 | 879 | { |
| 938 | 880 | case 0: |
| 939 | | sms_state.banking_cart[5] = sms_state.cartridge[sms_state.current_cartridge].ROM + page * 0x2000; |
| 940 | | memory_set_bankptr(space->machine, "bank5", sms_state.banking_cart[5]); |
| 881 | state->banking_cart[5] = state->cartridge[state->current_cartridge].ROM + page * 0x2000; |
| 882 | memory_set_bankptr(space->machine, "bank5", state->banking_cart[5]); |
| 941 | 883 | break; |
| 942 | 884 | case 1: |
| 943 | | sms_state.banking_cart[6] = sms_state.cartridge[sms_state.current_cartridge].ROM + page * 0x2000; |
| 944 | | memory_set_bankptr(space->machine, "bank6", sms_state.banking_cart[6]); |
| 885 | state->banking_cart[6] = state->cartridge[state->current_cartridge].ROM + page * 0x2000; |
| 886 | memory_set_bankptr(space->machine, "bank6", state->banking_cart[6]); |
| 945 | 887 | break; |
| 946 | 888 | case 2: |
| 947 | | sms_state.banking_cart[3] = sms_state.cartridge[sms_state.current_cartridge].ROM + page * 0x2000; |
| 948 | | memory_set_bankptr(space->machine, "bank3", sms_state.banking_cart[3]); |
| 889 | state->banking_cart[3] = state->cartridge[state->current_cartridge].ROM + page * 0x2000; |
| 890 | memory_set_bankptr(space->machine, "bank3", state->banking_cart[3]); |
| 949 | 891 | break; |
| 950 | 892 | case 3: |
| 951 | | sms_state.banking_cart[4] = sms_state.cartridge[sms_state.current_cartridge].ROM + page * 0x2000; |
| 952 | | memory_set_bankptr(space->machine, "bank4", sms_state.banking_cart[4]); |
| 893 | state->banking_cart[4] = state->cartridge[state->current_cartridge].ROM + page * 0x2000; |
| 894 | memory_set_bankptr(space->machine, "bank4", state->banking_cart[4]); |
| 953 | 895 | break; |
| 954 | 896 | } |
| 955 | 897 | LOG(("Zemina mapper write: offset %x data %x.\n", offset, page)); |
| r9579 | r9580 | |
| 958 | 900 | |
| 959 | 901 | static WRITE8_HANDLER( sms_codemasters_page0_w ) |
| 960 | 902 | { |
| 961 | | if (sms_state.cartridge[sms_state.current_cartridge].ROM && sms_state.cartridge[sms_state.current_cartridge].features & CF_CODEMASTERS_MAPPER) |
| 903 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 904 | |
| 905 | if (state->cartridge[state->current_cartridge].ROM && state->cartridge[state->current_cartridge].features & CF_CODEMASTERS_MAPPER) |
| 962 | 906 | { |
| 963 | | UINT8 rom_page_count = sms_state.cartridge[sms_state.current_cartridge].size / 0x4000; |
| 964 | | sms_state.banking_cart[1] = sms_state.cartridge[sms_state.current_cartridge].ROM + ((rom_page_count > 0) ? data % rom_page_count : 0) * 0x4000; |
| 965 | | sms_state.banking_cart[2] = sms_state.banking_cart[1] + 0x0400; |
| 966 | | memory_set_bankptr(space->machine, "bank1", sms_state.banking_cart[1]); |
| 967 | | memory_set_bankptr(space->machine, "bank2", sms_state.banking_cart[2]); |
| 907 | UINT8 rom_page_count = state->cartridge[state->current_cartridge].size / 0x4000; |
| 908 | state->banking_cart[1] = state->cartridge[state->current_cartridge].ROM + ((rom_page_count > 0) ? data % rom_page_count : 0) * 0x4000; |
| 909 | state->banking_cart[2] = state->banking_cart[1] + 0x0400; |
| 910 | memory_set_bankptr(space->machine, "bank1", state->banking_cart[1]); |
| 911 | memory_set_bankptr(space->machine, "bank2", state->banking_cart[2]); |
| 968 | 912 | } |
| 969 | 913 | } |
| 970 | 914 | |
| 971 | 915 | |
| 972 | 916 | static WRITE8_HANDLER( sms_codemasters_page1_w ) |
| 973 | 917 | { |
| 974 | | if (sms_state.cartridge[sms_state.current_cartridge].ROM && sms_state.cartridge[sms_state.current_cartridge].features & CF_CODEMASTERS_MAPPER) |
| 918 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 919 | |
| 920 | if (state->cartridge[state->current_cartridge].ROM && state->cartridge[state->current_cartridge].features & CF_CODEMASTERS_MAPPER) |
| 975 | 921 | { |
| 976 | 922 | /* Check if we need to switch in some RAM */ |
| 977 | 923 | if (data & 0x80) |
| 978 | 924 | { |
| 979 | | sms_state.cartridge[sms_state.current_cartridge].ram_page = data & 0x07; |
| 980 | | memory_set_bankptr(space->machine, "bank6", sms_state.cartridge[sms_state.current_cartridge].cartRAM + sms_state.cartridge[sms_state.current_cartridge].ram_page * 0x2000); |
| 925 | state->cartridge[state->current_cartridge].ram_page = data & 0x07; |
| 926 | memory_set_bankptr(space->machine, "bank6", state->cartridge[state->current_cartridge].cartRAM + state->cartridge[state->current_cartridge].ram_page * 0x2000); |
| 981 | 927 | } |
| 982 | 928 | else |
| 983 | 929 | { |
| 984 | | UINT8 rom_page_count = sms_state.cartridge[sms_state.current_cartridge].size / 0x4000; |
| 985 | | sms_state.banking_cart[3] = sms_state.cartridge[sms_state.current_cartridge].ROM + ((rom_page_count > 0) ? data % rom_page_count : 0) * 0x4000; |
| 986 | | memory_set_bankptr(space->machine, "bank3", sms_state.banking_cart[3]); |
| 987 | | memory_set_bankptr(space->machine, "bank4", sms_state.banking_cart[3] + 0x2000); |
| 988 | | memory_set_bankptr(space->machine, "bank6", sms_state.banking_cart[5] + 0x2000); |
| 930 | UINT8 rom_page_count = state->cartridge[state->current_cartridge].size / 0x4000; |
| 931 | state->banking_cart[3] = state->cartridge[state->current_cartridge].ROM + ((rom_page_count > 0) ? data % rom_page_count : 0) * 0x4000; |
| 932 | memory_set_bankptr(space->machine, "bank3", state->banking_cart[3]); |
| 933 | memory_set_bankptr(space->machine, "bank4", state->banking_cart[3] + 0x2000); |
| 934 | memory_set_bankptr(space->machine, "bank6", state->banking_cart[5] + 0x2000); |
| 989 | 935 | } |
| 990 | 936 | } |
| 991 | 937 | } |
| r9579 | r9580 | |
| 998 | 944 | |
| 999 | 945 | static WRITE8_HANDLER( sms_kor_nobank_w ) |
| 1000 | 946 | { |
| 947 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 1001 | 948 | UINT8 *SOURCE_BIOS; |
| 1002 | 949 | UINT8 *SOURCE = NULL; |
| 1003 | 950 | |
| 1004 | 951 | space->write_byte(0xdffc + offset, data); |
| 1005 | | sms_state.mapper[offset] = data; |
| 952 | state->mapper[offset] = data; |
| 1006 | 953 | |
| 1007 | 954 | // FIXME: the code below (which only handles the BIOS bankswitch at start) should be cleaned up |
| 1008 | 955 | // currently, it's just a stripped down version of sms_mapper_w |
| 1009 | | if (sms_state.BIOS) |
| 1010 | | SOURCE_BIOS = sms_state.BIOS + ((sms_state.bios_page_count > 0) ? data % sms_state.bios_page_count : 0) * 0x4000; |
| 956 | if (state->BIOS) |
| 957 | SOURCE_BIOS = state->BIOS + ((state->bios_page_count > 0) ? data % state->bios_page_count : 0) * 0x4000; |
| 1011 | 958 | else |
| 1012 | | SOURCE_BIOS = sms_state.banking_none[1]; |
| 959 | SOURCE_BIOS = state->banking_none[1]; |
| 1013 | 960 | |
| 1014 | | if (sms_state.bios_port & IO_BIOS_ROM || (sms_state.is_gamegear && sms_state.BIOS == NULL)) |
| 961 | if (state->bios_port & IO_BIOS_ROM || (state->is_gamegear && state->BIOS == NULL)) |
| 1015 | 962 | return; |
| 1016 | 963 | else |
| 1017 | 964 | { |
| 1018 | | if (!sms_state.BIOS) |
| 965 | if (!state->BIOS) |
| 1019 | 966 | return; |
| 1020 | 967 | SOURCE = SOURCE_BIOS; |
| 1021 | 968 | } |
| r9579 | r9580 | |
| 1027 | 974 | case 0: /* Control */ |
| 1028 | 975 | if (!(data & 0x08)) /* it's not ram */ |
| 1029 | 976 | { |
| 1030 | | if (!(sms_state.bios_port & IO_BIOS_ROM) && sms_state.has_bios) |
| 977 | if (!(state->bios_port & IO_BIOS_ROM) && state->has_bios) |
| 1031 | 978 | { |
| 1032 | | SOURCE = sms_state.banking_bios[5]; |
| 979 | SOURCE = state->banking_bios[5]; |
| 1033 | 980 | memory_set_bankptr(space->machine, "bank5", SOURCE); |
| 1034 | 981 | memory_set_bankptr(space->machine, "bank6", SOURCE + 0x2000); |
| 1035 | 982 | } |
| r9579 | r9580 | |
| 1037 | 984 | break; |
| 1038 | 985 | |
| 1039 | 986 | case 1: /* Select 16k ROM bank for 0400-3FFF */ |
| 1040 | | sms_state.banking_bios[2] = SOURCE_BIOS + 0x0400; |
| 987 | state->banking_bios[2] = SOURCE_BIOS + 0x0400; |
| 1041 | 988 | memory_set_bankptr(space->machine, "bank2", SOURCE + 0x0400); |
| 1042 | 989 | break; |
| 1043 | 990 | |
| 1044 | 991 | case 2: /* Select 16k ROM bank for 4000-7FFF */ |
| 1045 | | sms_state.banking_bios[3] = SOURCE_BIOS; |
| 992 | state->banking_bios[3] = SOURCE_BIOS; |
| 1046 | 993 | memory_set_bankptr(space->machine, "bank3", SOURCE); |
| 1047 | 994 | memory_set_bankptr(space->machine, "bank4", SOURCE + 0x2000); |
| 1048 | 995 | break; |
| 1049 | 996 | |
| 1050 | 997 | case 3: /* Select 16k ROM bank for 8000-BFFF */ |
| 1051 | | sms_state.banking_bios[5] = SOURCE_BIOS; |
| 1052 | | if (!(sms_state.mapper[0] & 0x08)) /* is RAM disabled? */ |
| 998 | state->banking_bios[5] = SOURCE_BIOS; |
| 999 | if (!(state->mapper[0] & 0x08)) /* is RAM disabled? */ |
| 1053 | 1000 | { |
| 1054 | 1001 | memory_set_bankptr(space->machine, "bank5", SOURCE); |
| 1055 | 1002 | memory_set_bankptr(space->machine, "bank6", SOURCE + 0x2000); |
| r9579 | r9580 | |
| 1060 | 1007 | |
| 1061 | 1008 | WRITE8_HANDLER( sms_bios_w ) |
| 1062 | 1009 | { |
| 1063 | | sms_state.bios_port = data; |
| 1010 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 1011 | state->bios_port = data; |
| 1064 | 1012 | |
| 1065 | 1013 | logerror("bios write %02x, pc: %04x\n", data, cpu_get_pc(space->cpu)); |
| 1066 | 1014 | |
| r9579 | r9580 | |
| 1070 | 1018 | |
| 1071 | 1019 | WRITE8_HANDLER( sms_cartram2_w ) |
| 1072 | 1020 | { |
| 1073 | | if (sms_state.mapper[0] & 0x08) |
| 1021 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 1022 | |
| 1023 | if (state->mapper[0] & 0x08) |
| 1074 | 1024 | { |
| 1075 | 1025 | logerror("write %02X to cartram at offset #%04X\n", data, offset + 0x2000); |
| 1076 | | if (sms_state.mapper[0] & 0x04) |
| 1026 | if (state->mapper[0] & 0x04) |
| 1077 | 1027 | { |
| 1078 | | sms_state.cartridge[sms_state.current_cartridge].cartSRAM[offset + 0x6000] = data; |
| 1028 | state->cartridge[state->current_cartridge].cartSRAM[offset + 0x6000] = data; |
| 1079 | 1029 | } |
| 1080 | 1030 | else |
| 1081 | 1031 | { |
| 1082 | | sms_state.cartridge[sms_state.current_cartridge].cartSRAM[offset + 0x2000] = data; |
| 1032 | state->cartridge[state->current_cartridge].cartSRAM[offset + 0x2000] = data; |
| 1083 | 1033 | } |
| 1084 | 1034 | } |
| 1085 | 1035 | |
| 1086 | | if (sms_state.cartridge[sms_state.current_cartridge].features & CF_CODEMASTERS_MAPPER) |
| 1036 | if (state->cartridge[state->current_cartridge].features & CF_CODEMASTERS_MAPPER) |
| 1087 | 1037 | { |
| 1088 | | sms_state.cartridge[sms_state.current_cartridge].cartRAM[sms_state.cartridge[sms_state.current_cartridge].ram_page * 0x2000 + offset] = data; |
| 1038 | state->cartridge[state->current_cartridge].cartRAM[state->cartridge[state->current_cartridge].ram_page * 0x2000 + offset] = data; |
| 1089 | 1039 | } |
| 1090 | 1040 | |
| 1091 | | if (sms_state.cartridge[sms_state.current_cartridge].features & CF_KOREAN_MAPPER && offset == 0) /* Dodgeball King mapper */ |
| 1041 | if (state->cartridge[state->current_cartridge].features & CF_KOREAN_MAPPER && offset == 0) /* Dodgeball King mapper */ |
| 1092 | 1042 | { |
| 1093 | | UINT8 rom_page_count = sms_state.cartridge[sms_state.current_cartridge].size / 0x4000; |
| 1043 | UINT8 rom_page_count = state->cartridge[state->current_cartridge].size / 0x4000; |
| 1094 | 1044 | int page = (rom_page_count > 0) ? data % rom_page_count : 0; |
| 1095 | 1045 | |
| 1096 | | if (!sms_state.cartridge[sms_state.current_cartridge].ROM) |
| 1046 | if (!state->cartridge[state->current_cartridge].ROM) |
| 1097 | 1047 | return; |
| 1098 | 1048 | |
| 1099 | | sms_state.banking_cart[5] = sms_state.cartridge[sms_state.current_cartridge].ROM + page * 0x4000; |
| 1100 | | memory_set_bankptr(space->machine, "bank5", sms_state.banking_cart[5]); |
| 1101 | | memory_set_bankptr(space->machine, "bank6", sms_state.banking_cart[5] + 0x2000); |
| 1049 | state->banking_cart[5] = state->cartridge[state->current_cartridge].ROM + page * 0x4000; |
| 1050 | memory_set_bankptr(space->machine, "bank5", state->banking_cart[5]); |
| 1051 | memory_set_bankptr(space->machine, "bank6", state->banking_cart[5] + 0x2000); |
| 1102 | 1052 | LOG(("rom 2 paged in %x (Korean mapper).\n", page)); |
| 1103 | 1053 | } |
| 1104 | 1054 | } |
| r9579 | r9580 | |
| 1106 | 1056 | |
| 1107 | 1057 | WRITE8_HANDLER( sms_cartram_w ) |
| 1108 | 1058 | { |
| 1059 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 1109 | 1060 | int page; |
| 1110 | 1061 | |
| 1111 | | if (sms_state.mapper[0] & 0x08) |
| 1062 | if (state->mapper[0] & 0x08) |
| 1112 | 1063 | { |
| 1113 | 1064 | logerror("write %02X to cartram at offset #%04X\n", data, offset); |
| 1114 | | if (sms_state.mapper[0] & 0x04) |
| 1065 | if (state->mapper[0] & 0x04) |
| 1115 | 1066 | { |
| 1116 | | sms_state.cartridge[sms_state.current_cartridge].cartSRAM[offset + 0x4000] = data; |
| 1067 | state->cartridge[state->current_cartridge].cartSRAM[offset + 0x4000] = data; |
| 1117 | 1068 | } |
| 1118 | 1069 | else |
| 1119 | 1070 | { |
| 1120 | | sms_state.cartridge[sms_state.current_cartridge].cartSRAM[offset] = data; |
| 1071 | state->cartridge[state->current_cartridge].cartSRAM[offset] = data; |
| 1121 | 1072 | } |
| 1122 | 1073 | } |
| 1123 | 1074 | else |
| 1124 | 1075 | { |
| 1125 | | if (sms_state.cartridge[sms_state.current_cartridge].features & CF_CODEMASTERS_MAPPER && offset == 0) /* Codemasters mapper */ |
| 1076 | if (state->cartridge[state->current_cartridge].features & CF_CODEMASTERS_MAPPER && offset == 0) /* Codemasters mapper */ |
| 1126 | 1077 | { |
| 1127 | | UINT8 rom_page_count = sms_state.cartridge[sms_state.current_cartridge].size / 0x4000; |
| 1078 | UINT8 rom_page_count = state->cartridge[state->current_cartridge].size / 0x4000; |
| 1128 | 1079 | page = (rom_page_count > 0) ? data % rom_page_count : 0; |
| 1129 | | if (!sms_state.cartridge[sms_state.current_cartridge].ROM) |
| 1080 | if (!state->cartridge[state->current_cartridge].ROM) |
| 1130 | 1081 | return; |
| 1131 | | sms_state.banking_cart[5] = sms_state.cartridge[sms_state.current_cartridge].ROM + page * 0x4000; |
| 1132 | | memory_set_bankptr(space->machine, "bank5", sms_state.banking_cart[5]); |
| 1133 | | memory_set_bankptr(space->machine, "bank6", sms_state.banking_cart[5] + 0x2000); |
| 1082 | state->banking_cart[5] = state->cartridge[state->current_cartridge].ROM + page * 0x4000; |
| 1083 | memory_set_bankptr(space->machine, "bank5", state->banking_cart[5]); |
| 1084 | memory_set_bankptr(space->machine, "bank6", state->banking_cart[5] + 0x2000); |
| 1134 | 1085 | LOG(("rom 2 paged in %x (Codemasters mapper).\n", page)); |
| 1135 | 1086 | } |
| 1136 | | else if (sms_state.cartridge[sms_state.current_cartridge].features & CF_ONCART_RAM) |
| 1087 | else if (state->cartridge[state->current_cartridge].features & CF_ONCART_RAM) |
| 1137 | 1088 | { |
| 1138 | | sms_state.cartridge[sms_state.current_cartridge].cartRAM[offset & (sms_state.cartridge[sms_state.current_cartridge].ram_size - 1)] = data; |
| 1089 | state->cartridge[state->current_cartridge].cartRAM[offset & (state->cartridge[state->current_cartridge].ram_size - 1)] = data; |
| 1139 | 1090 | } |
| 1140 | 1091 | else |
| 1141 | 1092 | { |
| r9579 | r9580 | |
| 1147 | 1098 | |
| 1148 | 1099 | WRITE8_HANDLER( gg_sio_w ) |
| 1149 | 1100 | { |
| 1101 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 1150 | 1102 | logerror("*** write %02X to SIO register #%d\n", data, offset); |
| 1151 | 1103 | |
| 1152 | | sms_state.gg_sio[offset & 0x07] = data; |
| 1104 | state->gg_sio[offset & 0x07] = data; |
| 1153 | 1105 | switch (offset & 7) |
| 1154 | 1106 | { |
| 1155 | 1107 | case 0x00: /* Parallel Data */ |
| r9579 | r9580 | |
| 1172 | 1124 | |
| 1173 | 1125 | READ8_HANDLER( gg_sio_r ) |
| 1174 | 1126 | { |
| 1127 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 1175 | 1128 | logerror("*** read SIO register #%d\n", offset); |
| 1176 | 1129 | |
| 1177 | 1130 | switch (offset & 7) |
| r9579 | r9580 | |
| 1192 | 1145 | break; |
| 1193 | 1146 | } |
| 1194 | 1147 | |
| 1195 | | return sms_state.gg_sio[offset]; |
| 1148 | return state->gg_sio[offset]; |
| 1196 | 1149 | } |
| 1197 | 1150 | |
| 1198 | 1151 | static void sms_machine_stop( running_machine &machine ) |
| 1199 | 1152 | { |
| 1153 | sms_state *state = machine.driver_data<sms_state>(); |
| 1154 | |
| 1200 | 1155 | /* Does the cartridge have SRAM that should be saved? */ |
| 1201 | | if (sms_state.cartridge[sms_state.current_cartridge].sram_save) { |
| 1156 | if (state->cartridge[state->current_cartridge].sram_save) { |
| 1202 | 1157 | device_image_interface *image = dynamic_cast<device_image_interface *>(machine.device("cart1")); |
| 1203 | | image->battery_save(sms_state.cartridge[sms_state.current_cartridge].cartSRAM, sizeof(UINT8) * NVRAM_SIZE ); |
| 1158 | image->battery_save(state->cartridge[state->current_cartridge].cartSRAM, sizeof(UINT8) * NVRAM_SIZE ); |
| 1204 | 1159 | } |
| 1205 | 1160 | } |
| 1206 | 1161 | |
| 1207 | 1162 | |
| 1208 | 1163 | static void setup_rom( address_space *space ) |
| 1209 | 1164 | { |
| 1165 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 1210 | 1166 | running_machine *machine = space->machine; |
| 1211 | 1167 | |
| 1212 | 1168 | /* 1. set up bank pointers to point to nothing */ |
| 1213 | | memory_set_bankptr(machine, "bank1", sms_state.banking_none[1]); |
| 1214 | | memory_set_bankptr(machine, "bank2", sms_state.banking_none[2]); |
| 1215 | | memory_set_bankptr(machine, "bank3", sms_state.banking_none[3]); |
| 1216 | | memory_set_bankptr(machine, "bank4", sms_state.banking_none[3] + 0x2000); |
| 1217 | | memory_set_bankptr(machine, "bank5", sms_state.banking_none[5]); |
| 1218 | | memory_set_bankptr(machine, "bank6", sms_state.banking_none[5] + 0x2000); |
| 1169 | memory_set_bankptr(machine, "bank1", state->banking_none[1]); |
| 1170 | memory_set_bankptr(machine, "bank2", state->banking_none[2]); |
| 1171 | memory_set_bankptr(machine, "bank3", state->banking_none[3]); |
| 1172 | memory_set_bankptr(machine, "bank4", state->banking_none[3] + 0x2000); |
| 1173 | memory_set_bankptr(machine, "bank5", state->banking_none[5]); |
| 1174 | memory_set_bankptr(machine, "bank6", state->banking_none[5] + 0x2000); |
| 1219 | 1175 | |
| 1220 | 1176 | /* 2. check and set up expansion port */ |
| 1221 | | if (!(sms_state.bios_port & IO_EXPANSION) && (sms_state.bios_port & IO_CARTRIDGE) && (sms_state.bios_port & IO_CARD)) |
| 1177 | if (!(state->bios_port & IO_EXPANSION) && (state->bios_port & IO_CARTRIDGE) && (state->bios_port & IO_CARD)) |
| 1222 | 1178 | { |
| 1223 | 1179 | /* TODO: Implement me */ |
| 1224 | 1180 | logerror("Switching to unsupported expansion port.\n"); |
| 1225 | 1181 | } |
| 1226 | 1182 | |
| 1227 | 1183 | /* 3. check and set up card rom */ |
| 1228 | | if (!(sms_state.bios_port & IO_CARD) && (sms_state.bios_port & IO_CARTRIDGE) && (sms_state.bios_port & IO_EXPANSION)) |
| 1184 | if (!(state->bios_port & IO_CARD) && (state->bios_port & IO_CARTRIDGE) && (state->bios_port & IO_EXPANSION)) |
| 1229 | 1185 | { |
| 1230 | 1186 | /* TODO: Implement me */ |
| 1231 | 1187 | logerror("Switching to unsupported card rom port.\n"); |
| 1232 | 1188 | } |
| 1233 | 1189 | |
| 1234 | 1190 | /* 4. check and set up cartridge rom */ |
| 1235 | | /* if ((!(bios_port & IO_CARTRIDGE) && (bios_port & IO_EXPANSION) && (bios_port & IO_CARD)) || sms_state.is_gamegear) { */ |
| 1191 | /* if ((!(bios_port & IO_CARTRIDGE) && (bios_port & IO_EXPANSION) && (bios_port & IO_CARD)) || state->is_gamegear) { */ |
| 1236 | 1192 | /* Out Run Europa initially writes a value to port 3E where IO_CARTRIDGE, IO_EXPANSION and IO_CARD are reset */ |
| 1237 | | if ((!(sms_state.bios_port & IO_CARTRIDGE)) || sms_state.is_gamegear) |
| 1193 | if ((!(state->bios_port & IO_CARTRIDGE)) || state->is_gamegear) |
| 1238 | 1194 | { |
| 1239 | | memory_set_bankptr(machine, "bank1", sms_state.banking_cart[1]); |
| 1240 | | memory_set_bankptr(machine, "bank2", sms_state.banking_cart[2]); |
| 1241 | | memory_set_bankptr(machine, "bank3", sms_state.banking_cart[3]); |
| 1242 | | memory_set_bankptr(machine, "bank4", sms_state.banking_cart[3] + 0x2000); |
| 1243 | | memory_set_bankptr(machine, "bank5", sms_state.banking_cart[5]); |
| 1244 | | memory_set_bankptr(machine, "bank6", sms_state.banking_cart[5] + 0x2000); |
| 1195 | memory_set_bankptr(machine, "bank1", state->banking_cart[1]); |
| 1196 | memory_set_bankptr(machine, "bank2", state->banking_cart[2]); |
| 1197 | memory_set_bankptr(machine, "bank3", state->banking_cart[3]); |
| 1198 | memory_set_bankptr(machine, "bank4", state->banking_cart[3] + 0x2000); |
| 1199 | memory_set_bankptr(machine, "bank5", state->banking_cart[5]); |
| 1200 | memory_set_bankptr(machine, "bank6", state->banking_cart[5] + 0x2000); |
| 1245 | 1201 | logerror("Switched in cartridge rom.\n"); |
| 1246 | 1202 | } |
| 1247 | 1203 | |
| 1248 | 1204 | /* 5. check and set up bios rom */ |
| 1249 | | if (!(sms_state.bios_port & IO_BIOS_ROM)) |
| 1205 | if (!(state->bios_port & IO_BIOS_ROM)) |
| 1250 | 1206 | { |
| 1251 | 1207 | /* 0x0400 bioses */ |
| 1252 | | if (sms_state.has_bios_0400) |
| 1208 | if (state->has_bios_0400) |
| 1253 | 1209 | { |
| 1254 | | memory_set_bankptr(machine, "bank1", sms_state.banking_bios[1]); |
| 1210 | memory_set_bankptr(machine, "bank1", state->banking_bios[1]); |
| 1255 | 1211 | logerror("Switched in 0x0400 bios.\n"); |
| 1256 | 1212 | } |
| 1257 | 1213 | /* 0x2000 bioses */ |
| 1258 | | if (sms_state.has_bios_2000) |
| 1214 | if (state->has_bios_2000) |
| 1259 | 1215 | { |
| 1260 | | memory_set_bankptr(machine, "bank1", sms_state.banking_bios[1]); |
| 1261 | | memory_set_bankptr(machine, "bank2", sms_state.banking_bios[2]); |
| 1216 | memory_set_bankptr(machine, "bank1", state->banking_bios[1]); |
| 1217 | memory_set_bankptr(machine, "bank2", state->banking_bios[2]); |
| 1262 | 1218 | logerror("Switched in 0x2000 bios.\n"); |
| 1263 | 1219 | } |
| 1264 | | if (sms_state.has_bios_full) |
| 1220 | if (state->has_bios_full) |
| 1265 | 1221 | { |
| 1266 | | memory_set_bankptr(machine, "bank1", sms_state.banking_bios[1]); |
| 1267 | | memory_set_bankptr(machine, "bank2", sms_state.banking_bios[2]); |
| 1268 | | memory_set_bankptr(machine, "bank3", sms_state.banking_bios[3]); |
| 1269 | | memory_set_bankptr(machine, "bank4", sms_state.banking_bios[3] + 0x2000); |
| 1270 | | memory_set_bankptr(machine, "bank5", sms_state.banking_bios[5]); |
| 1271 | | memory_set_bankptr(machine, "bank6", sms_state.banking_bios[5] + 0x2000); |
| 1222 | memory_set_bankptr(machine, "bank1", state->banking_bios[1]); |
| 1223 | memory_set_bankptr(machine, "bank2", state->banking_bios[2]); |
| 1224 | memory_set_bankptr(machine, "bank3", state->banking_bios[3]); |
| 1225 | memory_set_bankptr(machine, "bank4", state->banking_bios[3] + 0x2000); |
| 1226 | memory_set_bankptr(machine, "bank5", state->banking_bios[5]); |
| 1227 | memory_set_bankptr(machine, "bank6", state->banking_bios[5] + 0x2000); |
| 1272 | 1228 | logerror("Switched in full bios.\n"); |
| 1273 | 1229 | } |
| 1274 | 1230 | } |
| 1275 | 1231 | |
| 1276 | | if (sms_state.cartridge[sms_state.current_cartridge].features & CF_ONCART_RAM) |
| 1232 | if (state->cartridge[state->current_cartridge].features & CF_ONCART_RAM) |
| 1277 | 1233 | { |
| 1278 | | memory_set_bankptr(machine, "bank5", sms_state.cartridge[sms_state.current_cartridge].cartRAM); |
| 1279 | | memory_set_bankptr(machine, "bank6", sms_state.cartridge[sms_state.current_cartridge].cartRAM); |
| 1234 | memory_set_bankptr(machine, "bank5", state->cartridge[state->current_cartridge].cartRAM); |
| 1235 | memory_set_bankptr(machine, "bank6", state->cartridge[state->current_cartridge].cartRAM); |
| 1280 | 1236 | } |
| 1281 | 1237 | } |
| 1282 | 1238 | |
| r9579 | r9580 | |
| 1406 | 1362 | } |
| 1407 | 1363 | |
| 1408 | 1364 | |
| 1409 | | static int detect_lphaser_xoffset( UINT8 *rom ) |
| 1365 | static int detect_lphaser_xoffset( running_machine *machine, UINT8 *rom ) |
| 1410 | 1366 | { |
| 1367 | sms_state *state = machine->driver_data<sms_state>(); |
| 1368 | |
| 1411 | 1369 | static const UINT8 signatures[6][16] = |
| 1412 | 1370 | { |
| 1413 | 1371 | /* Spacegun */ |
| r9579 | r9580 | |
| 1424 | 1382 | { 0x54, 0x4d, 0x52, 0x20, 0x53, 0x45, 0x47, 0x41, 0xff, 0xff, 0x9f, 0x74, 0x34, 0x70, 0x00, 0x40 }, |
| 1425 | 1383 | }; |
| 1426 | 1384 | |
| 1427 | | if (!(sms_state.bios_port & IO_CARTRIDGE) && sms_state.cartridge[sms_state.current_cartridge].size >= 0x8000) |
| 1385 | if (!(state->bios_port & IO_CARTRIDGE) && state->cartridge[state->current_cartridge].size >= 0x8000) |
| 1428 | 1386 | { |
| 1429 | 1387 | if (!memcmp(&rom[0x7ff0], signatures[0], 16) || !memcmp(&rom[0x7ff0], signatures[1], 16)) |
| 1430 | 1388 | return 40; |
| r9579 | r9580 | |
| 1448 | 1406 | |
| 1449 | 1407 | DEVICE_START( sms_cart ) |
| 1450 | 1408 | { |
| 1409 | sms_state *state = device->machine->driver_data<sms_state>(); |
| 1451 | 1410 | int i; |
| 1452 | 1411 | |
| 1453 | 1412 | for (i = 0; i < MAX_CARTRIDGES; i++) |
| 1454 | 1413 | { |
| 1455 | | sms_state.cartridge[i].ROM = NULL; |
| 1456 | | sms_state.cartridge[i].size = 0; |
| 1457 | | sms_state.cartridge[i].features = 0; |
| 1458 | | sms_state.cartridge[i].cartSRAM = NULL; |
| 1459 | | sms_state.cartridge[i].sram_save = 0; |
| 1460 | | sms_state.cartridge[i].cartRAM = NULL; |
| 1461 | | sms_state.cartridge[i].ram_size = 0; |
| 1462 | | sms_state.cartridge[i].ram_page = 0; |
| 1414 | state->cartridge[i].ROM = NULL; |
| 1415 | state->cartridge[i].size = 0; |
| 1416 | state->cartridge[i].features = 0; |
| 1417 | state->cartridge[i].cartSRAM = NULL; |
| 1418 | state->cartridge[i].sram_save = 0; |
| 1419 | state->cartridge[i].cartRAM = NULL; |
| 1420 | state->cartridge[i].ram_size = 0; |
| 1421 | state->cartridge[i].ram_page = 0; |
| 1463 | 1422 | } |
| 1464 | | sms_state.current_cartridge = 0; |
| 1423 | state->current_cartridge = 0; |
| 1465 | 1424 | |
| 1466 | | sms_state.bios_port = (IO_EXPANSION | IO_CARTRIDGE | IO_CARD); |
| 1467 | | if (!sms_state.is_gamegear && !sms_state.has_bios) |
| 1425 | state->bios_port = (IO_EXPANSION | IO_CARTRIDGE | IO_CARD); |
| 1426 | if (!state->is_gamegear && !state->has_bios) |
| 1468 | 1427 | { |
| 1469 | | sms_state.bios_port &= ~(IO_CARTRIDGE); |
| 1470 | | sms_state.bios_port |= IO_BIOS_ROM; |
| 1428 | state->bios_port &= ~(IO_CARTRIDGE); |
| 1429 | state->bios_port |= IO_BIOS_ROM; |
| 1471 | 1430 | } |
| 1472 | 1431 | } |
| 1473 | 1432 | |
| 1474 | 1433 | |
| 1475 | 1434 | DEVICE_IMAGE_LOAD( sms_cart ) |
| 1476 | 1435 | { |
| 1436 | running_machine *machine = image.device().machine; |
| 1437 | sms_state *state = machine->driver_data<sms_state>(); |
| 1477 | 1438 | int size, index = 0, offset = 0; |
| 1478 | 1439 | const char *extrainfo = NULL; |
| 1479 | 1440 | |
| r9579 | r9580 | |
| 1510 | 1471 | if (strcmp(image.device().tag(), "cart16") == 0) |
| 1511 | 1472 | index = 15; |
| 1512 | 1473 | |
| 1513 | | sms_state.cartridge[index].features = 0; |
| 1474 | state->cartridge[index].features = 0; |
| 1514 | 1475 | |
| 1515 | 1476 | if (image.software_entry() == NULL) |
| 1516 | 1477 | { |
| r9579 | r9580 | |
| 1536 | 1497 | |
| 1537 | 1498 | /* Create a new memory region to hold the ROM. */ |
| 1538 | 1499 | /* Make sure the region holds only complete (0x4000) rom banks */ |
| 1539 | | sms_state.cartridge[index].size = (size & 0x3fff) ? (((size >> 14) + 1) << 14) : size; |
| 1540 | | sms_state.cartridge[index].ROM = auto_alloc_array(image.device().machine, UINT8, sms_state.cartridge[index].size); |
| 1541 | | sms_state.cartridge[index].cartSRAM = auto_alloc_array(image.device().machine, UINT8, NVRAM_SIZE); |
| 1500 | state->cartridge[index].size = (size & 0x3fff) ? (((size >> 14) + 1) << 14) : size; |
| 1501 | state->cartridge[index].ROM = auto_alloc_array(machine, UINT8, state->cartridge[index].size); |
| 1502 | state->cartridge[index].cartSRAM = auto_alloc_array(machine, UINT8, NVRAM_SIZE); |
| 1542 | 1503 | |
| 1543 | 1504 | /* Load ROM banks */ |
| 1544 | 1505 | if (image.software_entry() == NULL) |
| 1545 | 1506 | { |
| 1546 | 1507 | image.fseek(offset, SEEK_SET); |
| 1547 | 1508 | |
| 1548 | | if (image.fread( sms_state.cartridge[index].ROM, size) != size) |
| 1509 | if (image.fread( state->cartridge[index].ROM, size) != size) |
| 1549 | 1510 | return IMAGE_INIT_FAIL; |
| 1550 | 1511 | } |
| 1551 | 1512 | else |
| 1552 | 1513 | { |
| 1553 | | memcpy(sms_state.cartridge[index].ROM, image.get_software_region("rom") + offset, size); |
| 1514 | memcpy(state->cartridge[index].ROM, image.get_software_region("rom") + offset, size); |
| 1554 | 1515 | |
| 1555 | 1516 | // check for mapper feature (currently only KOREAN_NOBANK, but eventually we will add the other mappers as well) |
| 1556 | 1517 | if (image.get_feature("pcb") != NULL) |
| 1557 | 1518 | { |
| 1558 | 1519 | const char *mapper = image.get_feature("pcb"); |
| 1559 | 1520 | if (!strcmp(mapper, "korean_nobank")) |
| 1560 | | sms_state.cartridge[index].features |= CF_KOREAN_NOBANK_MAPPER; |
| 1521 | state->cartridge[index].features |= CF_KOREAN_NOBANK_MAPPER; |
| 1561 | 1522 | } |
| 1562 | 1523 | } |
| 1563 | 1524 | |
| 1564 | 1525 | /* check the image */ |
| 1565 | | if (!sms_state.has_bios) |
| 1526 | if (!state->has_bios) |
| 1566 | 1527 | { |
| 1567 | | if (sms_verify_cart(sms_state.cartridge[index].ROM, size) == IMAGE_VERIFY_FAIL) |
| 1528 | if (sms_verify_cart(state->cartridge[index].ROM, size) == IMAGE_VERIFY_FAIL) |
| 1568 | 1529 | { |
| 1569 | 1530 | logerror("Warning loading image: sms_verify_cart failed\n"); |
| 1570 | 1531 | } |
| r9579 | r9580 | |
| 1575 | 1536 | { |
| 1576 | 1537 | /* Check for codemasters mapper */ |
| 1577 | 1538 | if (strstr(extrainfo, "CODEMASTERS")) |
| 1578 | | sms_state.cartridge[index].features |= CF_CODEMASTERS_MAPPER; |
| 1539 | state->cartridge[index].features |= CF_CODEMASTERS_MAPPER; |
| 1579 | 1540 | |
| 1580 | 1541 | /* Check for korean mapper */ |
| 1581 | 1542 | if (strstr(extrainfo, "KOREAN")) |
| 1582 | | sms_state.cartridge[index].features |= CF_KOREAN_MAPPER; |
| 1543 | state->cartridge[index].features |= CF_KOREAN_MAPPER; |
| 1583 | 1544 | |
| 1584 | 1545 | /* Check for special SMS Compatibility mode gamegear cartridges */ |
| 1585 | | if (sms_state.is_gamegear && strstr(extrainfo, "GGSMS")) |
| 1586 | | sms_state.cartridge[index].features |= CF_GG_SMS_MODE; |
| 1546 | if (state->is_gamegear && strstr(extrainfo, "GGSMS")) |
| 1547 | state->cartridge[index].features |= CF_GG_SMS_MODE; |
| 1587 | 1548 | |
| 1588 | 1549 | /* Check for 93C46 eeprom */ |
| 1589 | 1550 | if (strstr(extrainfo, "93C46")) |
| 1590 | | sms_state.cartridge[index].features |= CF_93C46_EEPROM; |
| 1551 | state->cartridge[index].features |= CF_93C46_EEPROM; |
| 1591 | 1552 | |
| 1592 | 1553 | /* Check for 8KB on-cart RAM */ |
| 1593 | 1554 | if (strstr(extrainfo, "8KB_CART_RAM")) |
| 1594 | 1555 | { |
| 1595 | | sms_state.cartridge[index].features |= CF_ONCART_RAM; |
| 1596 | | sms_state.cartridge[index].ram_size = 0x2000; |
| 1597 | | sms_state.cartridge[index].cartRAM = auto_alloc_array(image.device().machine, UINT8, sms_state.cartridge[index].ram_size); |
| 1556 | state->cartridge[index].features |= CF_ONCART_RAM; |
| 1557 | state->cartridge[index].ram_size = 0x2000; |
| 1558 | state->cartridge[index].cartRAM = auto_alloc_array(machine, UINT8, state->cartridge[index].ram_size); |
| 1598 | 1559 | } |
| 1599 | 1560 | } |
| 1600 | 1561 | else |
| r9579 | r9580 | |
| 1606 | 1567 | int c0002 = 0, c8000 = 0, cA000 = 0, cFFFF = 0, i; |
| 1607 | 1568 | for (i = 0; i < 0x8000; i++) |
| 1608 | 1569 | { |
| 1609 | | if (sms_state.cartridge[index].ROM[i] == 0x32) // Z80 opcode for: LD (xxxx), A |
| 1570 | if (state->cartridge[index].ROM[i] == 0x32) // Z80 opcode for: LD (xxxx), A |
| 1610 | 1571 | { |
| 1611 | | UINT16 addr = (sms_state.cartridge[index].ROM[i + 2] << 8) | sms_state.cartridge[index].ROM[i + 1]; |
| 1572 | UINT16 addr = (state->cartridge[index].ROM[i + 2] << 8) | state->cartridge[index].ROM[i + 1]; |
| 1612 | 1573 | if (addr == 0xFFFF) |
| 1613 | 1574 | { i += 2; cFFFF++; continue; } |
| 1614 | 1575 | if (addr == 0x0002 || addr == 0x0003 || addr == 0x0004) |
| r9579 | r9580 | |
| 1624 | 1585 | |
| 1625 | 1586 | // 2 is a security measure, although tests on existing ROM showed it was not needed |
| 1626 | 1587 | if (c0002 > cFFFF + 2 || (c0002 > 0 && cFFFF == 0)) |
| 1627 | | sms_state.cartridge[index].features |= CF_KOREAN_ZEMINA_MAPPER; |
| 1588 | state->cartridge[index].features |= CF_KOREAN_ZEMINA_MAPPER; |
| 1628 | 1589 | else if (c8000 > cFFFF + 2 || (c8000 > 0 && cFFFF == 0)) |
| 1629 | | sms_state.cartridge[index].features |= CF_CODEMASTERS_MAPPER; |
| 1590 | state->cartridge[index].features |= CF_CODEMASTERS_MAPPER; |
| 1630 | 1591 | else if (cA000 > cFFFF + 2 || (cA000 > 0 && cFFFF == 0)) |
| 1631 | | sms_state.cartridge[index].features |= CF_KOREAN_MAPPER; |
| 1592 | state->cartridge[index].features |= CF_KOREAN_MAPPER; |
| 1632 | 1593 | |
| 1633 | 1594 | } |
| 1634 | 1595 | |
| 1635 | 1596 | /* Check for special SMS Compatibility mode gamegear cartridges */ |
| 1636 | | if (sms_state.is_gamegear && image.software_entry() == NULL) // not sure about how to handle this with softlists |
| 1597 | if (state->is_gamegear && image.software_entry() == NULL) // not sure about how to handle this with softlists |
| 1637 | 1598 | { |
| 1638 | 1599 | /* Just in case someone passes us an sms file */ |
| 1639 | 1600 | if (!mame_stricmp (image.filetype(), "sms")) |
| 1640 | | sms_state.cartridge[index].features |= CF_GG_SMS_MODE; |
| 1601 | state->cartridge[index].features |= CF_GG_SMS_MODE; |
| 1641 | 1602 | } |
| 1642 | 1603 | } |
| 1643 | 1604 | |
| 1644 | | if (sms_state.cartridge[index].features & CF_CODEMASTERS_MAPPER) |
| 1605 | if (state->cartridge[index].features & CF_CODEMASTERS_MAPPER) |
| 1645 | 1606 | { |
| 1646 | | sms_state.cartridge[index].ram_size = 0x10000; |
| 1647 | | sms_state.cartridge[index].cartRAM = auto_alloc_array(image.device().machine, UINT8, sms_state.cartridge[index].ram_size); |
| 1648 | | sms_state.cartridge[index].ram_page = 0; |
| 1607 | state->cartridge[index].ram_size = 0x10000; |
| 1608 | state->cartridge[index].cartRAM = auto_alloc_array(machine, UINT8, state->cartridge[index].ram_size); |
| 1609 | state->cartridge[index].ram_page = 0; |
| 1649 | 1610 | } |
| 1650 | 1611 | |
| 1651 | 1612 | /* For Light Phaser games, we have to detect the x offset */ |
| 1652 | | sms_state.lphaser_x_offs = detect_lphaser_xoffset(sms_state.cartridge[index].ROM); |
| 1613 | state->lphaser_x_offs = detect_lphaser_xoffset(machine, state->cartridge[index].ROM); |
| 1653 | 1614 | |
| 1654 | 1615 | /* Terebi Oekaki (TV Draw) is a SG1000 game with special input device which is compatible with SG1000 Mark III */ |
| 1655 | | if ((detect_tvdraw(sms_state.cartridge[index].ROM)) && sms_state.is_region_japan) |
| 1616 | if ((detect_tvdraw(state->cartridge[index].ROM)) && state->is_region_japan) |
| 1656 | 1617 | { |
| 1657 | | address_space *program = cputag_get_address_space(image.device().machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 1618 | address_space *program = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 1658 | 1619 | memory_install_write8_handler(program, 0x6000, 0x6000, 0, 0, &sms_tvdraw_axis_w); |
| 1659 | 1620 | memory_install_read8_handler(program, 0x8000, 0x8000, 0, 0, &sms_tvdraw_status_r); |
| 1660 | 1621 | memory_install_read8_handler(program, 0xa000, 0xa000, 0, 0, &sms_tvdraw_data_r); |
| 1661 | 1622 | memory_nop_write(program, 0xa000, 0xa000, 0, 0); |
| 1662 | 1623 | } |
| 1663 | 1624 | |
| 1664 | | if (sms_state.cartridge[index].features & CF_KOREAN_NOBANK_MAPPER) |
| 1625 | if (state->cartridge[index].features & CF_KOREAN_NOBANK_MAPPER) |
| 1665 | 1626 | { |
| 1666 | 1627 | // FIXME: we should have by default FFFD-FFFF to be only a mirror for DFFD-DFFF (with no bankswitch logic) |
| 1667 | 1628 | // and then the handlers should be installed here for all but the KOREAN_NOBANK carts |
| 1668 | 1629 | // However, to avoid memory map breakage, we currently go the other way around |
| 1669 | | address_space *program = cputag_get_address_space(image.device().machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 1630 | address_space *program = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 1670 | 1631 | memory_install_readwrite8_handler(program, 0xfffc, 0xffff, 0, 0, &sms_kor_nobank_r, &sms_kor_nobank_w); |
| 1671 | 1632 | } |
| 1672 | 1633 | |
| 1673 | | LOG(("Cart Features: %x\n", sms_state.cartridge[index].features)); |
| 1634 | LOG(("Cart Features: %x\n", state->cartridge[index].features)); |
| 1674 | 1635 | |
| 1675 | 1636 | /* Load battery backed RAM, if available */ |
| 1676 | | image.battery_load(sms_state.cartridge[index].cartSRAM, sizeof(UINT8) * NVRAM_SIZE, 0x00); |
| 1637 | image.battery_load(state->cartridge[index].cartSRAM, sizeof(UINT8) * NVRAM_SIZE, 0x00); |
| 1677 | 1638 | |
| 1678 | 1639 | return IMAGE_INIT_PASS; |
| 1679 | 1640 | } |
| 1680 | 1641 | |
| 1681 | 1642 | |
| 1682 | | static void setup_cart_banks( void ) |
| 1643 | static void setup_cart_banks( running_machine *machine ) |
| 1683 | 1644 | { |
| 1684 | | if (sms_state.cartridge[sms_state.current_cartridge].ROM) |
| 1645 | sms_state *state = machine->driver_data<sms_state>(); |
| 1646 | if (state->cartridge[state->current_cartridge].ROM) |
| 1685 | 1647 | { |
| 1686 | | UINT8 rom_page_count = sms_state.cartridge[sms_state.current_cartridge].size / 0x4000; |
| 1687 | | sms_state.banking_cart[1] = sms_state.cartridge[sms_state.current_cartridge].ROM; |
| 1688 | | sms_state.banking_cart[2] = sms_state.cartridge[sms_state.current_cartridge].ROM + 0x0400; |
| 1689 | | sms_state.banking_cart[3] = sms_state.cartridge[sms_state.current_cartridge].ROM + ((1 < rom_page_count) ? 0x4000 : 0); |
| 1690 | | sms_state.banking_cart[5] = sms_state.cartridge[sms_state.current_cartridge].ROM + ((2 < rom_page_count) ? 0x8000 : 0); |
| 1648 | UINT8 rom_page_count = state->cartridge[state->current_cartridge].size / 0x4000; |
| 1649 | state->banking_cart[1] = state->cartridge[state->current_cartridge].ROM; |
| 1650 | state->banking_cart[2] = state->cartridge[state->current_cartridge].ROM + 0x0400; |
| 1651 | state->banking_cart[3] = state->cartridge[state->current_cartridge].ROM + ((1 < rom_page_count) ? 0x4000 : 0); |
| 1652 | state->banking_cart[5] = state->cartridge[state->current_cartridge].ROM + ((2 < rom_page_count) ? 0x8000 : 0); |
| 1691 | 1653 | /* Codemasters mapper points to bank 0 for page 2 */ |
| 1692 | | if (sms_state.cartridge[sms_state.current_cartridge].features & CF_CODEMASTERS_MAPPER) |
| 1654 | if (state->cartridge[state->current_cartridge].features & CF_CODEMASTERS_MAPPER) |
| 1693 | 1655 | { |
| 1694 | | sms_state.banking_cart[5] = sms_state.cartridge[sms_state.current_cartridge].ROM; |
| 1656 | state->banking_cart[5] = state->cartridge[state->current_cartridge].ROM; |
| 1695 | 1657 | } |
| 1696 | 1658 | } |
| 1697 | 1659 | else |
| 1698 | 1660 | { |
| 1699 | | sms_state.banking_cart[1] = sms_state.banking_none[1]; |
| 1700 | | sms_state.banking_cart[2] = sms_state.banking_none[2]; |
| 1701 | | sms_state.banking_cart[3] = sms_state.banking_none[3]; |
| 1702 | | sms_state.banking_cart[5] = sms_state.banking_none[5]; |
| 1661 | state->banking_cart[1] = state->banking_none[1]; |
| 1662 | state->banking_cart[2] = state->banking_none[2]; |
| 1663 | state->banking_cart[3] = state->banking_none[3]; |
| 1664 | state->banking_cart[5] = state->banking_none[5]; |
| 1703 | 1665 | } |
| 1704 | 1666 | } |
| 1705 | 1667 | |
| 1706 | 1668 | |
| 1707 | 1669 | static void setup_banks( running_machine *machine ) |
| 1708 | 1670 | { |
| 1671 | sms_state *state = machine->driver_data<sms_state>(); |
| 1709 | 1672 | UINT8 *mem = memory_region(machine, "maincpu"); |
| 1710 | | sms_state.banking_bios[1] = sms_state.banking_cart[1] = sms_state.banking_none[1] = mem; |
| 1711 | | sms_state.banking_bios[2] = sms_state.banking_cart[2] = sms_state.banking_none[2] = mem; |
| 1712 | | sms_state.banking_bios[3] = sms_state.banking_cart[3] = sms_state.banking_none[3] = mem; |
| 1713 | | sms_state.banking_bios[4] = sms_state.banking_cart[4] = sms_state.banking_none[4] = mem; |
| 1714 | | sms_state.banking_bios[5] = sms_state.banking_cart[5] = sms_state.banking_none[5] = mem; |
| 1715 | | sms_state.banking_bios[6] = sms_state.banking_cart[6] = sms_state.banking_none[6] = mem; |
| 1673 | state->banking_bios[1] = state->banking_cart[1] = state->banking_none[1] = mem; |
| 1674 | state->banking_bios[2] = state->banking_cart[2] = state->banking_none[2] = mem; |
| 1675 | state->banking_bios[3] = state->banking_cart[3] = state->banking_none[3] = mem; |
| 1676 | state->banking_bios[4] = state->banking_cart[4] = state->banking_none[4] = mem; |
| 1677 | state->banking_bios[5] = state->banking_cart[5] = state->banking_none[5] = mem; |
| 1678 | state->banking_bios[6] = state->banking_cart[6] = state->banking_none[6] = mem; |
| 1716 | 1679 | |
| 1717 | | sms_state.BIOS = memory_region(machine, "user1"); |
| 1680 | state->BIOS = memory_region(machine, "user1"); |
| 1718 | 1681 | |
| 1719 | | sms_state.bios_page_count = (sms_state.BIOS ? memory_region_length(machine, "user1") / 0x4000 : 0); |
| 1682 | state->bios_page_count = (state->BIOS ? memory_region_length(machine, "user1") / 0x4000 : 0); |
| 1720 | 1683 | |
| 1721 | | setup_cart_banks(); |
| 1684 | setup_cart_banks(machine); |
| 1722 | 1685 | |
| 1723 | | if (sms_state.BIOS == NULL || sms_state.BIOS[0] == 0x00) |
| 1686 | if (state->BIOS == NULL || state->BIOS[0] == 0x00) |
| 1724 | 1687 | { |
| 1725 | | sms_state.BIOS = NULL; |
| 1726 | | sms_state.bios_port |= IO_BIOS_ROM; |
| 1688 | state->BIOS = NULL; |
| 1689 | state->bios_port |= IO_BIOS_ROM; |
| 1727 | 1690 | } |
| 1728 | 1691 | |
| 1729 | | if (sms_state.BIOS) |
| 1692 | if (state->BIOS) |
| 1730 | 1693 | { |
| 1731 | | sms_state.banking_bios[1] = sms_state.BIOS; |
| 1732 | | sms_state.banking_bios[2] = sms_state.BIOS + 0x0400; |
| 1733 | | sms_state.banking_bios[3] = sms_state.BIOS + ((1 < sms_state.bios_page_count) ? 0x4000 : 0); |
| 1734 | | sms_state.banking_bios[5] = sms_state.BIOS + ((2 < sms_state.bios_page_count) ? 0x8000 : 0); |
| 1694 | state->banking_bios[1] = state->BIOS; |
| 1695 | state->banking_bios[2] = state->BIOS + 0x0400; |
| 1696 | state->banking_bios[3] = state->BIOS + ((1 < state->bios_page_count) ? 0x4000 : 0); |
| 1697 | state->banking_bios[5] = state->BIOS + ((2 < state->bios_page_count) ? 0x8000 : 0); |
| 1735 | 1698 | } |
| 1736 | 1699 | } |
| 1737 | 1700 | |
| 1738 | 1701 | |
| 1739 | 1702 | MACHINE_START( sms ) |
| 1740 | 1703 | { |
| 1704 | sms_state *state = machine->driver_data<sms_state>(); |
| 1705 | |
| 1741 | 1706 | machine->add_notifier(MACHINE_NOTIFY_EXIT, sms_machine_stop); |
| 1742 | | sms_state.rapid_fire_timer = timer_alloc(machine, rapid_fire_callback , NULL); |
| 1743 | | timer_adjust_periodic(sms_state.rapid_fire_timer, ATTOTIME_IN_HZ(10), 0, ATTOTIME_IN_HZ(10)); |
| 1707 | state->rapid_fire_timer = timer_alloc(machine, rapid_fire_callback , NULL); |
| 1708 | timer_adjust_periodic(state->rapid_fire_timer, ATTOTIME_IN_HZ(10), 0, ATTOTIME_IN_HZ(10)); |
| 1744 | 1709 | |
| 1745 | | sms_state.lphaser_1_timer = timer_alloc(machine, lphaser_1_callback , NULL); |
| 1746 | | sms_state.lphaser_2_timer = timer_alloc(machine, lphaser_2_callback , NULL); |
| 1710 | state->lphaser_1_timer = timer_alloc(machine, lphaser_1_callback , NULL); |
| 1711 | state->lphaser_2_timer = timer_alloc(machine, lphaser_2_callback , NULL); |
| 1747 | 1712 | |
| 1713 | state->main_cpu = machine->device("maincpu"); |
| 1714 | state->control_cpu = machine->device("control"); |
| 1715 | state->vdp = machine->device("sms_vdp"); |
| 1716 | state->ym = machine->device("ym2413"); |
| 1717 | state->main_scr = machine->device("screen"); |
| 1718 | state->left_lcd = machine->device("left_lcd"); |
| 1719 | state->right_lcd = machine->device("right_lcd"); |
| 1720 | |
| 1748 | 1721 | /* Check if lightgun has been chosen as input: if so, enable crosshair */ |
| 1749 | 1722 | timer_set(machine, attotime_zero, NULL, 0, lightgun_tick); |
| 1750 | 1723 | } |
| r9579 | r9580 | |
| 1753 | 1726 | MACHINE_RESET( sms ) |
| 1754 | 1727 | { |
| 1755 | 1728 | address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 1756 | | running_device *smsvdp = machine->device("sms_vdp"); |
| 1729 | sms_state *state = machine->driver_data<sms_state>(); |
| 1757 | 1730 | |
| 1758 | | sms_state.ctrl_reg = 0xff; |
| 1759 | | if (sms_state.has_fm) |
| 1760 | | sms_state.fm_detect = 0x01; |
| 1731 | state->ctrl_reg = 0xff; |
| 1732 | if (state->has_fm) |
| 1733 | state->fm_detect = 0x01; |
| 1761 | 1734 | |
| 1762 | | sms_state.mapper_ram = (UINT8*)space->get_write_ptr(0xdffc); |
| 1735 | state->mapper_ram = (UINT8*)space->get_write_ptr(0xdffc); |
| 1763 | 1736 | |
| 1764 | | sms_state.bios_port = 0; |
| 1737 | state->bios_port = 0; |
| 1765 | 1738 | |
| 1766 | | if (sms_state.cartridge[sms_state.current_cartridge].features & CF_CODEMASTERS_MAPPER) |
| 1739 | if (state->cartridge[state->current_cartridge].features & CF_CODEMASTERS_MAPPER) |
| 1767 | 1740 | { |
| 1768 | 1741 | /* Install special memory handlers */ |
| 1769 | 1742 | memory_install_write8_handler(space, 0x0000, 0x0000, 0, 0, sms_codemasters_page0_w); |
| 1770 | 1743 | memory_install_write8_handler(space, 0x4000, 0x4000, 0, 0, sms_codemasters_page1_w); |
| 1771 | 1744 | } |
| 1772 | 1745 | |
| 1773 | | if (sms_state.cartridge[sms_state.current_cartridge].features & CF_KOREAN_ZEMINA_MAPPER) |
| 1746 | if (state->cartridge[state->current_cartridge].features & CF_KOREAN_ZEMINA_MAPPER) |
| 1774 | 1747 | memory_install_write8_handler(space, 0x0000, 0x0003, 0, 0, sms_korean_zemina_banksw_w); |
| 1775 | 1748 | |
| 1776 | | if (sms_state.cartridge[sms_state.current_cartridge].features & CF_GG_SMS_MODE) |
| 1777 | | sms_vdp_set_ggsmsmode(smsvdp, 1); |
| 1749 | if (state->cartridge[state->current_cartridge].features & CF_GG_SMS_MODE) |
| 1750 | sms_vdp_set_ggsmsmode(state->vdp, 1); |
| 1778 | 1751 | |
| 1779 | 1752 | /* Initialize SIO stuff for GG */ |
| 1780 | | sms_state.gg_sio[0] = 0x7f; |
| 1781 | | sms_state.gg_sio[1] = 0xff; |
| 1782 | | sms_state.gg_sio[2] = 0x00; |
| 1783 | | sms_state.gg_sio[3] = 0xff; |
| 1784 | | sms_state.gg_sio[4] = 0x00; |
| 1753 | state->gg_sio[0] = 0x7f; |
| 1754 | state->gg_sio[1] = 0xff; |
| 1755 | state->gg_sio[2] = 0x00; |
| 1756 | state->gg_sio[3] = 0xff; |
| 1757 | state->gg_sio[4] = 0x00; |
| 1785 | 1758 | |
| 1786 | | sms_state.store_control = 0; |
| 1759 | state->store_control = 0; |
| 1787 | 1760 | |
| 1788 | 1761 | setup_banks(machine); |
| 1789 | 1762 | |
| 1790 | 1763 | setup_rom(space); |
| 1791 | 1764 | |
| 1792 | | sms_state.rapid_fire_state_1 = 0; |
| 1793 | | sms_state.rapid_fire_state_2 = 0; |
| 1765 | state->rapid_fire_state_1 = 0; |
| 1766 | state->rapid_fire_state_2 = 0; |
| 1794 | 1767 | |
| 1795 | | sms_state.last_paddle_read_time = 0; |
| 1796 | | sms_state.paddle_read_state = 0; |
| 1768 | state->last_paddle_read_time = 0; |
| 1769 | state->paddle_read_state = 0; |
| 1797 | 1770 | |
| 1798 | | sms_state.last_sports_pad_time_1 = 0; |
| 1799 | | sms_state.last_sports_pad_time_2 = 0; |
| 1800 | | sms_state.sports_pad_state_1 = 0; |
| 1801 | | sms_state.sports_pad_state_2 = 0; |
| 1802 | | sms_state.sports_pad_last_data_1 = 0; |
| 1803 | | sms_state.sports_pad_last_data_2 = 0; |
| 1804 | | sms_state.sports_pad_1_x = 0; |
| 1805 | | sms_state.sports_pad_1_y = 0; |
| 1806 | | sms_state.sports_pad_2_x = 0; |
| 1807 | | sms_state.sports_pad_2_y = 0; |
| 1771 | state->last_sports_pad_time_1 = 0; |
| 1772 | state->last_sports_pad_time_2 = 0; |
| 1773 | state->sports_pad_state_1 = 0; |
| 1774 | state->sports_pad_state_2 = 0; |
| 1775 | state->sports_pad_last_data_1 = 0; |
| 1776 | state->sports_pad_last_data_2 = 0; |
| 1777 | state->sports_pad_1_x = 0; |
| 1778 | state->sports_pad_1_y = 0; |
| 1779 | state->sports_pad_2_x = 0; |
| 1780 | state->sports_pad_2_y = 0; |
| 1808 | 1781 | |
| 1809 | | sms_state.lphaser_1_latch = 0; |
| 1810 | | sms_state.lphaser_2_latch = 0; |
| 1782 | state->lphaser_1_latch = 0; |
| 1783 | state->lphaser_2_latch = 0; |
| 1811 | 1784 | |
| 1812 | | sms_state.sscope_state = 0; |
| 1785 | state->sscope_state = 0; |
| 1813 | 1786 | |
| 1814 | | sms_state.tvdraw_data = 0; |
| 1787 | state->tvdraw_data = 0; |
| 1815 | 1788 | } |
| 1816 | 1789 | |
| 1817 | 1790 | |
| r9579 | r9580 | |
| 1823 | 1796 | |
| 1824 | 1797 | WRITE8_HANDLER( sms_store_cart_select_w ) |
| 1825 | 1798 | { |
| 1799 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 1826 | 1800 | UINT8 slot = data >> 4; |
| 1827 | 1801 | UINT8 slottype = data & 0x08; |
| 1828 | 1802 | |
| 1829 | 1803 | logerror("switching in part of %s slot #%d\n", slottype ? "card" : "cartridge", slot ); |
| 1830 | 1804 | /* cartridge? slot #0 */ |
| 1831 | 1805 | if (slottype == 0) |
| 1832 | | sms_state.current_cartridge = slot; |
| 1806 | state->current_cartridge = slot; |
| 1833 | 1807 | |
| 1834 | | setup_cart_banks(); |
| 1835 | | memory_set_bankptr(space->machine, "bank10", sms_state.banking_cart[3] + 0x2000); |
| 1808 | setup_cart_banks(space->machine); |
| 1809 | memory_set_bankptr(space->machine, "bank10", state->banking_cart[3] + 0x2000); |
| 1836 | 1810 | setup_rom(space); |
| 1837 | 1811 | } |
| 1838 | 1812 | |
| r9579 | r9580 | |
| 1851 | 1825 | |
| 1852 | 1826 | READ8_HANDLER( sms_store_control_r ) |
| 1853 | 1827 | { |
| 1854 | | return sms_state.store_control; |
| 1828 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 1829 | return state->store_control; |
| 1855 | 1830 | } |
| 1856 | 1831 | |
| 1857 | 1832 | |
| 1858 | 1833 | WRITE8_HANDLER( sms_store_control_w ) |
| 1859 | 1834 | { |
| 1835 | sms_state *state = space->machine->driver_data<sms_state>(); |
| 1860 | 1836 | logerror("0x%04X: sms_store_control write 0x%02X\n", cpu_get_pc(space->cpu), data); |
| 1861 | 1837 | if (data & 0x02) |
| 1862 | 1838 | { |
| r9579 | r9580 | |
| 1868 | 1844 | space->machine->device("maincpu")->reset(); |
| 1869 | 1845 | space->machine->device<cpu_device>("maincpu")->suspend(SUSPEND_REASON_HALT, 1); |
| 1870 | 1846 | } |
| 1871 | | sms_state.store_control = data; |
| 1847 | state->store_control = data; |
| 1872 | 1848 | } |
| 1873 | 1849 | |
| 1874 | 1850 | void sms_store_int_callback( running_machine *machine, int state ) |
| 1875 | 1851 | { |
| 1876 | | cputag_set_input_line(machine, sms_state.store_control & 0x01 ? "control" : "maincpu", 0, state); |
| 1852 | sms_state *driver_state = machine->driver_data<sms_state>(); |
| 1853 | cpu_set_input_line(driver_state->store_control & 0x01 ? driver_state->control_cpu : driver_state->main_cpu, 0, state); |
| 1877 | 1854 | } |
| 1878 | 1855 | |
| 1879 | 1856 | |
| 1880 | | static void sms_set_zero_flag( void ) |
| 1857 | static void sms_set_zero_flag( running_machine *machine ) |
| 1881 | 1858 | { |
| 1882 | | sms_state.is_gamegear = 0; |
| 1883 | | sms_state.is_region_japan = 0; |
| 1884 | | sms_state.has_bios_0400 = 0; |
| 1885 | | sms_state.has_bios_2000 = 0; |
| 1886 | | sms_state.has_bios_full = 0; |
| 1887 | | sms_state.has_bios = 0; |
| 1888 | | sms_state.has_fm = 0; |
| 1859 | sms_state *state = machine->driver_data<sms_state>(); |
| 1860 | state->is_gamegear = 0; |
| 1861 | state->is_region_japan = 0; |
| 1862 | state->has_bios_0400 = 0; |
| 1863 | state->has_bios_2000 = 0; |
| 1864 | state->has_bios_full = 0; |
| 1865 | state->has_bios = 0; |
| 1866 | state->has_fm = 0; |
| 1889 | 1867 | } |
| 1890 | 1868 | |
| 1891 | 1869 | DRIVER_INIT( sg1000m3 ) |
| 1892 | 1870 | { |
| 1893 | | sms_set_zero_flag(); |
| 1894 | | sms_state.is_region_japan = 1; |
| 1895 | | sms_state.has_fm = 1; |
| 1871 | sms_state *state = machine->driver_data<sms_state>(); |
| 1872 | sms_set_zero_flag(machine); |
| 1873 | state->is_region_japan = 1; |
| 1874 | state->has_fm = 1; |
| 1896 | 1875 | } |
| 1897 | 1876 | |
| 1898 | 1877 | |
| 1899 | 1878 | DRIVER_INIT( sms1 ) |
| 1900 | 1879 | { |
| 1901 | | sms_set_zero_flag(); |
| 1902 | | sms_state.has_bios_full = 1; |
| 1880 | sms_state *state = machine->driver_data<sms_state>(); |
| 1881 | sms_set_zero_flag(machine); |
| 1882 | state->has_bios_full = 1; |
| 1903 | 1883 | } |
| 1904 | 1884 | |
| 1905 | 1885 | |
| 1906 | 1886 | DRIVER_INIT( smsj ) |
| 1907 | 1887 | { |
| 1908 | | sms_set_zero_flag(); |
| 1909 | | sms_state.is_region_japan = 1; |
| 1910 | | sms_state.has_bios_2000 = 1; |
| 1911 | | sms_state.has_fm = 1; |
| 1888 | sms_state *state = machine->driver_data<sms_state>(); |
| 1889 | sms_set_zero_flag(machine); |
| 1890 | state->is_region_japan = 1; |
| 1891 | state->has_bios_2000 = 1; |
| 1892 | state->has_fm = 1; |
| 1912 | 1893 | } |
| 1913 | 1894 | |
| 1914 | 1895 | |
| 1915 | 1896 | DRIVER_INIT( sms2kr ) |
| 1916 | 1897 | { |
| 1917 | | sms_set_zero_flag(); |
| 1918 | | sms_state.is_region_japan = 1; |
| 1919 | | sms_state.has_bios_full = 1; |
| 1920 | | sms_state.has_fm = 1; |
| 1898 | sms_state *state = machine->driver_data<sms_state>(); |
| 1899 | sms_set_zero_flag(machine); |
| 1900 | state->is_region_japan = 1; |
| 1901 | state->has_bios_full = 1; |
| 1902 | state->has_fm = 1; |
| 1921 | 1903 | } |
| 1922 | 1904 | |
| 1923 | 1905 | |
| 1924 | 1906 | DRIVER_INIT( smssdisp ) |
| 1925 | 1907 | { |
| 1926 | | sms_set_zero_flag(); |
| 1908 | sms_set_zero_flag(machine); |
| 1927 | 1909 | } |
| 1928 | 1910 | |
| 1929 | 1911 | |
| 1930 | 1912 | DRIVER_INIT( gamegear ) |
| 1931 | 1913 | { |
| 1932 | | sms_set_zero_flag(); |
| 1933 | | sms_state.is_gamegear = 1; |
| 1914 | sms_state *state = machine->driver_data<sms_state>(); |
| 1915 | sms_set_zero_flag(machine); |
| 1916 | state->is_gamegear = 1; |
| 1934 | 1917 | } |
| 1935 | 1918 | |
| 1936 | 1919 | |
| 1937 | 1920 | DRIVER_INIT( gamegeaj ) |
| 1938 | 1921 | { |
| 1939 | | sms_set_zero_flag(); |
| 1940 | | sms_state.is_region_japan = 1; |
| 1941 | | sms_state.is_gamegear = 1; |
| 1942 | | sms_state.has_bios_0400 = 1; |
| 1922 | sms_state *state = machine->driver_data<sms_state>(); |
| 1923 | sms_set_zero_flag(machine); |
| 1924 | state->is_region_japan = 1; |
| 1925 | state->is_gamegear = 1; |
| 1926 | state->has_bios_0400 = 1; |
| 1943 | 1927 | } |
| 1944 | 1928 | |
| 1945 | 1929 | |
| r9579 | r9580 | |
| 1957 | 1941 | |
| 1958 | 1942 | VIDEO_START( sms1 ) |
| 1959 | 1943 | { |
| 1944 | sms_state *state = machine->driver_data<sms_state>(); |
| 1960 | 1945 | screen_device *screen = screen_first(*machine); |
| 1961 | 1946 | int width = screen->width(); |
| 1962 | 1947 | int height = screen->height(); |
| 1963 | 1948 | |
| 1964 | | sms_state.prevleft_bitmap = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED32); |
| 1965 | | sms_state.prevright_bitmap = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED32); |
| 1966 | | state_save_register_global_bitmap(machine, sms_state.prevleft_bitmap); |
| 1967 | | state_save_register_global_bitmap(machine, sms_state.prevright_bitmap); |
| 1949 | state->prevleft_bitmap = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED32); |
| 1950 | state->prevright_bitmap = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED32); |
| 1951 | state_save_register_global_bitmap(machine, state->prevleft_bitmap); |
| 1952 | state_save_register_global_bitmap(machine, state->prevright_bitmap); |
| 1968 | 1953 | } |
| 1969 | 1954 | |
| 1970 | 1955 | VIDEO_UPDATE( sms1 ) |
| 1971 | 1956 | { |
| 1972 | | running_device *main_scr = screen->machine->device("screen"); |
| 1973 | | running_device *left_lcd = screen->machine->device("left_lcd"); |
| 1974 | | running_device *right_lcd = screen->machine->device("right_lcd"); |
| 1975 | | running_device *smsvdp = screen->machine->device("sms_vdp"); |
| 1957 | sms_state *state = screen->machine->driver_data<sms_state>(); |
| 1976 | 1958 | UINT8 sscope = input_port_read_safe(screen->machine, "SEGASCOPE", 0x00); |
| 1977 | 1959 | UINT8 sscope_binocular_hack = input_port_read_safe(screen->machine, "SSCOPE_BINOCULAR", 0x00); |
| 1978 | 1960 | UINT8 occluded_view = 0; |
| 1979 | 1961 | |
| 1980 | 1962 | // without SuperScope, both LCDs for glasses go black |
| 1981 | | if ((screen != main_scr) && !sscope) |
| 1963 | if ((screen != state->main_scr) && !sscope) |
| 1982 | 1964 | occluded_view = 1; |
| 1983 | 1965 | |
| 1984 | 1966 | // with SuperScope, sscope_state 0 = left screen OFF, right screen ON |
| 1985 | | if (!(sms_state.sscope_state & 0x01) && (screen == left_lcd)) |
| 1967 | if (!(state->sscope_state & 0x01) && (screen == state->left_lcd)) |
| 1986 | 1968 | occluded_view = 1; |
| 1987 | 1969 | |
| 1988 | 1970 | // with SuperScope, sscope_state 1 = left screen ON, right screen OFF |
| 1989 | | if ((sms_state.sscope_state & 0x01) && (screen == right_lcd)) |
| 1971 | if ((state->sscope_state & 0x01) && (screen == state->right_lcd)) |
| 1990 | 1972 | occluded_view = 1; |
| 1991 | 1973 | |
| 1992 | 1974 | if (!occluded_view) |
| 1993 | 1975 | { |
| 1994 | | sms_vdp_update(smsvdp, bitmap, cliprect); |
| 1976 | sms_vdp_update(state->vdp, bitmap, cliprect); |
| 1995 | 1977 | |
| 1996 | 1978 | // HACK: fake 3D->2D handling (if enabled, it repeats each frame twice on the selected lens) |
| 1997 | 1979 | // save a copy of current bitmap for the binocular hack |
| 1998 | | if (sscope && (screen == left_lcd) && (sscope_binocular_hack & 0x01)) |
| 1999 | | copybitmap(sms_state.prevleft_bitmap, bitmap, 0, 0, 0, 0, cliprect); |
| 2000 | | if (sscope && (screen == right_lcd) && (sscope_binocular_hack & 0x02)) |
| 2001 | | copybitmap(sms_state.prevright_bitmap, bitmap, 0, 0, 0, 0, cliprect); |
| 1980 | if (sscope && (screen == state->left_lcd) && (sscope_binocular_hack & 0x01)) |
| 1981 | copybitmap(state->prevleft_bitmap, bitmap, 0, 0, 0, 0, cliprect); |
| 1982 | if (sscope && (screen == state->right_lcd) && (sscope_binocular_hack & 0x02)) |
| 1983 | copybitmap(state->prevright_bitmap, bitmap, 0, 0, 0, 0, cliprect); |
| 2002 | 1984 | } |
| 2003 | 1985 | else |
| 2004 | 1986 | { |
| r9579 | r9580 | |
| 2006 | 1988 | |
| 2007 | 1989 | // HACK: fake 3D->2D handling (if enabled, it repeats each frame twice on the selected lens) |
| 2008 | 1990 | // use the copied bitmap for the binocular hack |
| 2009 | | if (sscope && (screen == left_lcd) && (sscope_binocular_hack & 0x01)) |
| 2010 | | copybitmap(bitmap, sms_state.prevleft_bitmap, 0, 0, 0, 0, cliprect); |
| 2011 | | if (sscope && (screen == right_lcd) && (sscope_binocular_hack & 0x02)) |
| 2012 | | copybitmap(bitmap, sms_state.prevright_bitmap, 0, 0, 0, 0, cliprect); |
| 1991 | if (sscope && (screen == state->left_lcd) && (sscope_binocular_hack & 0x01)) |
| 1992 | copybitmap(bitmap, state->prevleft_bitmap, 0, 0, 0, 0, cliprect); |
| 1993 | if (sscope && (screen == state->right_lcd) && (sscope_binocular_hack & 0x02)) |
| 1994 | copybitmap(bitmap, state->prevright_bitmap, 0, 0, 0, 0, cliprect); |
| 2013 | 1995 | } |
| 2014 | 1996 | |
| 2015 | 1997 | return 0; |
| r9579 | r9580 | |
| 2017 | 1999 | |
| 2018 | 2000 | VIDEO_UPDATE( sms ) |
| 2019 | 2001 | { |
| 2020 | | running_device *smsvdp = screen->machine->device("sms_vdp"); |
| 2021 | | sms_vdp_update(smsvdp, bitmap, cliprect); |
| 2022 | | |
| 2002 | sms_state *state = screen->machine->driver_data<sms_state>(); |
| 2003 | sms_vdp_update(state->vdp, bitmap, cliprect); |
| 2023 | 2004 | return 0; |
| 2024 | 2005 | } |
| 2025 | 2006 | |
| 2026 | 2007 | VIDEO_START( gamegear ) |
| 2027 | 2008 | { |
| 2009 | sms_state *state = machine->driver_data<sms_state>(); |
| 2028 | 2010 | screen_device *screen = screen_first(*machine); |
| 2029 | 2011 | int width = screen->width(); |
| 2030 | 2012 | int height = screen->height(); |
| 2031 | 2013 | |
| 2032 | | sms_state.prev_bitmap = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED32); |
| 2033 | | sms_state.tmp_bitmap = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED32); |
| 2034 | | state_save_register_global_bitmap(machine, sms_state.prev_bitmap); |
| 2014 | state->prev_bitmap = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED32); |
| 2015 | state->tmp_bitmap = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED32); |
| 2016 | state_save_register_global_bitmap(machine, state->prev_bitmap); |
| 2035 | 2017 | } |
| 2036 | 2018 | |
| 2037 | 2019 | VIDEO_UPDATE( gamegear ) |
| 2038 | 2020 | { |
| 2039 | | running_device *smsvdp = screen->machine->device("sms_vdp"); |
| 2021 | sms_state *state = screen->machine->driver_data<sms_state>(); |
| 2040 | 2022 | int width = screen->width(); |
| 2041 | 2023 | int height = screen->height(); |
| 2042 | 2024 | int x, y; |
| 2043 | 2025 | |
| 2044 | | sms_vdp_update(smsvdp, sms_state.tmp_bitmap, cliprect); |
| 2026 | sms_vdp_update(state->vdp, state->tmp_bitmap, cliprect); |
| 2045 | 2027 | |
| 2046 | 2028 | // HACK: fake LCD persistence effect |
| 2047 | 2029 | // (it would be better to generalized this in the core, to be used for all LCD systems) |
| 2048 | 2030 | for (y = 0; y < height; y++) |
| 2049 | 2031 | { |
| 2050 | | UINT32 *line0 = BITMAP_ADDR32(sms_state.tmp_bitmap, y, 0); |
| 2051 | | UINT32 *line1 = BITMAP_ADDR32(sms_state.prev_bitmap, y, 0); |
| 2032 | UINT32 *line0 = BITMAP_ADDR32(state->tmp_bitmap, y, 0); |
| 2033 | UINT32 *line1 = BITMAP_ADDR32(state->prev_bitmap, y, 0); |
| 2052 | 2034 | for (x = 0; x < width; x++) |
| 2053 | 2035 | { |
| 2054 | 2036 | UINT32 color0 = line0[x]; |
| r9579 | r9580 | |
| 2065 | 2047 | *BITMAP_ADDR32(bitmap, y, x) = (r << 16) | (g << 8) | b; |
| 2066 | 2048 | } |
| 2067 | 2049 | } |
| 2068 | | copybitmap(sms_state.prev_bitmap, sms_state.tmp_bitmap, 0, 0, 0, 0, cliprect); |
| 2050 | copybitmap(state->prev_bitmap, state->tmp_bitmap, 0, 0, 0, 0, cliprect); |
| 2069 | 2051 | |
| 2070 | 2052 | return 0; |
| 2071 | 2053 | } |