src/mess/machine/ay31015.c
| r3334 | r3335 | |
| 2 | 2 | |
| 3 | 3 | ay31015.c by Robbbert, May 2008 |
| 4 | 4 | |
| 5 | | Code for the AY-3-1014A, AY-3-1015(D), AY-5-1013(A) and AY-6-1013 UARTs |
| 5 | Code for the AY-3-1014A, AY-3-1015(D), AY-5-1013(A), and AY-6-1013 UARTs |
| 6 | The HD6402 UART is compatible with the AY-3-1015 UART. |
| 6 | 7 | |
| 7 | 8 | This is cycle-accurate according to the specifications. |
| 8 | 9 | |
| r3334 | r3335 | |
| 89 | 90 | #include "driver.h" |
| 90 | 91 | #include "ay31015.h" |
| 91 | 92 | |
| 92 | | //typedef struct _ay31015_token ay31015_token; |
| 93 | | static struct // _ay31015_token |
| 93 | typedef enum |
| 94 | 94 | { |
| 95 | IDLE, |
| 96 | START_BIT, |
| 97 | PROCESSING, |
| 98 | PARITY_BIT, |
| 99 | FIRST_STOP_BIT, |
| 100 | SECOND_STOP_BIT, |
| 101 | PREP_TIME |
| 102 | } state_t; |
| 103 | |
| 104 | |
| 105 | typedef struct _ay31015_t ay31015_t; |
| 106 | struct _ay31015_t |
| 107 | { |
| 108 | const ay31015_config *config; |
| 109 | |
| 110 | int pins[41]; |
| 111 | |
| 95 | 112 | UINT8 control_reg; |
| 96 | 113 | UINT8 status_reg; |
| 97 | 114 | UINT16 second_stop_bit; // 0, 8, 16 |
| 98 | 115 | UINT16 total_pulses; // bits * 16 |
| 99 | 116 | UINT8 internal_sample; |
| 100 | 117 | |
| 101 | | UINT8 rx_state; |
| 118 | state_t rx_state; |
| 102 | 119 | UINT8 rx_data; // byte being received |
| 103 | 120 | UINT8 rx_buffer; // received byte waiting to be accepted by computer |
| 104 | 121 | UINT8 rx_bit_count; |
| 105 | 122 | UINT8 rx_parity; |
| 106 | 123 | UINT16 rx_pulses; // total pulses left |
| 124 | double rx_clock; |
| 125 | emu_timer *rx_timer; |
| 107 | 126 | |
| 108 | | UINT8 tx_state; |
| 127 | state_t tx_state; |
| 109 | 128 | UINT8 tx_data; // byte being sent |
| 110 | 129 | UINT8 tx_buffer; // next byte to send |
| 111 | 130 | UINT8 tx_parity; |
| 112 | 131 | UINT16 tx_pulses; // total pulses left |
| 113 | | UINT8 si; |
| 114 | | } ay; |
| 132 | double tx_clock; |
| 133 | emu_timer *tx_timer; |
| 134 | }; |
| 115 | 135 | |
| 116 | | //static struct _ay31015_token ay; |
| 117 | 136 | |
| 118 | | /* state - must only be altered by the timer callbacks */ |
| 137 | /* control reg */ |
| 138 | #define CONTROL_NB1 0x01 |
| 139 | #define CONTROL_NB2 0x02 |
| 140 | #define CONTROL_TSB 0x04 |
| 141 | #define CONTROL_EPS 0x08 |
| 142 | #define CONTROL_NP 0x10 |
| 119 | 143 | |
| 120 | | #define IDLE 0 |
| 121 | | #define START_BIT 1 |
| 122 | | #define PROCESSING 2 |
| 123 | | #define PARITY_BIT 3 |
| 124 | | #define FIRST_STOP_BIT 4 |
| 125 | | #define SECOND_STOP_BIT 5 |
| 126 | | #define PREP_TIME 6 |
| 127 | 144 | |
| 128 | | #if 0 |
| 145 | /* status reg */ |
| 146 | #define STATUS_TBMT 0x01 |
| 147 | #define STATUS_DAV 0x02 |
| 148 | #define STATUS_OR 0x04 |
| 149 | #define STATUS_FE 0x08 |
| 150 | #define STATUS_PE 0x10 |
| 151 | #define STATUS_EOC 0x20 |
| 152 | |
| 153 | |
| 129 | 154 | /*------------------------------------------------- |
| 130 | | get_token - safely gets the data |
| 155 | get_safe_token - safely gets the data |
| 131 | 156 | -------------------------------------------------*/ |
| 132 | 157 | |
| 133 | | INLINE ay31015_token *get_token(const device_config *device) |
| 158 | INLINE ay31015_t *get_safe_token(const device_config *device) |
| 134 | 159 | { |
| 135 | 160 | assert(device != NULL); |
| 136 | 161 | assert(device->token != NULL); |
| 137 | 162 | assert(device->type == AY31015); |
| 138 | | return (ay31015_token *) device->token; |
| 163 | return (ay31015_t *) device->token; |
| 139 | 164 | } |
| 140 | 165 | |
| 141 | 166 | |
| 142 | | /*------------------------------------------------- |
| 143 | | get_config - safely gets the config |
| 144 | | -------------------------------------------------*/ |
| 145 | | |
| 146 | | INLINE const ay31015_config *get_config(const device_config *device) |
| 167 | INLINE UINT8 ay31015_get_si( const device_config *device ) |
| 147 | 168 | { |
| 148 | | assert(device != NULL); |
| 149 | | assert(device->token != NULL); |
| 150 | | assert(device->type == ay31015); |
| 151 | | return (const ay31015_config *) device->static_config; |
| 152 | | } |
| 169 | ay31015_t *ay31015 = get_safe_token( device ); |
| 153 | 170 | |
| 171 | if ( ay31015->config->read_si ) |
| 172 | ay31015->pins[AY31015_SI] = (ay31015->config->read_si)( device, 0 ) ? 1 : 0; |
| 154 | 173 | |
| 155 | | static DEVICE_START(ay31015) |
| 156 | | { |
| 157 | | ay31015_token *ay; |
| 158 | | // const ay31015_config *config = get_config(device); |
| 159 | | |
| 160 | | ay = get_token(device); |
| 161 | | return DEVICE_START_OK; |
| 174 | return ay31015->pins[AY31015_SI]; |
| 162 | 175 | } |
| 163 | | #endif |
| 164 | 176 | |
| 165 | 177 | |
| 166 | | /*------------------------------------------------- |
| 167 | | ay51013_xr - the reset pin |
| 168 | | -------------------------------------------------*/ |
| 169 | | static void ay51013_xr( void ) |
| 178 | INLINE void ay31015_set_so( const device_config *device, int data ) |
| 170 | 179 | { |
| 171 | | /* total pulses = 16 * data-bits */ |
| 172 | | UINT8 t1; |
| 173 | | t1 = (ay.control_reg & 3) + 5; /* data bits */ |
| 174 | | ay.total_pulses = t1 << 4; /* total clock pulses to load a byte */ |
| 175 | | ay.second_stop_bit = ((ay.control_reg & AY31015_TSB) ? 16 : 0); /* 2nd stop bit */ |
| 176 | | ay.status_reg = AY31015_EOC | AY31015_TBMT | AY31015_SO; |
| 177 | | ay.tx_data = 0; |
| 178 | | ay.rx_state = PREP_TIME; |
| 179 | | ay.tx_state = IDLE; |
| 180 | | ay.si = 1; |
| 181 | | } |
| 180 | ay31015_t *ay31015 = get_safe_token( device ); |
| 182 | 181 | |
| 182 | ay31015->pins[AY31015_SO] = data ? 1 : 0; |
| 183 | 183 | |
| 184 | | /*------------------------------------------------- |
| 185 | | ay51013_init - drivers should call this at |
| 186 | | machine reset time |
| 187 | | -------------------------------------------------*/ |
| 188 | | void ay51013_init( void ) |
| 189 | | { |
| 190 | | ay.control_reg = 0; |
| 191 | | ay.rx_data = 0; |
| 192 | | ay51013_xr(); |
| 184 | if ( ay31015->config->write_so ) |
| 185 | (ay31015->config->write_so)( device, 0, ay31015->pins[AY31015_SO] ); |
| 193 | 186 | } |
| 194 | 187 | |
| 195 | 188 | |
| 196 | | /*------------------------------------------------- |
| 197 | | ay51013_cs - The entire control register is |
| 198 | | updated at once. |
| 199 | | -------------------------------------------------*/ |
| 200 | | void ay51013_cs( UINT8 data ) |
| 189 | INLINE int ay31015_update_status_pin( ay31015_t *ay31015, UINT8 reg_bit, ay31015_output_pin_t pin ) |
| 201 | 190 | { |
| 202 | | UINT8 t1 = ay.control_reg; |
| 203 | | ay.control_reg = data; |
| 204 | | if (ay.control_reg != t1) ay51013_xr(); |
| 205 | | } |
| 191 | int new_value = ( ay31015->status_reg & reg_bit ) ? 1 : 0; |
| 206 | 192 | |
| 193 | if ( new_value == ay31015->pins[pin] ) |
| 194 | return 0; |
| 207 | 195 | |
| 208 | | |
| 209 | | /*------------------------------------------------- |
| 210 | | ay31015_xr - the reset pin |
| 211 | | -------------------------------------------------*/ |
| 212 | | static void ay31015_xr( void ) |
| 213 | | { |
| 214 | | /* total pulses = 16 * data-bits */ |
| 215 | | UINT8 t1; |
| 216 | | t1 = (ay.control_reg & 3) + 5; /* data bits */ |
| 217 | | ay.total_pulses = t1 << 4; /* total clock pulses to load a byte */ |
| 218 | | ay.second_stop_bit = ((ay.control_reg & AY31015_TSB) ? 16 : 0); /* 2nd stop bit */ |
| 219 | | if ((t1 == 5) && (ay.second_stop_bit == 16)) |
| 220 | | ay.second_stop_bit = 8; /* 5 data bits and 2 stop bits = 1.5 stop bits */ |
| 221 | | ay.status_reg = AY31015_EOC | AY31015_TBMT | AY31015_SO; |
| 222 | | ay.rx_data = 0; |
| 223 | | ay.tx_data = 0; |
| 224 | | ay.rx_state = PREP_TIME; |
| 225 | | ay.tx_state = IDLE; |
| 226 | | ay.si = 1; |
| 196 | ay31015->pins[pin] = new_value; |
| 197 | return 1; |
| 227 | 198 | } |
| 228 | 199 | |
| 229 | 200 | |
| 230 | 201 | /*------------------------------------------------- |
| 231 | | ay31015_init - drivers should call this at |
| 232 | | machine reset time |
| 202 | ay31015_update_status_pins - Update the status pins |
| 233 | 203 | -------------------------------------------------*/ |
| 234 | | void ay31015_init( void ) |
| 204 | static void ay31015_update_status_pins( const device_config *device ) |
| 235 | 205 | { |
| 236 | | ay.control_reg = 0; |
| 237 | | ay31015_xr(); |
| 238 | | } |
| 206 | ay31015_t *ay31015 = get_safe_token( device ); |
| 207 | int status_pins_changed = 0; |
| 239 | 208 | |
| 209 | /* Should status pins be updated? */ |
| 210 | if ( ! ay31015->pins[AY31015_SWE] ) |
| 211 | { |
| 212 | status_pins_changed += ay31015_update_status_pin( ay31015, STATUS_PE, AY31015_PE ); |
| 213 | status_pins_changed += ay31015_update_status_pin( ay31015, STATUS_FE, AY31015_FE ); |
| 214 | status_pins_changed += ay31015_update_status_pin( ay31015, STATUS_OR, AY31015_OR ); |
| 215 | status_pins_changed += ay31015_update_status_pin( ay31015, STATUS_DAV, AY31015_DAV ); |
| 216 | status_pins_changed += ay31015_update_status_pin( ay31015, STATUS_TBMT, AY31015_TBMT ); |
| 217 | } |
| 218 | status_pins_changed += ay31015_update_status_pin( ay31015, STATUS_EOC, AY31015_EOC ); |
| 240 | 219 | |
| 241 | | /*------------------------------------------------- |
| 242 | | ay31015_cs - The entire control register is |
| 243 | | updated at once. |
| 244 | | -------------------------------------------------*/ |
| 245 | | void ay31015_cs( UINT8 data ) |
| 246 | | { |
| 247 | | UINT8 t1 = ay.control_reg; |
| 248 | | ay.control_reg = data; |
| 249 | | if (ay.control_reg != t1) ay31015_xr(); |
| 220 | if ( status_pins_changed && ay31015->config->status_changed ) |
| 221 | { |
| 222 | (ay31015->config->status_changed)( device, 0, status_pins_changed ); |
| 223 | } |
| 250 | 224 | } |
| 251 | 225 | |
| 252 | 226 | |
| r3334 | r3335 | |
| 258 | 232 | -------------------------------------------------*/ |
| 259 | 233 | static TIMER_CALLBACK( ay31015_rx_process ) |
| 260 | 234 | { |
| 261 | | switch (ay.rx_state) |
| 235 | const device_config *device = ptr; |
| 236 | ay31015_t *ay31015 = get_safe_token( device ); |
| 237 | |
| 238 | switch (ay31015->rx_state) |
| 262 | 239 | { |
| 263 | 240 | case PREP_TIME: // assist sync by ensuring high bit occurs |
| 264 | | ay.rx_pulses--; |
| 265 | | if (ay.si) |
| 266 | | ay.rx_state = IDLE; |
| 241 | ay31015->rx_pulses--; |
| 242 | if (ay31015_get_si( device )) |
| 243 | ay31015->rx_state = IDLE; |
| 267 | 244 | return; |
| 268 | 245 | |
| 269 | 246 | case IDLE: |
| 270 | | ay.rx_pulses--; |
| 271 | | if (!ay.si) |
| 247 | ay31015->rx_pulses--; |
| 248 | if (!ay31015_get_si( device )) |
| 272 | 249 | { |
| 273 | | ay.rx_state = START_BIT; |
| 274 | | ay.rx_pulses = 16; |
| 250 | ay31015->rx_state = START_BIT; |
| 251 | ay31015->rx_pulses = 16; |
| 275 | 252 | } |
| 276 | 253 | return; |
| 277 | 254 | |
| 278 | 255 | case START_BIT: |
| 279 | | ay.rx_pulses--; |
| 280 | | if ((ay.rx_pulses == 8) && (ay.si)) // start bit must be low at sample time |
| 281 | | ay.rx_state = IDLE; |
| 256 | ay31015->rx_pulses--; |
| 257 | if (ay31015->rx_pulses == 8) // start bit must be low at sample time |
| 258 | { |
| 259 | if ( ay31015_get_si( device ) ) |
| 260 | ay31015->rx_state = IDLE; |
| 261 | } |
| 282 | 262 | else |
| 283 | | if (!ay.rx_pulses) // end of start bit |
| 263 | if (!ay31015->rx_pulses) // end of start bit |
| 284 | 264 | { |
| 285 | | ay.rx_state = PROCESSING; |
| 286 | | ay.rx_pulses = ay.total_pulses; |
| 287 | | ay.rx_bit_count = 0; |
| 288 | | ay.rx_parity = 0; |
| 289 | | ay.rx_data = 0; |
| 265 | ay31015->rx_state = PROCESSING; |
| 266 | ay31015->rx_pulses = ay31015->total_pulses; |
| 267 | ay31015->rx_bit_count = 0; |
| 268 | ay31015->rx_parity = 0; |
| 269 | ay31015->rx_data = 0; |
| 290 | 270 | } |
| 291 | 271 | return; |
| 292 | 272 | |
| 293 | 273 | case PROCESSING: |
| 294 | | ay.rx_pulses--; |
| 295 | | if (!ay.rx_pulses) // end of a byte |
| 274 | ay31015->rx_pulses--; |
| 275 | if (!ay31015->rx_pulses) // end of a byte |
| 296 | 276 | { |
| 297 | | ay.rx_pulses = 16; |
| 298 | | if (ay.control_reg & AY31015_NP) // see if we need to get a parity bit |
| 299 | | ay.rx_state = FIRST_STOP_BIT; |
| 277 | ay31015->rx_pulses = 16; |
| 278 | if (ay31015->control_reg & CONTROL_NP) // see if we need to get a parity bit |
| 279 | ay31015->rx_state = FIRST_STOP_BIT; |
| 300 | 280 | else |
| 301 | | ay.rx_state = PARITY_BIT; |
| 281 | ay31015->rx_state = PARITY_BIT; |
| 302 | 282 | } |
| 303 | 283 | else |
| 304 | | if (!(ay.rx_pulses & 15)) // end of a bit |
| 305 | | ay.rx_bit_count++; |
| 284 | if (!(ay31015->rx_pulses & 15)) // end of a bit |
| 285 | ay31015->rx_bit_count++; |
| 306 | 286 | else |
| 307 | | if ((ay.rx_pulses & 15) == 8) // sample input stream |
| 287 | if ((ay31015->rx_pulses & 15) == 8) // sample input stream |
| 308 | 288 | { |
| 309 | | ay.internal_sample = ay.si; |
| 310 | | ay.rx_parity ^= ay.internal_sample; // calculate cumulative parity |
| 311 | | ay.rx_data |= ay.internal_sample << ay.rx_bit_count; |
| 289 | ay31015->internal_sample = ay31015_get_si( device ); |
| 290 | ay31015->rx_parity ^= ay31015->internal_sample; // calculate cumulative parity |
| 291 | ay31015->rx_data |= ay31015->internal_sample << ay31015->rx_bit_count; |
| 312 | 292 | } |
| 313 | 293 | return; |
| 314 | 294 | |
| 315 | 295 | case PARITY_BIT: |
| 316 | | ay.rx_pulses--; |
| 296 | ay31015->rx_pulses--; |
| 317 | 297 | |
| 318 | | if (ay.rx_pulses == 8) // sample input stream |
| 319 | | ay.rx_parity ^= ay.si; // calculate cumulative parity |
| 298 | if (ay31015->rx_pulses == 8) // sample input stream |
| 299 | { |
| 300 | ay31015->rx_parity ^= ay31015_get_si( device ); // calculate cumulative parity |
| 301 | } |
| 320 | 302 | else |
| 321 | | if (!ay.rx_pulses) // end of a byte |
| 303 | if (!ay31015->rx_pulses) // end of a byte |
| 322 | 304 | { |
| 323 | | ay.rx_pulses = 16; |
| 324 | | ay.rx_state = FIRST_STOP_BIT; |
| 305 | ay31015->rx_pulses = 16; |
| 306 | ay31015->rx_state = FIRST_STOP_BIT; |
| 325 | 307 | |
| 326 | | if ((ay.status_reg & AY31015_EPS) && (ay.rx_parity)) |
| 327 | | ay.rx_parity = 0; // odd parity, ok |
| 308 | if ((ay31015->control_reg & CONTROL_EPS) && (ay31015->rx_parity)) |
| 309 | ay31015->rx_parity = 0; // odd parity, ok |
| 328 | 310 | else |
| 329 | | if ((!(ay.status_reg & AY31015_EPS)) && (!ay.rx_parity)) |
| 330 | | ay.rx_parity = 0; // even parity, ok |
| 311 | if ((!(ay31015->control_reg & CONTROL_EPS)) && (!ay31015->rx_parity)) |
| 312 | ay31015->rx_parity = 0; // even parity, ok |
| 331 | 313 | else |
| 332 | | ay.rx_parity = 1; // parity error |
| 314 | ay31015->rx_parity = 1; // parity error |
| 333 | 315 | } |
| 334 | 316 | return; |
| 335 | 317 | |
| 336 | 318 | case FIRST_STOP_BIT: |
| 337 | | ay.rx_pulses--; |
| 338 | | if (ay.rx_pulses == 8) // sample input stream |
| 339 | | ay.internal_sample = ay.si; |
| 319 | ay31015->rx_pulses--; |
| 320 | if (ay31015->rx_pulses == 8) // sample input stream |
| 321 | ay31015->internal_sample = ay31015_get_si( device ); |
| 340 | 322 | else |
| 341 | | if (ay.rx_pulses == 7) // set error flags |
| 323 | if (ay31015->rx_pulses == 7) // set error flags |
| 342 | 324 | { |
| 343 | | if (!ay.internal_sample) |
| 325 | if (!ay31015->internal_sample) |
| 344 | 326 | { |
| 345 | | ay.status_reg |= AY31015_FE; // framing error - the stop bit not high |
| 346 | | ay.rx_state = PREP_TIME; // lost sync - start over |
| 327 | ay31015->status_reg |= STATUS_FE; // framing error - the stop bit not high |
| 328 | ay31015->rx_state = PREP_TIME; // lost sync - start over |
| 347 | 329 | // return; |
| 348 | 330 | } |
| 349 | 331 | else |
| 350 | | ay.status_reg &= ~AY31015_FE; |
| 332 | ay31015->status_reg &= ~STATUS_FE; |
| 351 | 333 | |
| 352 | | if ((ay.rx_parity) && (!(ay.control_reg & AY31015_NP))) |
| 353 | | ay.status_reg |= AY31015_PE; // parity error |
| 334 | if ((ay31015->rx_parity) && (!(ay31015->control_reg & CONTROL_NP))) |
| 335 | ay31015->status_reg |= STATUS_PE; // parity error |
| 354 | 336 | else |
| 355 | | ay.status_reg &= ~AY31015_PE; |
| 337 | ay31015->status_reg &= ~STATUS_PE; |
| 356 | 338 | |
| 357 | | if (ay.status_reg & AY31015_DAV) |
| 358 | | ay.status_reg |= AY31015_OR; // overrun error - previous byte still in buffer |
| 339 | if (ay31015->status_reg & STATUS_DAV) |
| 340 | ay31015->status_reg |= STATUS_OR; // overrun error - previous byte still in buffer |
| 359 | 341 | else |
| 360 | | ay.status_reg &= ~AY31015_OR; |
| 342 | ay31015->status_reg &= ~STATUS_OR; |
| 361 | 343 | |
| 362 | | ay.rx_buffer = ay.rx_data; // bring received byte out for computer to read |
| 344 | ay31015->rx_buffer = ay31015->rx_data; // bring received byte out for computer to read |
| 345 | |
| 346 | ay31015_update_status_pins( device ); |
| 363 | 347 | } |
| 364 | 348 | else |
| 365 | | if (ay.rx_pulses == 6) |
| 366 | | ay.status_reg |= AY31015_DAV; // tell computer that new byte is ready |
| 349 | if (ay31015->rx_pulses == 6) |
| 350 | { |
| 351 | ay31015->status_reg |= STATUS_DAV; // tell computer that new byte is ready |
| 352 | ay31015_update_status_pins( device ); |
| 353 | } |
| 367 | 354 | else |
| 368 | | if (ay.rx_pulses == 4) |
| 355 | if (ay31015->rx_pulses == 4) |
| 356 | { |
| 357 | if (ay31015->second_stop_bit) |
| 358 | { |
| 359 | /* We should wait for the full first stop bit and |
| 360 | the beginning of the second stop bit */ |
| 361 | ay31015->rx_state = SECOND_STOP_BIT; |
| 362 | ay31015->rx_pulses += ay31015->second_stop_bit - 7; |
| 363 | } |
| 364 | else |
| 365 | { |
| 366 | /* We have seen a STOP bit, go back to PREP_TIME */ |
| 367 | ay31015->rx_state = PREP_TIME; |
| 368 | } |
| 369 | } |
| 370 | return; |
| 371 | |
| 372 | case SECOND_STOP_BIT: |
| 373 | ay31015->rx_pulses--; |
| 374 | if (!ay31015->rx_pulses) |
| 375 | ay31015->rx_state = PREP_TIME; |
| 376 | return; |
| 369 | 377 | |
| 370 | | /* According to the specs, this commented-out code is what happens. |
| 371 | | However, it is not particularly effective at keeping sync. |
| 372 | | Therefore, since the input is HIGH, we simply jump to PREP_TIME and |
| 373 | | wait for the next start bit to begin. */ |
| 374 | | |
| 375 | | // if (!ay.rx_pulses) // end of first stop bit |
| 376 | | // { |
| 377 | | // if (ay.second_stop_bit) |
| 378 | | // { |
| 379 | | // ay.rx_state = SECOND_STOP_BIT; |
| 380 | | // ay.rx_pulses = ay.second_stop_bit; |
| 381 | | // } |
| 382 | | // else |
| 383 | | // ay.rx_state = PREP_TIME; |
| 384 | | // } |
| 385 | | // return; |
| 386 | | // |
| 387 | | // case SECOND_STOP_BIT: |
| 388 | | // ay.rx_pulses--; |
| 389 | | // if (!ay.rx_pulses) |
| 390 | | ay.rx_state = PREP_TIME; |
| 391 | | return; |
| 392 | 378 | } |
| 393 | 379 | } |
| 394 | 380 | |
| 395 | 381 | |
| 396 | | /*------------------------------------------------- |
| 397 | | ay31015_set_rx_clock_speed - set receive clock |
| 398 | | -------------------------------------------------*/ |
| 399 | | void ay31015_set_rx_clock_speed( UINT32 data ) |
| 400 | | { |
| 401 | | // if (data) |
| 402 | | timer_pulse(ATTOTIME_IN_HZ(data),NULL,0,ay31015_rx_process); |
| 403 | | // else |
| 404 | | // turn timer off; |
| 405 | | } |
| 406 | | |
| 407 | | /*------------------------------------------------- |
| 408 | | ay31015_swe - The entire status register is |
| 409 | | returned at once. |
| 410 | | -------------------------------------------------*/ |
| 411 | | UINT8 ay31015_swe( void ) |
| 412 | | { |
| 413 | | return ay.status_reg & 0x3f; |
| 414 | | } |
| 415 | | |
| 416 | | |
| 417 | | /*------------------------------------------------- |
| 418 | | ay31015_rde - return a byte to the computer |
| 419 | | -------------------------------------------------*/ |
| 420 | | UINT8 ay31015_rde( void ) |
| 421 | | { |
| 422 | | return ay.rx_buffer; |
| 423 | | } |
| 424 | | |
| 425 | | |
| 426 | | /*------------------------------------------------- |
| 427 | | ay31015_rdav - tell uart computer has retrieved |
| 428 | | the above byte. |
| 429 | | -------------------------------------------------*/ |
| 430 | | void ay31015_rdav( void ) |
| 431 | | { |
| 432 | | ay.status_reg &= ~AY31015_DAV; /* set dav low */ |
| 433 | | } |
| 434 | | |
| 435 | | |
| 436 | | /*------------------------------------------------- |
| 437 | | ay31015_si - send a serial bit to the uart |
| 438 | | -------------------------------------------------*/ |
| 439 | | void ay31015_si( UINT8 data ) |
| 440 | | { |
| 441 | | ay.si = (data) ? 1 : 0; |
| 442 | | } |
| 443 | | |
| 444 | | |
| 445 | 382 | /*************************************************** TRANSMIT CONTROLS *************************************************/ |
| 446 | 383 | |
| 447 | 384 | |
| r3334 | r3335 | |
| 450 | 387 | -------------------------------------------------*/ |
| 451 | 388 | static TIMER_CALLBACK( ay31015_tx_process ) |
| 452 | 389 | { |
| 390 | const device_config *device = ptr; |
| 391 | ay31015_t *ay31015 = get_safe_token( device ); |
| 392 | |
| 453 | 393 | UINT8 t1; |
| 454 | | switch (ay.tx_state) |
| 394 | switch (ay31015->tx_state) |
| 455 | 395 | { |
| 456 | 396 | case IDLE: |
| 457 | | if (!(ay.status_reg & AY31015_TBMT)) |
| 397 | if (!(ay31015->status_reg & STATUS_TBMT)) |
| 458 | 398 | { |
| 459 | | ay.tx_state = PREP_TIME; // When idle, see if a byte has been sent to us |
| 460 | | ay.tx_pulses = 1; |
| 399 | ay31015->tx_state = PREP_TIME; // When idle, see if a byte has been sent to us |
| 400 | ay31015->tx_pulses = 1; |
| 461 | 401 | } |
| 462 | 402 | return; |
| 463 | 403 | |
| 464 | 404 | case PREP_TIME: // This phase lets the transmitter regain sync after an idle period |
| 465 | | ay.tx_pulses--; |
| 466 | | if (!ay.tx_pulses) |
| 405 | ay31015->tx_pulses--; |
| 406 | if (!ay31015->tx_pulses) |
| 467 | 407 | { |
| 468 | | ay.tx_state = START_BIT; |
| 469 | | ay.tx_pulses = 16; |
| 408 | ay31015->tx_state = START_BIT; |
| 409 | ay31015->tx_pulses = 16; |
| 470 | 410 | } |
| 471 | 411 | return; |
| 472 | 412 | |
| 473 | 413 | case START_BIT: |
| 474 | | if (ay.tx_pulses == 16) // beginning of start bit |
| 414 | if (ay31015->tx_pulses == 16) // beginning of start bit |
| 475 | 415 | { |
| 476 | | ay.tx_data = ay.tx_buffer; // load the shift register |
| 477 | | ay.status_reg |= AY31015_TBMT; // tell computer that another byte can be sent to uart |
| 478 | | ay.status_reg &= ~AY31015_SO; // start bit begins now (we are "spacing") |
| 479 | | ay.status_reg &= ~AY31015_EOC; // we are no longer idle |
| 480 | | ay.tx_parity = 0; |
| 416 | ay31015->tx_data = ay31015->tx_buffer; // load the shift register |
| 417 | ay31015->status_reg |= STATUS_TBMT; // tell computer that another byte can be sent to uart |
| 418 | ay31015_set_so( device, 0 ); /* start bit begins now (we are "spacing") */ |
| 419 | ay31015->status_reg &= ~STATUS_EOC; // we are no longer idle |
| 420 | ay31015->tx_parity = 0; |
| 421 | ay31015_update_status_pins( device ); |
| 481 | 422 | } |
| 482 | 423 | |
| 483 | | ay.tx_pulses--; |
| 484 | | if (!ay.tx_pulses) // end of start bit |
| 424 | ay31015->tx_pulses--; |
| 425 | if (!ay31015->tx_pulses) // end of start bit |
| 485 | 426 | { |
| 486 | | ay.tx_state = PROCESSING; |
| 487 | | ay.tx_pulses = ay.total_pulses; |
| 427 | ay31015->tx_state = PROCESSING; |
| 428 | ay31015->tx_pulses = ay31015->total_pulses; |
| 488 | 429 | } |
| 489 | 430 | return; |
| 490 | 431 | |
| 491 | 432 | case PROCESSING: |
| 492 | | if (!(ay.tx_pulses & 15)) // beginning of a data bit |
| 433 | if (!(ay31015->tx_pulses & 15)) // beginning of a data bit |
| 493 | 434 | { |
| 494 | | if (ay.tx_data & 1) |
| 435 | if (ay31015->tx_data & 1) |
| 495 | 436 | { |
| 496 | | ay.status_reg |= AY31015_SO; |
| 497 | | ay.tx_parity++; // calculate cumulative parity |
| 437 | ay31015_set_so( device, 1 ); |
| 438 | ay31015->tx_parity++; // calculate cumulative parity |
| 498 | 439 | } |
| 499 | 440 | else |
| 500 | | ay.status_reg &= ~AY31015_SO; |
| 441 | ay31015_set_so( device, 0 ); |
| 501 | 442 | |
| 502 | | ay.tx_data >>= 1; // adjust the shift register |
| 443 | ay31015->tx_data >>= 1; // adjust the shift register |
| 503 | 444 | } |
| 504 | 445 | |
| 505 | | ay.tx_pulses--; |
| 506 | | if (!ay.tx_pulses) // all data bits sent |
| 446 | ay31015->tx_pulses--; |
| 447 | if (!ay31015->tx_pulses) // all data bits sent |
| 507 | 448 | { |
| 508 | | ay.tx_pulses = 16; |
| 509 | | if (ay.control_reg & AY31015_NP) // see if we need to make a parity bit |
| 510 | | ay.tx_state = FIRST_STOP_BIT; |
| 449 | ay31015->tx_pulses = 16; |
| 450 | if (ay31015->control_reg & CONTROL_NP) // see if we need to make a parity bit |
| 451 | ay31015->tx_state = FIRST_STOP_BIT; |
| 511 | 452 | else |
| 512 | | ay.tx_state = PARITY_BIT; |
| 453 | ay31015->tx_state = PARITY_BIT; |
| 513 | 454 | } |
| 514 | 455 | |
| 515 | 456 | return; |
| 516 | 457 | |
| 517 | 458 | case PARITY_BIT: |
| 518 | | if (ay.tx_pulses == 16) |
| 459 | if (ay31015->tx_pulses == 16) |
| 519 | 460 | { |
| 520 | | t1 = (ay.control_reg & AY31015_EPS) ? 0 : 1; |
| 521 | | t1 ^= (ay.tx_parity & 1); |
| 461 | t1 = (ay31015->control_reg & CONTROL_EPS) ? 0 : 1; |
| 462 | t1 ^= (ay31015->tx_parity & 1); |
| 522 | 463 | if (t1) |
| 523 | | ay.status_reg |= AY31015_SO; // extra bit to set the correct parity |
| 464 | ay31015_set_so( device, 1 ); /* extra bit to set the correct parity */ |
| 524 | 465 | else |
| 525 | | ay.status_reg &= ~AY31015_SO; // it was already correct |
| 466 | ay31015_set_so( device, 0 ); /* it was already correct */ |
| 526 | 467 | } |
| 527 | 468 | |
| 528 | | ay.tx_pulses--; |
| 529 | | if (!ay.tx_pulses) |
| 469 | ay31015->tx_pulses--; |
| 470 | if (!ay31015->tx_pulses) |
| 530 | 471 | { |
| 531 | | ay.tx_state = FIRST_STOP_BIT; |
| 532 | | ay.tx_pulses = 16; |
| 472 | ay31015->tx_state = FIRST_STOP_BIT; |
| 473 | ay31015->tx_pulses = 16; |
| 533 | 474 | } |
| 534 | 475 | return; |
| 535 | 476 | |
| 536 | 477 | case FIRST_STOP_BIT: |
| 537 | | if (ay.tx_pulses == 16) |
| 538 | | ay.status_reg |= AY31015_SO; // create a stop bit (marking and soon idle) |
| 539 | | ay.tx_pulses--; |
| 540 | | if (!ay.tx_pulses) |
| 478 | if (ay31015->tx_pulses == 16) |
| 479 | ay31015_set_so( device, 1 ); /* create a stop bit (marking and soon idle) */ |
| 480 | ay31015->tx_pulses--; |
| 481 | if (!ay31015->tx_pulses) |
| 541 | 482 | { |
| 542 | | ay.status_reg |= AY31015_EOC; // character is completely sent |
| 543 | | if (ay.second_stop_bit) |
| 483 | ay31015->status_reg |= STATUS_EOC; // character is completely sent |
| 484 | if (ay31015->second_stop_bit) |
| 544 | 485 | { |
| 545 | | ay.tx_state = SECOND_STOP_BIT; |
| 546 | | ay.tx_pulses = ay.second_stop_bit; |
| 486 | ay31015->tx_state = SECOND_STOP_BIT; |
| 487 | ay31015->tx_pulses = ay31015->second_stop_bit; |
| 547 | 488 | } |
| 548 | 489 | else |
| 549 | | if (ay.status_reg & AY31015_TBMT) |
| 550 | | ay.tx_state = IDLE; // if nothing to send, go idle |
| 490 | if (ay31015->status_reg & STATUS_TBMT) |
| 491 | ay31015->tx_state = IDLE; // if nothing to send, go idle |
| 551 | 492 | else |
| 552 | 493 | { |
| 553 | | ay.tx_pulses = 16; |
| 554 | | ay.tx_state = START_BIT; // otherwise immediately start next byte |
| 494 | ay31015->tx_pulses = 16; |
| 495 | ay31015->tx_state = START_BIT; // otherwise immediately start next byte |
| 555 | 496 | } |
| 497 | ay31015_update_status_pins( device ); |
| 556 | 498 | } |
| 557 | 499 | return; |
| 558 | 500 | |
| 559 | 501 | case SECOND_STOP_BIT: |
| 560 | | ay.tx_pulses--; |
| 561 | | if (!ay.tx_pulses) |
| 502 | ay31015->tx_pulses--; |
| 503 | if (!ay31015->tx_pulses) |
| 562 | 504 | { |
| 563 | | if (ay.status_reg & AY31015_TBMT) |
| 564 | | ay.tx_state = IDLE; // if nothing to send, go idle |
| 505 | if (ay31015->status_reg & STATUS_TBMT) |
| 506 | ay31015->tx_state = IDLE; // if nothing to send, go idle |
| 565 | 507 | else |
| 566 | 508 | { |
| 567 | | ay.tx_pulses = 16; |
| 568 | | ay.tx_state = START_BIT; // otherwise immediately start next byte |
| 509 | ay31015->tx_pulses = 16; |
| 510 | ay31015->tx_state = START_BIT; // otherwise immediately start next byte |
| 569 | 511 | } |
| 570 | 512 | } |
| 571 | 513 | return; |
| r3334 | r3335 | |
| 575 | 517 | |
| 576 | 518 | |
| 577 | 519 | /*------------------------------------------------- |
| 578 | | ay31015_set_tx_clock_speed - set transmit clock |
| 520 | ay31015_reset - reset internal state |
| 579 | 521 | -------------------------------------------------*/ |
| 580 | | void ay31015_set_tx_clock_speed( UINT32 data ) |
| 522 | static void ay31015_reset( const device_config *device ) |
| 581 | 523 | { |
| 582 | | // if (data) |
| 583 | | timer_pulse(ATTOTIME_IN_HZ(data),NULL,0,ay31015_tx_process); |
| 584 | | // else |
| 585 | | // turn timer off; |
| 524 | ay31015_t *ay31015 = get_safe_token( device ); |
| 525 | |
| 526 | /* total pulses = 16 * data-bits */ |
| 527 | UINT8 t1; |
| 528 | |
| 529 | if ( ay31015->control_reg & CONTROL_NB2 ) |
| 530 | t1 = ( ay31015->control_reg & CONTROL_NB1 ) ? 8 : 7; |
| 531 | else |
| 532 | t1 = ( ay31015->control_reg & CONTROL_NB1 ) ? 6 : 5; |
| 533 | |
| 534 | ay31015->total_pulses = t1 << 4; /* total clock pulses to load a byte */ |
| 535 | ay31015->second_stop_bit = ((ay31015->control_reg & CONTROL_TSB) ? 16 : 0); /* 2nd stop bit */ |
| 536 | if ((t1 == 5) && (ay31015->second_stop_bit == 16)) |
| 537 | ay31015->second_stop_bit = 8; /* 5 data bits and 2 stop bits = 1.5 stop bits */ |
| 538 | ay31015->status_reg = STATUS_EOC | STATUS_TBMT; |
| 539 | ay31015->tx_data = 0; |
| 540 | ay31015->rx_state = PREP_TIME; |
| 541 | ay31015->tx_state = IDLE; |
| 542 | ay31015->pins[AY31015_SI] = 1; |
| 543 | ay31015_set_so( device, 1 ); |
| 544 | |
| 545 | if ( ay31015->config->type == AY_3_1015 ) |
| 546 | ay31015->rx_data = 0; |
| 547 | |
| 586 | 548 | } |
| 587 | 549 | |
| 588 | 550 | |
| 589 | 551 | /*------------------------------------------------- |
| 590 | | ay31015_so - return a serial bit to calling |
| 591 | | driver. |
| 552 | ay31015_transfer_control_pins - transfers contents of controls pins to the control register |
| 592 | 553 | -------------------------------------------------*/ |
| 593 | | UINT8 ay31015_so( void ) |
| 554 | static void ay31015_transfer_control_pins( const device_config *device ) |
| 594 | 555 | { |
| 595 | | return (ay.status_reg & AY31015_SO) ? 1 : 0; |
| 556 | ay31015_t *ay31015 = get_safe_token( device ); |
| 557 | UINT8 control = 0; |
| 558 | |
| 559 | control |= ay31015->pins[AY31015_NP ] ? CONTROL_NP : 0; |
| 560 | control |= ay31015->pins[AY31015_TSB] ? CONTROL_TSB : 0; |
| 561 | control |= ay31015->pins[AY31015_NB1] ? CONTROL_NB1 : 0; |
| 562 | control |= ay31015->pins[AY31015_NB2] ? CONTROL_NB2 : 0; |
| 563 | control |= ay31015->pins[AY31015_EPS] ? CONTROL_EPS : 0; |
| 564 | |
| 565 | if ( ay31015->control_reg != control ) |
| 566 | { |
| 567 | ay31015->control_reg = control; |
| 568 | ay31015_reset( device ); |
| 569 | } |
| 596 | 570 | } |
| 597 | 571 | |
| 598 | 572 | |
| 599 | 573 | /*------------------------------------------------- |
| 600 | | ay31015_ds - accept a byte to transmit, if able |
| 574 | ay31015_set_input_pin - set an input pin |
| 601 | 575 | -------------------------------------------------*/ |
| 602 | | void ay31015_ds( UINT8 data ) |
| 576 | void ay31015_set_input_pin( const device_config *device, ay31015_input_pin_t pin, int data ) |
| 603 | 577 | { |
| 604 | | if (ay.status_reg & AY31015_TBMT) |
| 578 | ay31015_t *ay31015 = get_safe_token(device); |
| 579 | |
| 580 | data = data ? 1 : 0; |
| 581 | |
| 582 | switch ( pin ) |
| 605 | 583 | { |
| 606 | | ay.tx_buffer = data; |
| 607 | | ay.status_reg &= ~AY31015_TBMT; |
| 584 | case AY31015_SWE: |
| 585 | ay31015->pins[pin] = data; |
| 586 | ay31015_update_status_pins( device ); |
| 587 | break; |
| 588 | case AY31015_RDAV: |
| 589 | ay31015->pins[pin] = data; |
| 590 | if ( ! data ) |
| 591 | { |
| 592 | ay31015->status_reg &= ~STATUS_DAV; |
| 593 | ay31015->pins[AY31015_DAV] = 0; |
| 594 | } |
| 595 | break; |
| 596 | case AY31015_SI: |
| 597 | ay31015->pins[pin] = data; |
| 598 | break; |
| 599 | case AY31015_XR: |
| 600 | ay31015->pins[pin] = data; |
| 601 | if ( data ) |
| 602 | ay31015_reset( device ); |
| 603 | break; |
| 604 | case AY31015_CS: |
| 605 | case AY31015_NP: |
| 606 | case AY31015_TSB: |
| 607 | case AY31015_NB1: |
| 608 | case AY31015_NB2: |
| 609 | case AY31015_EPS: |
| 610 | ay31015->pins[pin] = data; |
| 611 | if ( ay31015->pins[AY31015_CS] ) |
| 612 | ay31015_transfer_control_pins( device ); |
| 613 | break; |
| 608 | 614 | } |
| 609 | 615 | } |
| 610 | 616 | |
| 611 | 617 | |
| 618 | /*------------------------------------------------- |
| 619 | ay31015_get_output_pin - get the status of an output pin |
| 620 | -------------------------------------------------*/ |
| 621 | int ay31015_get_output_pin( const device_config *device, ay31015_output_pin_t pin ) |
| 622 | { |
| 623 | ay31015_t *ay31015 = get_safe_token(device); |
| 612 | 624 | |
| 613 | | #if 0 |
| 625 | return ay31015->pins[pin]; |
| 626 | } |
| 614 | 627 | |
| 615 | | void |
| 616 | | ay31015_token *ay = get_token(device); |
| 617 | | const ay31015_config *config = get_config(device); |
| 618 | 628 | |
| 629 | INLINE void ay31015_update_rx_timer( const device_config *device ) |
| 630 | { |
| 631 | ay31015_t *ay31015 = get_safe_token( device ); |
| 619 | 632 | |
| 633 | if ( ay31015->rx_clock > 0.0 ) |
| 634 | { |
| 635 | timer_adjust_periodic( ay31015->rx_timer, ATTOTIME_IN_HZ( ay31015->rx_clock ), 0, ATTOTIME_IN_HZ( ay31015->rx_clock ) ); |
| 636 | } |
| 637 | else |
| 638 | { |
| 639 | timer_enable( ay31015->rx_timer, 0 ); |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | |
| 644 | INLINE void ay31015_update_tx_timer( const device_config *device ) |
| 645 | { |
| 646 | ay31015_t *ay31015 = get_safe_token( device ); |
| 647 | |
| 648 | if ( ay31015->tx_clock > 0.0 ) |
| 649 | { |
| 650 | timer_adjust_periodic( ay31015->tx_timer, ATTOTIME_IN_HZ( ay31015->tx_clock ), 0, ATTOTIME_IN_HZ( ay31015->tx_clock ) ); |
| 651 | } |
| 652 | else |
| 653 | { |
| 654 | timer_enable( ay31015->tx_timer, 0 ); |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | |
| 620 | 659 | /*------------------------------------------------- |
| 660 | ay31015_set_receiver_clock - set receive clock |
| 661 | -------------------------------------------------*/ |
| 662 | void ay31015_set_receiver_clock( const device_config *device, double new_clock ) |
| 663 | { |
| 664 | ay31015_t *ay31015 = get_safe_token(device); |
| 665 | |
| 666 | ay31015->rx_clock = new_clock; |
| 667 | ay31015_update_rx_timer( device ); |
| 668 | } |
| 669 | |
| 670 | |
| 671 | /*------------------------------------------------- |
| 672 | ay31015_set_transmitter_clock - set transmit clock |
| 673 | -------------------------------------------------*/ |
| 674 | void ay31015_set_transmitter_clock( const device_config *device, double new_clock ) |
| 675 | { |
| 676 | ay31015_t *ay31015 = get_safe_token(device); |
| 677 | |
| 678 | ay31015->tx_clock = new_clock; |
| 679 | ay31015_update_tx_timer( device ); |
| 680 | } |
| 681 | |
| 682 | |
| 683 | /*------------------------------------------------- |
| 684 | ay31015_get_received_data - return a byte to the computer |
| 685 | -------------------------------------------------*/ |
| 686 | UINT8 ay31015_get_received_data( const device_config *device ) |
| 687 | { |
| 688 | ay31015_t *ay31015 = get_safe_token(device); |
| 689 | |
| 690 | return ay31015->rx_buffer; |
| 691 | } |
| 692 | |
| 693 | |
| 694 | /*------------------------------------------------- |
| 695 | ay31015_set_transmit_data - accept a byte to transmit, if able |
| 696 | -------------------------------------------------*/ |
| 697 | void ay31015_set_transmit_data( const device_config *device, UINT8 data ) |
| 698 | { |
| 699 | ay31015_t *ay31015 = get_safe_token(device); |
| 700 | |
| 701 | if (ay31015->status_reg & STATUS_TBMT) |
| 702 | { |
| 703 | ay31015->tx_buffer = data; |
| 704 | ay31015->status_reg &= ~STATUS_TBMT; |
| 705 | ay31015_update_status_pins( device ); |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | |
| 710 | static DEVICE_START(ay31015) |
| 711 | { |
| 712 | ay31015_t *ay31015 = get_safe_token(device); |
| 713 | |
| 714 | ay31015->config = device->static_config; |
| 715 | |
| 716 | ay31015->tx_clock = ay31015->config->transmitter_clock; |
| 717 | ay31015->rx_clock = ay31015->config->receiver_clock; |
| 718 | |
| 719 | ay31015->rx_timer = timer_alloc( ay31015_rx_process, (void *)device ); |
| 720 | ay31015->tx_timer = timer_alloc( ay31015_tx_process, (void *)device ); |
| 721 | |
| 722 | ay31015_update_rx_timer( device ); |
| 723 | ay31015_update_tx_timer( device ); |
| 724 | |
| 725 | return DEVICE_START_OK; |
| 726 | } |
| 727 | |
| 728 | |
| 729 | static DEVICE_RESET( ay31015 ) |
| 730 | { |
| 731 | ay31015_t *ay31015 = get_safe_token(device); |
| 732 | |
| 733 | ay31015->control_reg = 0; |
| 734 | ay31015->rx_data = 0; |
| 735 | |
| 736 | ay31015_reset( device ); |
| 737 | } |
| 738 | |
| 739 | |
| 740 | static DEVICE_SET_INFO( ay31015 ) |
| 741 | { |
| 742 | switch ( state ) |
| 743 | { |
| 744 | /* no parameters to set */ |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | |
| 749 | /*------------------------------------------------- |
| 621 | 750 | DEVICE_GET_INFO(ay31015) - device getinfo |
| 622 | 751 | function |
| 623 | 752 | -------------------------------------------------*/ |
| 624 | 753 | |
| 625 | | DEVICE_GET_INFO(ay31015) |
| 754 | DEVICE_GET_INFO( ay31015 ) |
| 626 | 755 | { |
| 627 | 756 | switch(state) |
| 628 | 757 | { |
| 629 | 758 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 630 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(ay31015_token); break; |
| 631 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 632 | | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break; |
| 633 | | case DEVINFO_INT_IMAGE_TYPE: info->i = IO_PRINTER; break; |
| 634 | | case DEVINFO_INT_IMAGE_READABLE: info->i = 0; break; |
| 635 | | case DEVINFO_INT_IMAGE_WRITEABLE: info->i = 1; break; |
| 636 | | case DEVINFO_INT_IMAGE_CREATABLE: info->i = 1; break; |
| 759 | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(ay31015_t); break; |
| 760 | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 761 | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break; |
| 637 | 762 | |
| 638 | 763 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 639 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(ay31015); break; |
| 764 | case DEVINFO_FCT_SET_INFO: info->set_info = DEVICE_SET_INFO_NAME(ay31015); break; |
| 765 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(ay31015); break; |
| 766 | case DEVINFO_FCT_STOP: /* nothing */ break; |
| 767 | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME( ay31015 ); break; |
| 640 | 768 | |
| 641 | 769 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 642 | | case DEVINFO_STR_NAME: info->s = "ay31015"; break; |
| 643 | | case DEVINFO_STR_FAMILY: info->s = "ay31015"; break; |
| 644 | | case DEVINFO_STR_SOURCE_FILE: info->s = __FILE__; break; |
| 645 | | case DEVINFO_STR_IMAGE_FILE_EXTENSIONS: info->s = "prn"; break; |
| 770 | case DEVINFO_STR_NAME: info->s = "AY-3-1015"; break; |
| 771 | case DEVINFO_STR_FAMILY: info->s = "AY-3-1015/AY-5-1013 UARTs"; break; |
| 772 | case DEVINFO_STR_VERSION: info->s = "1.00"; break; |
| 773 | case DEVINFO_STR_SOURCE_FILE: info->s = __FILE__; break; |
| 774 | case DEVINFO_STR_CREDITS: info->s = "Copyright the MAME and MESS Teams"; break; |
| 646 | 775 | } |
| 647 | 776 | } |
| 648 | | #endif |
| 649 | 777 | |
src/mess/drivers/exidy.c
| r3334 | r3335 | |
| 150 | 150 | #include "machine/ay31015.h" |
| 151 | 151 | |
| 152 | 152 | |
| 153 | static const device_config *exidy_ay31015; |
| 154 | |
| 155 | |
| 153 | 156 | static Z80BIN_EXECUTE( exidy ); |
| 154 | 157 | |
| 155 | 158 | static DEVICE_IMAGE_LOAD( exidy_floppy ) |
| r3334 | r3335 | |
| 203 | 206 | return device_list_find_by_tag( machine->config->devicelist, CASSETTE, "cassette1" ); |
| 204 | 207 | } |
| 205 | 208 | |
| 206 | | static UINT8 cass_data[]={ 0, 0, 0, 0, 0, 0, 0 }; |
| 207 | 209 | |
| 210 | static struct { |
| 211 | struct { |
| 212 | int length; /* time cassette level is at input.level */ |
| 213 | int level; /* cassette level */ |
| 214 | int bit; /* bit being read */ |
| 215 | } input; |
| 216 | struct { |
| 217 | int length; /* time cassette level is at output.level */ |
| 218 | int level; /* cassette level */ |
| 219 | int bit; /* bit to to output */ |
| 220 | } output; |
| 221 | } cass_data; |
| 222 | |
| 223 | |
| 208 | 224 | static TIMER_CALLBACK(exidy_cassette_tc) |
| 209 | 225 | { |
| 210 | 226 | UINT8 cass_ws = 0; |
| 211 | | switch (exidy_fe & 0xc0) // bit 7 low indicates cassette |
| 227 | switch (exidy_fe & 0xc0) /*/ bit 7 low indicates cassette */ |
| 212 | 228 | { |
| 213 | | case 0x00: // cassette 300 baud - works |
| 229 | case 0x00: /* Cassette 300 baud */ |
| 214 | 230 | |
| 215 | 231 | /* loading a tape - this is basically the same as the super80. |
| 216 | 232 | We convert the 1200/2400 Hz signal to a 0 or 1, and send it to the uart. */ |
| 217 | 233 | |
| 218 | | cass_data[1]++; |
| 234 | cass_data.input.length++; |
| 219 | 235 | |
| 220 | 236 | cass_ws = (cassette_input(cassette_device_image(machine)) > +0.02) ? 1 : 0; |
| 221 | 237 | |
| 222 | | if (cass_ws != cass_data[0]) |
| 238 | if (cass_ws != cass_data.input.level) |
| 223 | 239 | { |
| 224 | | cass_data[0] = cass_ws; |
| 225 | | cass_data[2] = ((cass_data[1] < 0x6) || (cass_data[1] > 0x20)) ? 1 : 0; |
| 226 | | cass_data[1] = 0; |
| 227 | | if (cass_data[2] != cass_data[3]) |
| 228 | | { |
| 229 | | ay31015_si(cass_data[2]); |
| 230 | | cass_data[3] = cass_data[2]; |
| 231 | | } |
| 240 | cass_data.input.level = cass_ws; |
| 241 | cass_data.input.bit = ((cass_data.input.length < 0x6) || (cass_data.input.length > 0x20)) ? 1 : 0; |
| 242 | cass_data.input.length = 0; |
| 243 | ay31015_set_input_pin( exidy_ay31015, AY31015_SI, cass_data.input.bit ); |
| 232 | 244 | } |
| 233 | 245 | |
| 234 | 246 | /* saving a tape - convert the serial stream from the uart, into 1200 and 2400 Hz frequencies. |
| 235 | 247 | Synchronisation of the frequency pulses to the uart is extremely important. */ |
| 236 | 248 | |
| 237 | | cass_data[5]++; |
| 238 | | if (!(cass_data[5] & 0x1f)) |
| 249 | cass_data.output.length++; |
| 250 | if (!(cass_data.output.length & 0x1f)) |
| 239 | 251 | { |
| 240 | | cass_ws = ay31015_so(); |
| 241 | | if (cass_ws != cass_data[4]) |
| 252 | cass_ws = ay31015_get_output_pin( exidy_ay31015, AY31015_SO ); |
| 253 | if (cass_ws != cass_data.output.bit) |
| 242 | 254 | { |
| 243 | | cass_data[4] = cass_ws; |
| 244 | | cass_data[5]=0; |
| 255 | cass_data.output.bit = cass_ws; |
| 256 | cass_data.output.length = 0; |
| 245 | 257 | } |
| 246 | 258 | } |
| 247 | 259 | |
| 248 | | if (!(cass_data[5] & 3)) |
| 260 | if (!(cass_data.output.length & 3)) |
| 249 | 261 | { |
| 250 | | if (!((cass_data[4] == 0) && (cass_data[5] & 4))) |
| 262 | if (!((cass_data.output.bit == 0) && (cass_data.output.length & 4))) |
| 251 | 263 | { |
| 252 | | cass_data[6] ^= 1; // toggle output state, except on 2nd half of low bit |
| 253 | | cassette_output(cassette_device_image(machine), cass_data[6] ? -1.0 : +1.0); |
| 264 | cass_data.output.level ^= 1; // toggle output state, except on 2nd half of low bit |
| 265 | cassette_output(cassette_device_image(machine), cass_data.output.level ? -1.0 : +1.0); |
| 254 | 266 | } |
| 255 | 267 | } |
| 256 | 268 | return; |
| 257 | 269 | |
| 258 | | case 0x40: // cassette 1200 baud - not working at this time |
| 270 | case 0x40: /* Cassette 1200 baud */ |
| 259 | 271 | /* loading a tape */ |
| 260 | | cass_data[1]++; |
| 272 | cass_data.input.length++; |
| 261 | 273 | |
| 262 | 274 | cass_ws = (cassette_input(cassette_device_image(machine)) > +0.02) ? 1 : 0; |
| 263 | 275 | |
| 264 | | if (cass_ws != cass_data[0]) |
| 276 | if (cass_ws != cass_data.input.level || cass_data.input.length == 10) |
| 265 | 277 | { |
| 266 | | cass_data[0] = cass_ws; |
| 267 | | cass_data[2] = ((cass_data[1] < 0xc) || (cass_data[1] > 0x20)) ? 1 : 0; |
| 268 | | cass_data[1] = 0; |
| 269 | | if (cass_data[2] != cass_data[3]) |
| 278 | cass_data.input.bit = ((cass_data.input.length < 10) || (cass_data.input.length > 0x20)) ? 1 : 0; |
| 279 | if ( cass_ws != cass_data.input.level ) |
| 270 | 280 | { |
| 271 | | ay31015_si(cass_data[2]); |
| 272 | | cass_data[3] = cass_data[2]; |
| 281 | cass_data.input.length = 0; |
| 282 | cass_data.input.level = cass_ws; |
| 273 | 283 | } |
| 274 | | cass_data[2] = 0; |
| 284 | ay31015_set_input_pin( exidy_ay31015, AY31015_SI, cass_data.input.bit ); |
| 275 | 285 | } |
| 276 | 286 | |
| 277 | 287 | /* saving a tape - convert the serial stream from the uart, into 600 and 1200 Hz frequencies. */ |
| 278 | 288 | |
| 279 | | cass_data[5]++; |
| 280 | | if (!(cass_data[5] & 0x07)) |
| 289 | cass_data.output.length++; |
| 290 | if (!(cass_data.output.length & 0x07)) |
| 281 | 291 | { |
| 282 | | cass_ws = ay31015_so(); |
| 283 | | if (cass_ws != cass_data[4]) |
| 292 | cass_ws = ay31015_get_output_pin( exidy_ay31015, AY31015_SO ); |
| 293 | if (cass_ws != cass_data.output.bit) |
| 284 | 294 | { |
| 285 | | cass_data[4] = cass_ws; |
| 286 | | cass_data[5]=0; |
| 295 | cass_data.output.bit = cass_ws; |
| 296 | cass_data.output.length = 0; |
| 287 | 297 | } |
| 288 | 298 | } |
| 289 | 299 | |
| 290 | | if (!(cass_data[5] & 7)) |
| 300 | if (!(cass_data.output.length & 7)) |
| 291 | 301 | { |
| 292 | | if (!((cass_data[4] == 0) && (cass_data[5] & 8))) |
| 302 | if (!((cass_data.output.bit == 0) && (cass_data.output.length & 8))) |
| 293 | 303 | { |
| 294 | | cass_data[6] ^= 1; // toggle output state, except on 2nd half of low bit |
| 295 | | cassette_output(cassette_device_image(machine), cass_data[6] ? -1.0 : +1.0); |
| 304 | cass_data.output.level ^= 1; // toggle output state, except on 2nd half of low bit |
| 305 | cassette_output(cassette_device_image(machine), cass_data.output.level ? -1.0 : +1.0); |
| 296 | 306 | } |
| 297 | 307 | } |
| 298 | 308 | return; |
| r3334 | r3335 | |
| 337 | 347 | |
| 338 | 348 | static MACHINE_RESET( exidyd ) |
| 339 | 349 | { |
| 340 | | ay31015_init(); |
| 350 | /* Initialize cassette interface */ |
| 351 | cass_data.output.length = 0; |
| 352 | cass_data.output.level = 1; |
| 353 | cass_data.input.length = 0; |
| 354 | cass_data.input.bit = 1; |
| 341 | 355 | |
| 356 | exidy_ay31015 = device_list_find_by_tag( machine->config->devicelist, AY31015, "ay_3_1015" ); |
| 357 | |
| 342 | 358 | centronics_config(0, exidy_cent_config); |
| 343 | 359 | /* assumption: select is tied low */ |
| 344 | 360 | centronics_write_handshake(0, CENTRONICS_SELECT | CENTRONICS_NO_RESET, CENTRONICS_SELECT| CENTRONICS_NO_RESET); |
| r3334 | r3335 | |
| 396 | 412 | |
| 397 | 413 | static WRITE8_HANDLER(exidy_fc_port_w) |
| 398 | 414 | { |
| 399 | | ay31015_ds( data ); |
| 415 | ay31015_set_transmit_data( exidy_ay31015, data ); |
| 400 | 416 | } |
| 401 | 417 | |
| 402 | 418 | |
| 403 | 419 | static WRITE8_HANDLER(exidy_fd_port_w) |
| 404 | 420 | { |
| 405 | | ay31015_cs( data ); |
| 421 | /* Translate data to control signals */ |
| 422 | |
| 423 | ay31015_set_input_pin( exidy_ay31015, AY31015_CS, 0 ); |
| 424 | ay31015_set_input_pin( exidy_ay31015, AY31015_NB1, ( data & 0x01 ) ? 1 : 0 ); |
| 425 | ay31015_set_input_pin( exidy_ay31015, AY31015_NB2, ( data & 0x02 ) ? 1 : 0 ); |
| 426 | ay31015_set_input_pin( exidy_ay31015, AY31015_TSB, ( data & 0x04 ) ? 1 : 0 ); |
| 427 | ay31015_set_input_pin( exidy_ay31015, AY31015_EPS, ( data & 0x08 ) ? 1 : 0 ); |
| 428 | ay31015_set_input_pin( exidy_ay31015, AY31015_NP, ( data & 0x10 ) ? 1 : 0 ); |
| 429 | ay31015_set_input_pin( exidy_ay31015, AY31015_CS, 1 ); |
| 406 | 430 | } |
| 407 | 431 | |
| 408 | 432 | #define EXIDY_CASSETTE_MOTOR_MASK ((1<<4)|(1<<5)) |
| r3334 | r3335 | |
| 455 | 479 | /* bit 6 */ |
| 456 | 480 | if (changed_bits & 0x40) |
| 457 | 481 | { |
| 458 | | ay31015_set_rx_clock_speed ((data & 0x40) ? 19200 : 4800); |
| 459 | | ay31015_set_tx_clock_speed ((data & 0x40) ? 14400 : 4800); |
| 482 | ay31015_set_receiver_clock( exidy_ay31015, (data & 0x40) ? 19200.0 : 4800.0); |
| 483 | ay31015_set_transmitter_clock( exidy_ay31015, (data & 0x40) ? 19200.0 : 4800.0); |
| 460 | 484 | } |
| 461 | 485 | |
| 462 | 486 | /* bit 7 */ |
| r3334 | r3335 | |
| 495 | 519 | |
| 496 | 520 | static READ8_HANDLER(exidy_fc_port_r) |
| 497 | 521 | { |
| 498 | | UINT8 data = ay31015_rde(); |
| 499 | | ay31015_rdav(); |
| 522 | UINT8 data = ay31015_get_received_data( exidy_ay31015 ); |
| 523 | ay31015_set_input_pin( exidy_ay31015, AY31015_RDAV, 0 ); |
| 524 | ay31015_set_input_pin( exidy_ay31015, AY31015_RDAV, 1 ); |
| 500 | 525 | return data; |
| 501 | 526 | } |
| 502 | 527 | |
| 503 | 528 | static READ8_HANDLER(exidy_fd_port_r) |
| 504 | 529 | { |
| 505 | 530 | /* set unused bits high */ |
| 506 | | return ay31015_swe() | 0xe0; |
| 531 | UINT8 data = 0xe0; |
| 532 | |
| 533 | ay31015_set_input_pin( exidy_ay31015, AY31015_SWE, 0 ); |
| 534 | data |= ay31015_get_output_pin( exidy_ay31015, AY31015_TBMT ) ? 0x01 : 0; |
| 535 | data |= ay31015_get_output_pin( exidy_ay31015, AY31015_DAV ) ? 0x02 : 0; |
| 536 | data |= ay31015_get_output_pin( exidy_ay31015, AY31015_OR ) ? 0x04 : 0; |
| 537 | data |= ay31015_get_output_pin( exidy_ay31015, AY31015_FE ) ? 0x08 : 0; |
| 538 | data |= ay31015_get_output_pin( exidy_ay31015, AY31015_PE ) ? 0x10 : 0; |
| 539 | ay31015_set_input_pin( exidy_ay31015, AY31015_SWE, 1 ); |
| 540 | |
| 541 | return data; |
| 507 | 542 | } |
| 508 | 543 | |
| 509 | 544 | static READ8_HANDLER(exidy_fe_port_r) |
| r3334 | r3335 | |
| 720 | 755 | |
| 721 | 756 | /**********************************************************************************************************/ |
| 722 | 757 | |
| 758 | static const ay31015_config exidy_ay31015_config = |
| 759 | { |
| 760 | AY_3_1015, |
| 761 | 4800.0, |
| 762 | 4800.0, |
| 763 | NULL, |
| 764 | NULL, |
| 765 | NULL |
| 766 | }; |
| 767 | |
| 768 | |
| 723 | 769 | static const cassette_config exidy_cassette_config = |
| 724 | 770 | { |
| 725 | 771 | cassette_default_formats, |
| 726 | 772 | NULL, |
| 727 | | CASSETTE_STOPPED | CASSETTE_MOTOR_DISABLED | CASSETTE_SPEAKER_ENABLED |
| 773 | CASSETTE_PLAY | CASSETTE_MOTOR_DISABLED | CASSETTE_SPEAKER_ENABLED |
| 728 | 774 | }; |
| 729 | 775 | |
| 730 | 776 | |
| r3334 | r3335 | |
| 758 | 804 | MDRV_SOUND_ADD("speaker", SPEAKER, 0) |
| 759 | 805 | MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50) // speaker on parallel port |
| 760 | 806 | |
| 807 | MDRV_AY31015_ADD( "ay_3_1015", exidy_ay31015_config ) |
| 808 | |
| 761 | 809 | /* printer */ |
| 762 | 810 | MDRV_DEVICE_ADD("printer", PRINTER) |
| 763 | 811 | |