trunk/src/mess/machine/sms.c
| r242732 | r242733 | |
| 45 | 45 | |
| 46 | 46 | WRITE_LINE_MEMBER(sms_state::sms_ctrl2_th_input) |
| 47 | 47 | { |
| 48 | | if (m_is_gamegear && (!m_cartslot->exists() || !m_cartslot->m_cart->get_sms_mode())) |
| 48 | if (m_is_gamegear && !(m_cartslot->exists() && m_cartslot->m_cart->get_sms_mode())) |
| 49 | 49 | return; |
| 50 | 50 | |
| 51 | 51 | // Check if TH of controller port 2 is set to input (1) |
| r242732 | r242733 | |
| 68 | 68 | |
| 69 | 69 | void sms_state::sms_get_inputs() |
| 70 | 70 | { |
| 71 | bool port_dd_has_th_input = true; |
| 72 | |
| 71 | 73 | UINT8 data1 = 0xff; |
| 72 | 74 | UINT8 data2 = 0xff; |
| 73 | 75 | |
| r242732 | r242733 | |
| 80 | 82 | |
| 81 | 83 | if (m_is_gamegear) |
| 82 | 84 | { |
| 85 | // Assume the Japanese Game Gear behaves as the |
| 86 | // Japanese Master System, regarding TH input. |
| 87 | if (m_is_gg_region_japan) |
| 88 | port_dd_has_th_input = false; |
| 89 | |
| 90 | // For Game Gear, this function is used only if SMS mode is |
| 91 | // enabled, else only register $dc receives input data, through |
| 92 | // direct read of the m_port_gg_dc I/O port. |
| 93 | |
| 83 | 94 | data1 = m_port_gg_dc->read(); |
| 84 | 95 | m_port_dc_reg &= ~0x03f | data1; |
| 96 | |
| 97 | data2 = m_port_gear2gear->port_r(); |
| 85 | 98 | } |
| 86 | 99 | else |
| 87 | 100 | { |
| 101 | // Sega Mark III does not have TH lines connected. |
| 102 | // The Japanese Master System does not set port $dd with TH input. |
| 103 | if (m_is_mark_iii || m_is_smsj) |
| 104 | port_dd_has_th_input = false; |
| 105 | |
| 88 | 106 | data1 = m_port_ctrl1->port_r(); |
| 89 | 107 | m_port_dc_reg &= ~0x0f | data1; // Up, Down, Left, Right |
| 90 | 108 | m_port_dc_reg &= ~0x10 | (data1 >> 1); // TL (Button 1) |
| 91 | 109 | m_port_dc_reg &= ~0x20 | (data1 >> 2); // TR (Button 2) |
| 92 | | } |
| 93 | 110 | |
| 94 | | if (m_is_gamegear) |
| 95 | | { |
| 96 | | if (m_cartslot->exists() && m_cartslot->m_cart->get_sms_mode()) |
| 97 | | data2 = m_port_gear2gear->port_r(); |
| 98 | | } |
| 99 | | else |
| 100 | | { |
| 101 | 111 | data2 = m_port_ctrl2->port_r(); |
| 102 | 112 | } |
| 113 | |
| 103 | 114 | m_port_dc_reg &= ~0xc0 | (data2 << 6); // Up, Down |
| 104 | 115 | m_port_dd_reg &= ~0x03 | (data2 >> 2); // Left, Right |
| 105 | 116 | m_port_dd_reg &= ~0x04 | (data2 >> 3); // TL (Button 1) |
| 106 | 117 | m_port_dd_reg &= ~0x08 | (data2 >> 4); // TR (Button 2) |
| 107 | 118 | |
| 108 | | // Sega Mark III does not have TH line connected. |
| 109 | | // Also, the Japanese Master System does not set port $dd with TH input. |
| 110 | | if (!m_is_mark_iii && !m_is_smsj) |
| 119 | if (port_dd_has_th_input) |
| 111 | 120 | { |
| 112 | 121 | m_port_dd_reg &= ~0x40 | data1; // TH ctrl1 |
| 113 | 122 | m_port_dd_reg &= ~0x80 | (data2 << 1); // TH ctrl2 |
| r242732 | r242733 | |
| 149 | 158 | UINT8 ctrl1_port_data = 0xff; |
| 150 | 159 | UINT8 ctrl2_port_data = 0xff; |
| 151 | 160 | |
| 152 | | if (m_is_gamegear && (!m_cartslot->exists() || !m_cartslot->m_cart->get_sms_mode())) |
| 161 | if (m_is_gamegear && !(m_cartslot->exists() && m_cartslot->m_cart->get_sms_mode())) |
| 153 | 162 | { |
| 154 | 163 | m_io_ctrl_reg = data; |
| 155 | 164 | return; |
| r242732 | r242733 | |
| 236 | 245 | */ |
| 237 | 246 | WRITE_LINE_MEMBER(sms_state::sms_pause_callback) |
| 238 | 247 | { |
| 239 | | if (m_is_gamegear && m_cartslot->exists() && !m_cartslot->m_cart->get_sms_mode()) |
| 240 | | return; |
| 248 | bool pause_pressed = false; |
| 241 | 249 | |
| 242 | | if ((m_is_gamegear && !(m_port_start->read() & 0x80)) || (!m_is_gamegear && !(m_port_pause->read() & 0x80))) |
| 250 | if (!m_is_mark_iii) |
| 243 | 251 | { |
| 252 | // clear TH latch of the controller ports |
| 253 | m_ctrl1_th_latch = 0; |
| 254 | m_ctrl2_th_latch = 0; |
| 255 | } |
| 256 | |
| 257 | if (m_is_gamegear) |
| 258 | { |
| 259 | if (!(m_cartslot->exists() && m_cartslot->m_cart->get_sms_mode())) |
| 260 | return; |
| 261 | |
| 262 | if (!(m_port_start->read() & 0x80)) |
| 263 | pause_pressed = true; |
| 264 | } |
| 265 | else |
| 266 | { |
| 267 | if (!(m_port_pause->read() & 0x80)) |
| 268 | pause_pressed = true; |
| 269 | } |
| 270 | |
| 271 | if (pause_pressed) |
| 272 | { |
| 244 | 273 | if (!m_paused) |
| 245 | 274 | m_maincpu->set_input_line(INPUT_LINE_NMI, PULSE_LINE); |
| 246 | 275 | |
| r242732 | r242733 | |
| 248 | 277 | } |
| 249 | 278 | else |
| 250 | 279 | m_paused = 0; |
| 251 | | |
| 252 | | if (!m_is_mark_iii) |
| 253 | | { |
| 254 | | // clear TH latch of the controller ports |
| 255 | | m_ctrl1_th_latch = 0; |
| 256 | | m_ctrl2_th_latch = 0; |
| 257 | | } |
| 258 | 280 | } |
| 259 | 281 | |
| 260 | 282 | |
| r242732 | r242733 | |
| 266 | 288 | return m_port_dc_reg; |
| 267 | 289 | } |
| 268 | 290 | |
| 269 | | if (!m_is_gamegear && (m_mem_ctrl_reg & IO_CHIP)) |
| 291 | if (m_is_gamegear) |
| 270 | 292 | { |
| 271 | | return 0xff; |
| 293 | // If SMS mode is disabled, just return the data read from the |
| 294 | // input port. Its mapped port bits match the bits of register $dc. |
| 295 | if (!(m_cartslot->exists() && m_cartslot->m_cart->get_sms_mode())) |
| 296 | return m_port_gg_dc->read(); |
| 272 | 297 | } |
| 273 | 298 | else |
| 274 | 299 | { |
| 275 | | sms_get_inputs(); |
| 300 | // Return if the I/O chip is disabled (1). This check isn't performed |
| 301 | // for the Game Gear because has no effect on it (even in SMS mode?). |
| 302 | if (m_mem_ctrl_reg & IO_CHIP) |
| 303 | return 0xff; |
| 304 | } |
| 276 | 305 | |
| 277 | | // Check if TR of controller port 1 is set to output (0) |
| 278 | | if (!(m_io_ctrl_reg & 0x01)) |
| 279 | | { |
| 280 | | // Read TR state set through IO control port |
| 281 | | m_port_dc_reg &= ~0x20 | ((m_io_ctrl_reg & 0x10) << 1); |
| 282 | | } |
| 306 | sms_get_inputs(); |
| 283 | 307 | |
| 284 | | return m_port_dc_reg; |
| 308 | // Check if TR of controller port 1 is set to output (0) |
| 309 | if (!(m_io_ctrl_reg & 0x01)) |
| 310 | { |
| 311 | // Read TR state set through IO control port |
| 312 | m_port_dc_reg &= ~0x20 | ((m_io_ctrl_reg & 0x10) << 1); |
| 285 | 313 | } |
| 314 | |
| 315 | return m_port_dc_reg; |
| 286 | 316 | } |
| 287 | 317 | |
| 288 | 318 | |
| r242732 | r242733 | |
| 294 | 324 | return m_port_dd_reg; |
| 295 | 325 | } |
| 296 | 326 | |
| 297 | | if (!m_is_gamegear && (m_mem_ctrl_reg & IO_CHIP)) |
| 298 | | return 0xff; |
| 327 | if (m_is_gamegear) |
| 328 | { |
| 329 | if (!(m_cartslot->exists() && m_cartslot->m_cart->get_sms_mode())) |
| 330 | return 0xff; |
| 331 | } |
| 332 | else |
| 333 | { |
| 334 | // Return if the I/O chip is disabled (1). This check isn't performed |
| 335 | // for the Game Gear because has no effect on it (even in SMS mode?). |
| 336 | if (m_mem_ctrl_reg & IO_CHIP) |
| 337 | return 0xff; |
| 338 | } |
| 299 | 339 | |
| 300 | 340 | sms_get_inputs(); |
| 301 | 341 | |
| r242732 | r242733 | |
| 377 | 417 | } |
| 378 | 418 | |
| 379 | 419 | |
| 380 | | READ8_MEMBER(sms_state::gg_input_port_2_r) |
| 420 | READ8_MEMBER(sms_state::gg_input_port_00_r) |
| 381 | 421 | { |
| 382 | | //logerror("joy 2 read, val: %02x, pc: %04x\n", (m_is_gg_region_japan ? 0x00 : 0x40) | (m_port_start->read() & 0x80), activecpu_get_pc()); |
| 383 | | return (m_is_gg_region_japan ? 0x00 : 0x40) | (m_port_start->read() & 0x80); |
| 422 | if (m_cartslot->exists() && m_cartslot->m_cart->get_sms_mode()) |
| 423 | return 0xff; |
| 424 | else |
| 425 | { |
| 426 | UINT8 data = (m_is_gg_region_japan ? 0x00 : 0x40) | (m_port_start->read() & 0x80); |
| 427 | |
| 428 | //logerror("port $00 read, val: %02x, pc: %04x\n", data, activecpu_get_pc()); |
| 429 | return data; |
| 430 | } |
| 384 | 431 | } |
| 385 | 432 | |
| 386 | 433 | |