trunk/src/emu/cpu/psx/psx.c
| r18804 | r18805 | |
| 1532 | 1532 | /* 1f801018 dv delay */ |
| 1533 | 1533 | AM_RANGE(0x1f801020, 0x1f801023) AM_READWRITE_LEGACY( psx_com_delay_r, psx_com_delay_w ) |
| 1534 | 1534 | AM_RANGE(0x1f801024, 0x1f80102f) AM_RAM |
| 1535 | | AM_RANGE(0x1f801040, 0x1f80105f) AM_DEVREADWRITE( "sio", psxsio_device, read, write ) |
| 1535 | AM_RANGE(0x1f801040, 0x1f80104f) AM_DEVREADWRITE( "sio0", psxsio_device, read, write ) |
| 1536 | AM_RANGE(0x1f801050, 0x1f80105f) AM_DEVREADWRITE( "sio1", psxsio_device, read, write ) |
| 1536 | 1537 | /* 1f801060 ram config */ |
| 1537 | 1538 | AM_RANGE(0x1f801060, 0x1f80106f) AM_RAM |
| 1538 | 1539 | AM_RANGE(0x1f801070, 0x1f801077) AM_DEVREADWRITE( "irq", psxirq_device, read, write ) |
| r18804 | r18805 | |
| 1560 | 1561 | AM_RANGE(0x1f801000, 0x1f80101f) AM_RAM |
| 1561 | 1562 | AM_RANGE(0x1f801020, 0x1f801023) AM_READWRITE_LEGACY( psx_com_delay_r, psx_com_delay_w ) |
| 1562 | 1563 | AM_RANGE(0x1f801024, 0x1f80102f) AM_RAM |
| 1563 | | AM_RANGE(0x1f801040, 0x1f80105f) AM_DEVREADWRITE( "sio", psxsio_device, read, write ) |
| 1564 | AM_RANGE(0x1f801040, 0x1f80104f) AM_DEVREADWRITE( "sio0", psxsio_device, read, write ) |
| 1565 | AM_RANGE(0x1f801050, 0x1f80105f) AM_DEVREADWRITE( "sio1", psxsio_device, read, write ) |
| 1564 | 1566 | AM_RANGE(0x1f801060, 0x1f80106f) AM_RAM |
| 1565 | 1567 | AM_RANGE(0x1f801070, 0x1f801077) AM_DEVREADWRITE( "irq", psxirq_device, read, write ) |
| 1566 | 1568 | AM_RANGE(0x1f801080, 0x1f8010ff) AM_DEVREADWRITE( "dma", psxdma_device, read, write ) |
| r18804 | r18805 | |
| 3167 | 3169 | |
| 3168 | 3170 | void psxcpu_device::install_sio_handler( device_t &device, const char *cputag, int n_port, psx_sio_handler p_f_sio_handler ) |
| 3169 | 3171 | { |
| 3170 | | psxsio_device *sio = getcpu( device, cputag )->subdevice<psxsio_device>("sio"); |
| 3171 | | sio->install_handler( n_port, p_f_sio_handler ); |
| 3172 | psxsio_device *sio; |
| 3173 | |
| 3174 | switch( n_port ) |
| 3175 | { |
| 3176 | case 0: |
| 3177 | sio = getcpu( device, cputag )->subdevice<psxsio_device>("sio0"); |
| 3178 | break; |
| 3179 | case 1: |
| 3180 | sio = getcpu( device, cputag )->subdevice<psxsio_device>("sio1"); |
| 3181 | break; |
| 3182 | default: |
| 3183 | return; |
| 3184 | } |
| 3185 | |
| 3186 | sio->install_handler( p_f_sio_handler ); |
| 3172 | 3187 | } |
| 3173 | 3188 | |
| 3174 | 3189 | void psxcpu_device::sio_input( device_t &device, const char *cputag, int n_port, int n_mask, int n_data ) |
| 3175 | 3190 | { |
| 3176 | | psxsio_device *sio = getcpu( device, cputag )->subdevice<psxsio_device>("sio"); |
| 3177 | | sio->input( n_port, n_mask, n_data ); |
| 3191 | psxsio_device *sio; |
| 3192 | |
| 3193 | switch( n_port ) |
| 3194 | { |
| 3195 | case 0: |
| 3196 | sio = getcpu( device, cputag )->subdevice<psxsio_device>("sio0"); |
| 3197 | break; |
| 3198 | case 1: |
| 3199 | sio = getcpu( device, cputag )->subdevice<psxsio_device>("sio1"); |
| 3200 | break; |
| 3201 | default: |
| 3202 | return; |
| 3203 | } |
| 3204 | |
| 3205 | sio->input( n_mask, n_data ); |
| 3178 | 3206 | } |
| 3179 | 3207 | |
| 3180 | 3208 | READ32_HANDLER( psxcpu_device::gpu_r ) |
| r18804 | r18805 | |
| 3203 | 3231 | MCFG_PSX_RCNT_IRQ1_HANDLER(DEVWRITELINE("irq", psxirq_device, intin5)) |
| 3204 | 3232 | MCFG_PSX_RCNT_IRQ2_HANDLER(DEVWRITELINE("irq", psxirq_device, intin6)) |
| 3205 | 3233 | |
| 3206 | | MCFG_DEVICE_ADD("sio", PSX_SIO, 0) |
| 3207 | | MCFG_PSX_SIO_IRQ0_HANDLER(DEVWRITELINE("irq", psxirq_device, intin7)) |
| 3208 | | MCFG_PSX_SIO_IRQ1_HANDLER(DEVWRITELINE("irq", psxirq_device, intin8)) |
| 3234 | MCFG_DEVICE_ADD("sio0", PSX_SIO0, 0) |
| 3235 | MCFG_PSX_SIO_IRQ_HANDLER(DEVWRITELINE("irq", psxirq_device, intin7)) |
| 3236 | |
| 3237 | MCFG_DEVICE_ADD("sio1", PSX_SIO1, 0) |
| 3238 | MCFG_PSX_SIO_IRQ_HANDLER(DEVWRITELINE("irq", psxirq_device, intin8)) |
| 3209 | 3239 | MACHINE_CONFIG_END |
| 3210 | 3240 | |
| 3211 | 3241 | //------------------------------------------------- |
trunk/src/emu/cpu/psx/sio.c
| r18804 | r18805 | |
| 23 | 23 | } |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | | const device_type PSX_SIO = &device_creator<psxsio_device>; |
| 26 | const device_type PSX_SIO0 = &device_creator<psxsio0_device>; |
| 27 | const device_type PSX_SIO1 = &device_creator<psxsio1_device>; |
| 27 | 28 | |
| 28 | | psxsio_device::psxsio_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : |
| 29 | | device_t(mconfig, PSX_SIO, "PSX SIO", tag, owner, clock), |
| 30 | | m_irq0_handler(*this), |
| 31 | | m_irq1_handler(*this) |
| 29 | psxsio0_device::psxsio0_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : |
| 30 | psxsio_device(mconfig, PSX_SIO0, tag, owner, clock) |
| 32 | 31 | { |
| 33 | | int n; |
| 32 | } |
| 34 | 33 | |
| 35 | | for( n = 0; n < 2; n++ ) |
| 36 | | { |
| 37 | | port[ n ].fn_handler = NULL; |
| 38 | | } |
| 34 | psxsio1_device::psxsio1_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : |
| 35 | psxsio_device(mconfig, PSX_SIO1, tag, owner, clock) |
| 36 | { |
| 39 | 37 | } |
| 40 | 38 | |
| 41 | | void psxsio_device::device_reset() |
| 39 | psxsio_device::psxsio_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, UINT32 clock) : |
| 40 | device_t(mconfig, type, "PSX SIO", tag, owner, clock), |
| 41 | m_fn_handler(NULL), |
| 42 | m_irq_handler(*this) |
| 42 | 43 | { |
| 43 | 44 | } |
| 44 | 45 | |
| 45 | 46 | void psxsio_device::device_post_load() |
| 46 | 47 | { |
| 47 | | int n; |
| 48 | | |
| 49 | | for( n = 0; n < 2; n++ ) |
| 50 | | { |
| 51 | | sio_timer_adjust( n ); |
| 52 | | } |
| 48 | sio_timer_adjust(); |
| 53 | 49 | } |
| 54 | 50 | |
| 55 | 51 | void psxsio_device::device_start() |
| 56 | 52 | { |
| 57 | | int n; |
| 53 | m_irq_handler.resolve_safe(); |
| 58 | 54 | |
| 59 | | m_irq0_handler.resolve_safe(); |
| 60 | | m_irq1_handler.resolve_safe(); |
| 55 | m_timer = timer_alloc( 0 ); |
| 56 | m_status = SIO_STATUS_TX_EMPTY | SIO_STATUS_TX_RDY; |
| 57 | m_mode = 0; |
| 58 | m_control = 0; |
| 59 | m_baud = 0; |
| 60 | m_tx = 0; |
| 61 | m_rx = 0; |
| 62 | m_tx_prev = 0; |
| 63 | m_rx_prev = 0; |
| 64 | m_rx_data = 0; |
| 65 | m_tx_data = 0; |
| 66 | m_rx_shift = 0; |
| 67 | m_tx_shift = 0; |
| 68 | m_rx_bits = 0; |
| 69 | m_tx_bits = 0; |
| 61 | 70 | |
| 62 | | for( n = 0; n < 2; n++ ) |
| 63 | | { |
| 64 | | port[ n ].timer = machine().scheduler().timer_alloc( timer_expired_delegate( FUNC( psxsio_device::sio_clock ), this ) ); |
| 65 | | port[ n ].n_status = SIO_STATUS_TX_EMPTY | SIO_STATUS_TX_RDY; |
| 66 | | port[ n ].n_mode = 0; |
| 67 | | port[ n ].n_control = 0; |
| 68 | | port[ n ].n_baud = 0; |
| 69 | | port[ n ].n_tx = 0; |
| 70 | | port[ n ].n_rx = 0; |
| 71 | | port[ n ].n_tx_prev = 0; |
| 72 | | port[ n ].n_rx_prev = 0; |
| 73 | | port[ n ].n_rx_data = 0; |
| 74 | | port[ n ].n_tx_data = 0; |
| 75 | | port[ n ].n_rx_shift = 0; |
| 76 | | port[ n ].n_tx_shift = 0; |
| 77 | | port[ n ].n_rx_bits = 0; |
| 78 | | port[ n ].n_tx_bits = 0; |
| 79 | | } |
| 80 | | |
| 81 | | for( n = 0; n < 2; n++ ) |
| 82 | | { |
| 83 | | state_save_register_item( machine(), "psxsio", NULL, n, port[n].n_status ); |
| 84 | | state_save_register_item( machine(), "psxsio", NULL, n, port[n].n_mode ); |
| 85 | | state_save_register_item( machine(), "psxsio", NULL, n, port[n].n_control ); |
| 86 | | state_save_register_item( machine(), "psxsio", NULL, n, port[n].n_baud ); |
| 87 | | state_save_register_item( machine(), "psxsio", NULL, n, port[n].n_tx ); |
| 88 | | state_save_register_item( machine(), "psxsio", NULL, n, port[n].n_rx ); |
| 89 | | state_save_register_item( machine(), "psxsio", NULL, n, port[n].n_tx_prev ); |
| 90 | | state_save_register_item( machine(), "psxsio", NULL, n, port[n].n_rx_prev ); |
| 91 | | state_save_register_item( machine(), "psxsio", NULL, n, port[n].n_rx_data ); |
| 92 | | state_save_register_item( machine(), "psxsio", NULL, n, port[n].n_tx_data ); |
| 93 | | state_save_register_item( machine(), "psxsio", NULL, n, port[n].n_rx_shift ); |
| 94 | | state_save_register_item( machine(), "psxsio", NULL, n, port[n].n_tx_shift ); |
| 95 | | state_save_register_item( machine(), "psxsio", NULL, n, port[n].n_rx_bits ); |
| 96 | | state_save_register_item( machine(), "psxsio", NULL, n, port[n].n_tx_bits ); |
| 97 | | } |
| 71 | save_item( NAME( m_status ) ); |
| 72 | save_item( NAME( m_mode ) ); |
| 73 | save_item( NAME( m_control ) ); |
| 74 | save_item( NAME( m_baud ) ); |
| 75 | save_item( NAME( m_tx ) ); |
| 76 | save_item( NAME( m_rx ) ); |
| 77 | save_item( NAME( m_tx_prev ) ); |
| 78 | save_item( NAME( m_rx_prev ) ); |
| 79 | save_item( NAME( m_rx_data ) ); |
| 80 | save_item( NAME( m_tx_data ) ); |
| 81 | save_item( NAME( m_rx_shift ) ); |
| 82 | save_item( NAME( m_tx_shift ) ); |
| 83 | save_item( NAME( m_rx_bits ) ); |
| 84 | save_item( NAME( m_tx_bits ) ); |
| 98 | 85 | } |
| 99 | 86 | |
| 100 | | void psxsio_device::install_handler( int n_port, psx_sio_handler p_f_sio_handler ) |
| 87 | void psxsio_device::install_handler( psx_sio_handler p_f_sio_handler ) |
| 101 | 88 | { |
| 102 | | port[ n_port ].fn_handler = p_f_sio_handler; |
| 89 | m_fn_handler = p_f_sio_handler; |
| 103 | 90 | } |
| 104 | 91 | |
| 105 | | void psxsio_device::sio_interrupt( int n_port ) |
| 92 | void psxsio_device::sio_interrupt() |
| 106 | 93 | { |
| 107 | | psx_sio *sio = &port[ n_port ]; |
| 108 | | |
| 109 | | verboselog( machine(), 1, "sio_interrupt( %d )\n", n_port ); |
| 110 | | sio->n_status |= SIO_STATUS_IRQ; |
| 111 | | if( n_port == 0 ) |
| 112 | | { |
| 113 | | m_irq0_handler(1); |
| 114 | | } |
| 115 | | else |
| 116 | | { |
| 117 | | m_irq1_handler(1); |
| 118 | | } |
| 94 | verboselog( machine(), 1, "sio_interrupt( %s )\n", tag() ); |
| 95 | m_status |= SIO_STATUS_IRQ; |
| 96 | m_irq_handler(1); |
| 119 | 97 | } |
| 120 | 98 | |
| 121 | | void psxsio_device::sio_timer_adjust( int n_port ) |
| 99 | void psxsio_device::sio_timer_adjust() |
| 122 | 100 | { |
| 123 | | psx_sio *sio = &port[ n_port ]; |
| 124 | 101 | attotime n_time; |
| 125 | 102 | |
| 126 | | if( ( sio->n_status & SIO_STATUS_TX_EMPTY ) == 0 || sio->n_tx_bits != 0 ) |
| 103 | if( ( m_status & SIO_STATUS_TX_EMPTY ) == 0 || m_tx_bits != 0 ) |
| 127 | 104 | { |
| 128 | 105 | int n_prescaler; |
| 129 | 106 | |
| 130 | | switch( sio->n_mode & 3 ) |
| 107 | switch( m_mode & 3 ) |
| 131 | 108 | { |
| 132 | 109 | case 1: |
| 133 | 110 | n_prescaler = 1; |
| r18804 | r18805 | |
| 143 | 120 | break; |
| 144 | 121 | } |
| 145 | 122 | |
| 146 | | if( sio->n_baud != 0 && n_prescaler != 0 ) |
| 123 | if( m_baud != 0 && n_prescaler != 0 ) |
| 147 | 124 | { |
| 148 | | n_time = attotime::from_hz(33868800) * (n_prescaler * sio->n_baud); |
| 149 | | verboselog( machine(), 2, "sio_timer_adjust( %d ) = %s ( %d x %d )\n", n_port, n_time.as_string(), n_prescaler, sio->n_baud ); |
| 125 | n_time = attotime::from_hz(33868800) * (n_prescaler * m_baud); |
| 126 | verboselog( machine(), 2, "sio_timer_adjust( %s ) = %s ( %d x %d )\n", tag(), n_time.as_string(), n_prescaler, m_baud ); |
| 150 | 127 | } |
| 151 | 128 | else |
| 152 | 129 | { |
| 153 | 130 | n_time = attotime::never; |
| 154 | | verboselog( machine(), 0, "sio_timer_adjust( %d ) invalid baud rate ( %d x %d )\n", n_port, n_prescaler, sio->n_baud ); |
| 131 | verboselog( machine(), 0, "sio_timer_adjust( %s ) invalid baud rate ( %d x %d )\n", tag(), n_prescaler, m_baud ); |
| 155 | 132 | } |
| 156 | 133 | } |
| 157 | 134 | else |
| 158 | 135 | { |
| 159 | 136 | n_time = attotime::never; |
| 160 | | verboselog( machine(), 2, "sio_timer_adjust( %d ) finished\n", n_port ); |
| 137 | verboselog( machine(), 2, "sio_timer_adjust( %s ) finished\n", tag() ); |
| 161 | 138 | } |
| 162 | | sio->timer->adjust( n_time, n_port); |
| 139 | |
| 140 | m_timer->adjust( n_time ); |
| 163 | 141 | } |
| 164 | 142 | |
| 165 | | TIMER_CALLBACK_MEMBER(psxsio_device::sio_clock) |
| 143 | void psxsio_device::device_timer(emu_timer &timer, device_timer_id tid, int param, void *ptr) |
| 166 | 144 | { |
| 167 | | int n_port = param; |
| 168 | | psx_sio *sio = &port[ n_port ]; |
| 169 | 145 | verboselog( machine(), 2, "sio tick\n" ); |
| 170 | 146 | |
| 171 | | if( sio->n_tx_bits == 0 && |
| 172 | | ( sio->n_control & SIO_CONTROL_TX_ENA ) != 0 && |
| 173 | | ( sio->n_status & SIO_STATUS_TX_EMPTY ) == 0 ) |
| 147 | if( m_tx_bits == 0 && |
| 148 | ( m_control & SIO_CONTROL_TX_ENA ) != 0 && |
| 149 | ( m_status & SIO_STATUS_TX_EMPTY ) == 0 ) |
| 174 | 150 | { |
| 175 | | sio->n_tx_bits = 8; |
| 176 | | sio->n_tx_shift = sio->n_tx_data; |
| 177 | | if( n_port == 0 ) |
| 151 | m_tx_bits = 8; |
| 152 | m_tx_shift = m_tx_data; |
| 153 | |
| 154 | if( type() == PSX_SIO0 ) |
| 178 | 155 | { |
| 179 | | sio->n_rx_bits = 8; |
| 180 | | sio->n_rx_shift = 0; |
| 156 | m_rx_bits = 8; |
| 157 | m_rx_shift = 0; |
| 181 | 158 | } |
| 182 | | sio->n_status |= SIO_STATUS_TX_EMPTY; |
| 183 | | sio->n_status |= SIO_STATUS_TX_RDY; |
| 159 | |
| 160 | m_status |= SIO_STATUS_TX_EMPTY; |
| 161 | m_status |= SIO_STATUS_TX_RDY; |
| 184 | 162 | } |
| 185 | 163 | |
| 186 | | if( sio->n_tx_bits != 0 ) |
| 164 | if( m_tx_bits != 0 ) |
| 187 | 165 | { |
| 188 | | sio->n_tx = ( sio->n_tx & ~PSX_SIO_OUT_DATA ) | ( ( sio->n_tx_shift & 1 ) * PSX_SIO_OUT_DATA ); |
| 189 | | sio->n_tx_shift >>= 1; |
| 190 | | sio->n_tx_bits--; |
| 166 | m_tx = ( m_tx & ~PSX_SIO_OUT_DATA ) | ( ( m_tx_shift & 1 ) * PSX_SIO_OUT_DATA ); |
| 167 | m_tx_shift >>= 1; |
| 168 | m_tx_bits--; |
| 191 | 169 | |
| 192 | | if( sio->fn_handler != NULL ) |
| 170 | if( m_fn_handler != NULL ) |
| 193 | 171 | { |
| 194 | | if( n_port == 0 ) |
| 172 | if( type() == PSX_SIO0 ) |
| 195 | 173 | { |
| 196 | | sio->n_tx &= ~PSX_SIO_OUT_CLOCK; |
| 197 | | (*sio->fn_handler)( machine(), sio->n_tx ); |
| 198 | | sio->n_tx |= PSX_SIO_OUT_CLOCK; |
| 174 | m_tx &= ~PSX_SIO_OUT_CLOCK; |
| 175 | (*m_fn_handler)( machine(), m_tx ); |
| 176 | m_tx |= PSX_SIO_OUT_CLOCK; |
| 199 | 177 | } |
| 200 | | (*sio->fn_handler)( machine(), sio->n_tx ); |
| 178 | |
| 179 | (*m_fn_handler)( machine(), m_tx ); |
| 201 | 180 | } |
| 202 | 181 | |
| 203 | | if( sio->n_tx_bits == 0 && |
| 204 | | ( sio->n_control & SIO_CONTROL_TX_IENA ) != 0 ) |
| 182 | if( m_tx_bits == 0 && |
| 183 | ( m_control & SIO_CONTROL_TX_IENA ) != 0 ) |
| 205 | 184 | { |
| 206 | | sio_interrupt( n_port ); |
| 185 | sio_interrupt(); |
| 207 | 186 | } |
| 208 | 187 | } |
| 209 | 188 | |
| 210 | | if( sio->n_rx_bits != 0 ) |
| 189 | if( m_rx_bits != 0 ) |
| 211 | 190 | { |
| 212 | | sio->n_rx_shift = ( sio->n_rx_shift >> 1 ) | ( ( ( sio->n_rx & PSX_SIO_IN_DATA ) / PSX_SIO_IN_DATA ) << 7 ); |
| 213 | | sio->n_rx_bits--; |
| 191 | m_rx_shift = ( m_rx_shift >> 1 ) | ( ( ( m_rx & PSX_SIO_IN_DATA ) / PSX_SIO_IN_DATA ) << 7 ); |
| 192 | m_rx_bits--; |
| 214 | 193 | |
| 215 | | if( sio->n_rx_bits == 0 ) |
| 194 | if( m_rx_bits == 0 ) |
| 216 | 195 | { |
| 217 | | if( ( sio->n_status & SIO_STATUS_RX_RDY ) != 0 ) |
| 196 | if( ( m_status & SIO_STATUS_RX_RDY ) != 0 ) |
| 218 | 197 | { |
| 219 | | sio->n_status |= SIO_STATUS_OVERRUN; |
| 198 | m_status |= SIO_STATUS_OVERRUN; |
| 220 | 199 | } |
| 221 | 200 | else |
| 222 | 201 | { |
| 223 | | sio->n_rx_data = sio->n_rx_shift; |
| 224 | | sio->n_status |= SIO_STATUS_RX_RDY; |
| 202 | m_rx_data = m_rx_shift; |
| 203 | m_status |= SIO_STATUS_RX_RDY; |
| 225 | 204 | } |
| 226 | | if( ( sio->n_control & SIO_CONTROL_RX_IENA ) != 0 ) |
| 205 | |
| 206 | if( ( m_control & SIO_CONTROL_RX_IENA ) != 0 ) |
| 227 | 207 | { |
| 228 | | sio_interrupt( n_port ); |
| 208 | sio_interrupt(); |
| 229 | 209 | } |
| 230 | 210 | } |
| 231 | 211 | } |
| 232 | 212 | |
| 233 | | sio_timer_adjust( n_port ); |
| 213 | sio_timer_adjust(); |
| 234 | 214 | } |
| 235 | 215 | |
| 236 | 216 | WRITE32_MEMBER( psxsio_device::write ) |
| 237 | 217 | { |
| 238 | | int n_port = offset / 4; |
| 239 | | psx_sio *sio = &port[ n_port ]; |
| 240 | | |
| 241 | 218 | switch( offset % 4 ) |
| 242 | 219 | { |
| 243 | 220 | case 0: |
| 244 | | verboselog( machine(), 1, "psx_sio_w %d data %02x (%08x)\n", n_port, data, mem_mask ); |
| 245 | | sio->n_tx_data = data; |
| 246 | | sio->n_status &= ~( SIO_STATUS_TX_RDY ); |
| 247 | | sio->n_status &= ~( SIO_STATUS_TX_EMPTY ); |
| 248 | | sio_timer_adjust( n_port ); |
| 221 | verboselog( machine(), 1, "psx_sio_w %s data %02x (%08x)\n", tag(), data, mem_mask ); |
| 222 | m_tx_data = data; |
| 223 | m_status &= ~( SIO_STATUS_TX_RDY ); |
| 224 | m_status &= ~( SIO_STATUS_TX_EMPTY ); |
| 225 | sio_timer_adjust(); |
| 249 | 226 | break; |
| 250 | 227 | case 1: |
| 251 | 228 | verboselog( machine(), 0, "psx_sio_w( %08x, %08x, %08x )\n", offset, data, mem_mask ); |
| r18804 | r18805 | |
| 253 | 230 | case 2: |
| 254 | 231 | if( ACCESSING_BITS_0_15 ) |
| 255 | 232 | { |
| 256 | | sio->n_mode = data & 0xffff; |
| 257 | | verboselog( machine(), 1, "psx_sio_w %d mode %04x\n", n_port, data & 0xffff ); |
| 233 | m_mode = data & 0xffff; |
| 234 | verboselog( machine(), 1, "psx_sio_w %s mode %04x\n", tag(), data & 0xffff ); |
| 258 | 235 | } |
| 259 | 236 | if( ACCESSING_BITS_16_31 ) |
| 260 | 237 | { |
| 261 | | verboselog( machine(), 1, "psx_sio_w %d control %04x\n", n_port, data >> 16 ); |
| 262 | | sio->n_control = data >> 16; |
| 238 | verboselog( machine(), 1, "psx_sio_w %s control %04x\n", tag(), data >> 16 ); |
| 239 | m_control = data >> 16; |
| 263 | 240 | |
| 264 | | if( ( sio->n_control & SIO_CONTROL_RESET ) != 0 ) |
| 241 | if( ( m_control & SIO_CONTROL_RESET ) != 0 ) |
| 265 | 242 | { |
| 266 | 243 | verboselog( machine(), 1, "psx_sio_w reset\n" ); |
| 267 | | sio->n_status |= SIO_STATUS_TX_EMPTY | SIO_STATUS_TX_RDY; |
| 268 | | sio->n_status &= ~( SIO_STATUS_RX_RDY | SIO_STATUS_OVERRUN | SIO_STATUS_IRQ ); |
| 244 | m_status |= SIO_STATUS_TX_EMPTY | SIO_STATUS_TX_RDY; |
| 245 | m_status &= ~( SIO_STATUS_RX_RDY | SIO_STATUS_OVERRUN | SIO_STATUS_IRQ ); |
| 269 | 246 | } |
| 270 | | if( ( sio->n_control & SIO_CONTROL_IACK ) != 0 ) |
| 247 | if( ( m_control & SIO_CONTROL_IACK ) != 0 ) |
| 271 | 248 | { |
| 272 | 249 | verboselog( machine(), 1, "psx_sio_w iack\n" ); |
| 273 | | sio->n_status &= ~( SIO_STATUS_IRQ ); |
| 274 | | sio->n_control &= ~( SIO_CONTROL_IACK ); |
| 250 | m_status &= ~( SIO_STATUS_IRQ ); |
| 251 | m_control &= ~( SIO_CONTROL_IACK ); |
| 275 | 252 | } |
| 276 | | if( ( sio->n_control & SIO_CONTROL_DTR ) != 0 ) |
| 253 | if( ( m_control & SIO_CONTROL_DTR ) != 0 ) |
| 277 | 254 | { |
| 278 | | sio->n_tx |= PSX_SIO_OUT_DTR; |
| 255 | m_tx |= PSX_SIO_OUT_DTR; |
| 279 | 256 | } |
| 280 | 257 | else |
| 281 | 258 | { |
| 282 | | sio->n_tx &= ~PSX_SIO_OUT_DTR; |
| 259 | m_tx &= ~PSX_SIO_OUT_DTR; |
| 283 | 260 | } |
| 284 | 261 | |
| 285 | | if( ( ( sio->n_tx ^ sio->n_tx_prev ) & PSX_SIO_OUT_DTR ) != 0 ) |
| 262 | if( ( ( m_tx ^ m_tx_prev ) & PSX_SIO_OUT_DTR ) != 0 ) |
| 286 | 263 | { |
| 287 | | if( sio->fn_handler != NULL ) |
| 264 | if( m_fn_handler != NULL ) |
| 288 | 265 | { |
| 289 | | (*sio->fn_handler)( machine(), sio->n_tx ); |
| 266 | (*m_fn_handler)( machine(), m_tx ); |
| 290 | 267 | } |
| 291 | 268 | } |
| 292 | | sio->n_tx_prev = sio->n_tx; |
| 293 | 269 | |
| 270 | m_tx_prev = m_tx; |
| 271 | |
| 294 | 272 | } |
| 295 | 273 | break; |
| 296 | 274 | case 3: |
| r18804 | r18805 | |
| 300 | 278 | } |
| 301 | 279 | if( ACCESSING_BITS_16_31 ) |
| 302 | 280 | { |
| 303 | | sio->n_baud = data >> 16; |
| 304 | | verboselog( machine(), 1, "psx_sio_w %d baud %04x\n", n_port, data >> 16 ); |
| 281 | m_baud = data >> 16; |
| 282 | verboselog( machine(), 1, "psx_sio_w %s baud %04x\n", tag(), data >> 16 ); |
| 305 | 283 | } |
| 306 | 284 | break; |
| 307 | 285 | default: |
| r18804 | r18805 | |
| 312 | 290 | |
| 313 | 291 | READ32_MEMBER( psxsio_device::read ) |
| 314 | 292 | { |
| 315 | | int n_port = offset / 4; |
| 316 | | psx_sio *sio = &port[ n_port ]; |
| 317 | 293 | UINT32 data; |
| 318 | 294 | |
| 319 | 295 | switch( offset % 4 ) |
| 320 | 296 | { |
| 321 | 297 | case 0: |
| 322 | | data = sio->n_rx_data; |
| 323 | | sio->n_status &= ~( SIO_STATUS_RX_RDY ); |
| 324 | | sio->n_rx_data = 0xff; |
| 325 | | verboselog( machine(), 1, "psx_sio_r %d data %02x (%08x)\n", n_port, data, mem_mask ); |
| 298 | data = m_rx_data; |
| 299 | m_status &= ~( SIO_STATUS_RX_RDY ); |
| 300 | m_rx_data = 0xff; |
| 301 | verboselog( machine(), 1, "psx_sio_r %s data %02x (%08x)\n", tag(), data, mem_mask ); |
| 326 | 302 | break; |
| 327 | 303 | case 1: |
| 328 | | data = sio->n_status; |
| 304 | data = m_status; |
| 329 | 305 | if( ACCESSING_BITS_0_15 ) |
| 330 | 306 | { |
| 331 | | verboselog( machine(), 1, "psx_sio_r %d status %04x\n", n_port, data & 0xffff ); |
| 307 | verboselog( machine(), 1, "psx_sio_r %s status %04x\n", tag(), data & 0xffff ); |
| 332 | 308 | } |
| 333 | 309 | if( ACCESSING_BITS_16_31 ) |
| 334 | 310 | { |
| r18804 | r18805 | |
| 336 | 312 | } |
| 337 | 313 | break; |
| 338 | 314 | case 2: |
| 339 | | data = ( sio->n_control << 16 ) | sio->n_mode; |
| 315 | data = ( m_control << 16 ) | m_mode; |
| 340 | 316 | if( ACCESSING_BITS_0_15 ) |
| 341 | 317 | { |
| 342 | | verboselog( machine(), 1, "psx_sio_r %d mode %04x\n", n_port, data & 0xffff ); |
| 318 | verboselog( machine(), 1, "psx_sio_r %s mode %04x\n", tag(), data & 0xffff ); |
| 343 | 319 | } |
| 344 | 320 | if( ACCESSING_BITS_16_31 ) |
| 345 | 321 | { |
| 346 | | verboselog( machine(), 1, "psx_sio_r %d control %04x\n", n_port, data >> 16 ); |
| 322 | verboselog( machine(), 1, "psx_sio_r %s control %04x\n", tag(), data >> 16 ); |
| 347 | 323 | } |
| 348 | 324 | break; |
| 349 | 325 | case 3: |
| 350 | | data = sio->n_baud << 16; |
| 326 | data = m_baud << 16; |
| 351 | 327 | if( ACCESSING_BITS_0_15 ) |
| 352 | 328 | { |
| 353 | 329 | verboselog( machine(), 0, "psx_sio_r( %08x, %08x ) %08x\n", offset, mem_mask, data ); |
| 354 | 330 | } |
| 355 | 331 | if( ACCESSING_BITS_16_31 ) |
| 356 | 332 | { |
| 357 | | verboselog( machine(), 1, "psx_sio_r %d baud %04x\n", n_port, data >> 16 ); |
| 333 | verboselog( machine(), 1, "psx_sio_r %s baud %04x\n", tag(), data >> 16 ); |
| 358 | 334 | } |
| 359 | 335 | break; |
| 360 | 336 | default: |
| r18804 | r18805 | |
| 365 | 341 | return data; |
| 366 | 342 | } |
| 367 | 343 | |
| 368 | | void psxsio_device::input( int n_port, int n_mask, int n_data ) |
| 344 | void psxsio_device::input( int n_mask, int n_data ) |
| 369 | 345 | { |
| 370 | | psx_sio *sio = &port[ n_port ]; |
| 371 | | verboselog( machine(), 1, "psx_sio_input( %d, %02x, %02x )\n", n_port, n_mask, n_data ); |
| 372 | | sio->n_rx = ( sio->n_rx & ~n_mask ) | ( n_data & n_mask ); |
| 346 | verboselog( machine(), 1, "psx_sio_input( %s, %02x, %02x )\n", tag(), n_mask, n_data ); |
| 347 | m_rx = ( m_rx & ~n_mask ) | ( n_data & n_mask ); |
| 373 | 348 | |
| 374 | | if( ( sio->n_rx & PSX_SIO_IN_DSR ) != 0 ) |
| 349 | if( ( m_rx & PSX_SIO_IN_DSR ) != 0 ) |
| 375 | 350 | { |
| 376 | | sio->n_status |= SIO_STATUS_DSR; |
| 377 | | if( ( sio->n_rx_prev & PSX_SIO_IN_DSR ) == 0 && |
| 378 | | ( sio->n_control & SIO_CONTROL_DSR_IENA ) != 0 ) |
| 351 | m_status |= SIO_STATUS_DSR; |
| 352 | if( ( m_rx_prev & PSX_SIO_IN_DSR ) == 0 && |
| 353 | ( m_control & SIO_CONTROL_DSR_IENA ) != 0 ) |
| 379 | 354 | { |
| 380 | | sio_interrupt( n_port ); |
| 355 | sio_interrupt(); |
| 381 | 356 | } |
| 382 | 357 | } |
| 383 | 358 | else |
| 384 | 359 | { |
| 385 | | sio->n_status &= ~SIO_STATUS_DSR; |
| 360 | m_status &= ~SIO_STATUS_DSR; |
| 386 | 361 | } |
| 387 | | sio->n_rx_prev = sio->n_rx; |
| 362 | m_rx_prev = m_rx; |
| 388 | 363 | } |