src/mess/machine/tms9902.c
| r3833 | r3834 | |
| 9 | 9 | |
| 10 | 10 | #include "tms9902.h" |
| 11 | 11 | |
| 12 | | #define MAX_9902 2 |
| 13 | | |
| 14 | 12 | /* |
| 15 | 13 | TMS9902 emulation. |
| 16 | 14 | |
| r3833 | r3834 | |
| 25 | 23 | |
| 26 | 24 | */ |
| 27 | 25 | |
| 28 | | typedef struct tms9902_t |
| 26 | |
| 27 | /*************************************************************************** |
| 28 | TYPE DEFINITIONS |
| 29 | ***************************************************************************/ |
| 30 | |
| 31 | typedef struct _tms9902_t tms9902_t; |
| 32 | struct _tms9902_t |
| 29 | 33 | { |
| 30 | 34 | /* driver-specific configuration */ |
| 31 | 35 | /* tms9902 clock rate (PHI* pin, normally connected to TMS9900 Phi3*) */ |
| r3833 | r3834 | |
| 34 | 38 | (warning: 3MHz on a tms9900 is equivalent to 12MHz on a tms9995 or tms99000) */ |
| 35 | 39 | double clock_rate; |
| 36 | 40 | |
| 37 | | void (*int_callback)(int which, int INT); /* called when interrupt pin state changes */ |
| 38 | | void (*rts_callback)(int which, int RTS); /* called when Request To Send pin state changes */ |
| 39 | | void (*brk_callback)(int which, int BRK); /* called when BReaK state changes */ |
| 40 | | void (*xmit_callback)(int which, int data); /* called when a character is transmitted */ |
| 41 | | |
| 42 | | |
| 43 | 41 | /* CRU interface */ |
| 44 | | int register_select; /* bits which select which register is being written to */ |
| 42 | int register_select; /* bits device select device register is being written to */ |
| 45 | 43 | |
| 46 | 44 | /* inputs pins */ |
| 47 | 45 | unsigned int CTS : 1; |
| r3833 | r3834 | |
| 93 | 91 | |
| 94 | 92 | /* clock registers */ |
| 95 | 93 | void *timer; /* MESS timer, used to emulate the decrementer register */ |
| 96 | | } tms9902_t; |
| 97 | 94 | |
| 95 | /* Pointer to interface */ |
| 96 | const tms9902_interface *intf; |
| 97 | }; |
| 98 | |
| 98 | 99 | /* bits in register_select */ |
| 99 | 100 | enum |
| 100 | 101 | { |
| r3833 | r3834 | |
| 104 | 105 | register_select_LDCTRL = 0x8 |
| 105 | 106 | }; |
| 106 | 107 | |
| 107 | | static tms9902_t tms9902[MAX_9902]; |
| 108 | static void initiate_transmit(const device_config *device); |
| 109 | static void set_brk(const device_config *device, int state); |
| 110 | static DEVICE_RESET( tms9902 ); |
| 108 | 111 | |
| 112 | /*************************************************************************** |
| 113 | INLINE FUNCTIONS |
| 114 | ***************************************************************************/ |
| 109 | 115 | |
| 110 | | /* |
| 111 | | prototypes |
| 112 | | */ |
| 113 | | |
| 114 | | static void field_interrupts(int which); |
| 115 | | static TIMER_CALLBACK(decrementer_callback); |
| 116 | | static void set_rts(int which, int state); |
| 117 | | static void set_brk(int which, int state); |
| 118 | | static void initiate_transmit(int which); |
| 119 | | |
| 120 | | |
| 121 | | /* |
| 122 | | utilities |
| 123 | | */ |
| 124 | | |
| 125 | | |
| 126 | | /* |
| 127 | | initialize the tms9902 core |
| 128 | | */ |
| 129 | | void tms9902_init(running_machine *machine,int which, const tms9902reset_param *param) |
| 116 | INLINE tms9902_t *get_token(const device_config *device) |
| 130 | 117 | { |
| 131 | | tms9902[which].clock_rate = param->clock_rate; |
| 132 | | |
| 133 | | tms9902[which].int_callback = param->int_callback; |
| 134 | | tms9902[which].rts_callback = param->rts_callback; |
| 135 | | tms9902[which].brk_callback = param->brk_callback; |
| 136 | | tms9902[which].xmit_callback = param->xmit_callback; |
| 137 | | |
| 138 | | tms9902[which].timer = timer_alloc(machine, decrementer_callback, NULL); |
| 139 | | |
| 140 | | tms9902_reset(which); |
| 118 | assert(device != NULL); |
| 119 | assert(device->type == TMS9902); |
| 120 | return (tms9902_t *) device->token; |
| 141 | 121 | } |
| 142 | 122 | |
| 143 | 123 | |
| 144 | | void tms9902_cleanup(int which) |
| 145 | | { |
| 146 | | if (tms9902[which].timer) |
| 147 | | { |
| 148 | | timer_reset(tms9902[which].timer, attotime_never); /* FIXME - timers should only be allocated once */ |
| 149 | | tms9902[which].timer = NULL; |
| 150 | | } |
| 151 | | } |
| 152 | | |
| 153 | | void tms9902_reset(int which) |
| 154 | | { |
| 155 | | /* disable all interrupts */ |
| 156 | | tms9902[which].DSCENB = 0; |
| 157 | | tms9902[which].TIMENB = 0; |
| 158 | | tms9902[which].XBIENB = 0; |
| 159 | | tms9902[which].RIENB = 0; |
| 160 | | if (tms9902[which].int_callback) |
| 161 | | (*tms9902[which].int_callback)(which, 0); |
| 162 | | /* initialize transmitter */ |
| 163 | | tms9902[which].XBRE = 1; |
| 164 | | tms9902[which].XSRE = 1; |
| 165 | | /* initialize receiver */ |
| 166 | | tms9902[which].RBRL = 0; |
| 167 | | /* we probably need to clear receive error conditions, too... */ |
| 168 | | /* clear RTS */ |
| 169 | | tms9902[which].RTSON = 0; |
| 170 | | tms9902[which].RTS = 0; |
| 171 | | if (tms9902[which].rts_callback) |
| 172 | | (*tms9902[which].rts_callback)(which, 0); |
| 173 | | /* set all resister load flags to 1 */ |
| 174 | | tms9902[which].register_select = 0xf; |
| 175 | | /* clear break condition */ |
| 176 | | tms9902[which].BRKON = 0; |
| 177 | | tms9902[which].BRK = 0; |
| 178 | | if (tms9902[which].brk_callback) |
| 179 | | (*tms9902[which].brk_callback)(which, 0); |
| 180 | | field_interrupts(which); |
| 181 | | } |
| 182 | | |
| 183 | 124 | /* |
| 184 | 125 | should be called after any change to int_state or enabled_ints. |
| 185 | 126 | */ |
| 186 | | static void field_interrupts(int which) |
| 127 | static void field_interrupts(const device_config *device) |
| 187 | 128 | { |
| 188 | | int new_int = (tms9902[which].DSCH && tms9902[which].DSCENB) |
| 189 | | || (tms9902[which].RBRL && tms9902[which].RIENB) |
| 190 | | || (tms9902[which].XBRE && tms9902[which].XBIENB) |
| 191 | | || (tms9902[which].TIMELP && tms9902[which].TIMENB); |
| 129 | tms9902_t *tms9902 = get_token(device); |
| 130 | int new_int = (tms9902->DSCH && tms9902->DSCENB) |
| 131 | || (tms9902->RBRL && tms9902->RIENB) |
| 132 | || (tms9902->XBRE && tms9902->XBIENB) |
| 133 | || (tms9902->TIMELP && tms9902->TIMENB); |
| 192 | 134 | |
| 193 | | if (new_int != tms9902[which].INT) |
| 135 | if (new_int != tms9902->INT) |
| 194 | 136 | { |
| 195 | | tms9902[which].INT = new_int; |
| 137 | tms9902->INT = new_int; |
| 196 | 138 | |
| 197 | | if (tms9902[which].int_callback) |
| 198 | | (*tms9902[which].int_callback)(which, new_int); |
| 139 | if (tms9902->intf->int_callback) |
| 140 | (*tms9902->intf->int_callback)(device, new_int); |
| 199 | 141 | } |
| 200 | 142 | } |
| 201 | 143 | |
| 202 | 144 | |
| 203 | 145 | /* |
| 204 | | function which should be called by the driver when the state of CTS changes |
| 146 | function device should be called by the driver when the state of CTS changes |
| 205 | 147 | |
| 206 | 148 | state == 0: CTS* is inactive (high) |
| 207 | | state != 0: CTS* is active (low) |
| 149 | state != 0: CTS* is active (low) |
| 208 | 150 | */ |
| 209 | | void tms9902_set_cts(int which, int state) |
| 151 | void tms9902_set_cts(const device_config *device, int state) |
| 210 | 152 | { |
| 153 | tms9902_t *tms9902 = get_token(device); |
| 211 | 154 | state = state != 0; |
| 212 | 155 | |
| 213 | | if (state != tms9902[which].CTS) |
| 156 | if (state != tms9902->CTS) |
| 214 | 157 | { |
| 215 | | tms9902[which].CTS = state; |
| 216 | | tms9902[which].DSCH = 1; |
| 217 | | field_interrupts(which); |
| 158 | tms9902->CTS = state; |
| 159 | tms9902->DSCH = 1; |
| 160 | field_interrupts(device); |
| 218 | 161 | |
| 219 | | if (state && tms9902[which].RTS && tms9902[which].XSRE) |
| 162 | if (state && tms9902->RTS && tms9902->XSRE) |
| 220 | 163 | { |
| 221 | | if ((! tms9902[which].XBRE) && ! tms9902[which].BRK) |
| 222 | | initiate_transmit(which); |
| 223 | | else if (tms9902[which].BRKON) |
| 224 | | set_brk(which, 1); |
| 164 | if ((! tms9902->XBRE) && ! tms9902->BRK) |
| 165 | initiate_transmit(device); |
| 166 | else if (tms9902->BRKON) |
| 167 | set_brk(device, 1); |
| 225 | 168 | } |
| 226 | 169 | } |
| 227 | 170 | } |
| 228 | 171 | |
| 229 | 172 | |
| 230 | 173 | /* |
| 231 | | function which should be called by the driver when the state of DSR changes |
| 174 | function device should be called by the driver when the state of DSR changes |
| 232 | 175 | |
| 233 | 176 | state == 0: DSR* is inactive (high) |
| 234 | 177 | state != 0: DSR* is active (low) |
| 235 | 178 | */ |
| 236 | | void tms9902_set_dsr(int which, int state) |
| 179 | void tms9902_set_dsr(const device_config *device, int state) |
| 237 | 180 | { |
| 181 | tms9902_t *tms9902 = get_token(device); |
| 238 | 182 | state = state != 0; |
| 239 | 183 | |
| 240 | | if (state != tms9902[which].DSR) |
| 184 | if (state != tms9902->DSR) |
| 241 | 185 | { |
| 242 | | tms9902[which].DSR = state; |
| 243 | | tms9902[which].DSCH = 1; |
| 244 | | field_interrupts(which); |
| 186 | tms9902->DSR = state; |
| 187 | tms9902->DSCH = 1; |
| 188 | field_interrupts(device); |
| 245 | 189 | } |
| 246 | 190 | } |
| 247 | 191 | |
| 248 | 192 | |
| 249 | | void tms9902_push_data(int which, int data) |
| 193 | void tms9902_push_data(const device_config *device, int data) |
| 250 | 194 | { |
| 251 | | tms9902[which].RBR = data; |
| 195 | tms9902_t *tms9902 = get_token(device); |
| 196 | tms9902->RBR = data; |
| 252 | 197 | |
| 253 | | if (! tms9902[which].RBRL) |
| 198 | if (! tms9902->RBRL) |
| 254 | 199 | { |
| 255 | | tms9902[which].RBRL = 1; |
| 256 | | field_interrupts(which); |
| 200 | tms9902->RBRL = 1; |
| 201 | field_interrupts(device); |
| 257 | 202 | } |
| 258 | 203 | else |
| 259 | | tms9902[which].ROVER = 1; |
| 204 | tms9902->ROVER = 1; |
| 260 | 205 | } |
| 261 | 206 | |
| 262 | 207 | |
| r3833 | r3834 | |
| 266 | 211 | */ |
| 267 | 212 | static TIMER_CALLBACK(decrementer_callback) |
| 268 | 213 | { |
| 269 | | int which = param; |
| 270 | | if (tms9902[which].TIMELP) |
| 271 | | tms9902[which].TIMERR = 1; |
| 214 | const device_config *device = (const device_config *) ptr; |
| 215 | tms9902_t *tms9902 = get_token(device); |
| 216 | |
| 217 | if (tms9902->TIMELP) |
| 218 | tms9902->TIMERR = 1; |
| 272 | 219 | else |
| 273 | | tms9902[which].TIMELP = 1; |
| 220 | tms9902->TIMELP = 1; |
| 274 | 221 | } |
| 275 | 222 | |
| 276 | 223 | /* |
| 277 | 224 | load the content of clockinvl into the decrementer |
| 278 | 225 | */ |
| 279 | | static void reload_interval_timer(int which) |
| 226 | static void reload_interval_timer(const device_config *device) |
| 280 | 227 | { |
| 281 | | if (tms9902[which].TMR) |
| 228 | tms9902_t *tms9902 = get_token(device); |
| 229 | if (tms9902->TMR) |
| 282 | 230 | { /* reset clock interval */ |
| 283 | | timer_adjust_periodic(tms9902[which].timer, |
| 284 | | double_to_attotime((double) tms9902[which].TMR / (tms9902[which].clock_rate / ((tms9902[which].CLK4M) ? 4. : 3.) / 64.)), |
| 285 | | which, |
| 286 | | double_to_attotime((double) tms9902[which].TMR / (tms9902[which].clock_rate / ((tms9902[which].CLK4M) ? 4. : 3.) / 64.))); |
| 231 | timer_adjust_periodic(tms9902->timer, |
| 232 | double_to_attotime((double) tms9902->TMR / (tms9902->clock_rate / ((tms9902->CLK4M) ? 4. : 3.) / 64.)), |
| 233 | 0, |
| 234 | double_to_attotime((double) tms9902->TMR / (tms9902->clock_rate / ((tms9902->CLK4M) ? 4. : 3.) / 64.))); |
| 287 | 235 | } |
| 288 | 236 | else |
| 289 | 237 | { /* clock interval == 0 -> no timer */ |
| 290 | | timer_enable(tms9902[which].timer, 0); |
| 238 | timer_enable(tms9902->timer, 0); |
| 291 | 239 | } |
| 292 | 240 | } |
| 293 | 241 | |
| 294 | 242 | |
| 295 | | static void set_rts(int which, int state) |
| 243 | static void set_rts(const device_config *device, int state) |
| 296 | 244 | { |
| 245 | tms9902_t *tms9902 = get_token(device); |
| 297 | 246 | /*state = state != 0;*/ |
| 298 | 247 | |
| 299 | | if (state != tms9902[which].RTS) |
| 248 | if (state != tms9902->RTS) |
| 300 | 249 | { |
| 301 | | tms9902[which].RTS = state; |
| 250 | tms9902->RTS = state; |
| 302 | 251 | |
| 303 | | if (tms9902[which].rts_callback) |
| 304 | | (*tms9902[which].rts_callback)(which, state); |
| 252 | if (tms9902->intf->rts_callback) |
| 253 | (*tms9902->intf->rts_callback)(device, state); |
| 305 | 254 | } |
| 306 | 255 | } |
| 307 | 256 | |
| 308 | 257 | |
| 309 | | static void set_brk(int which, int state) |
| 258 | static void set_brk(const device_config *device, int state) |
| 310 | 259 | { |
| 260 | tms9902_t *tms9902 = get_token(device); |
| 311 | 261 | /*state = state != 0;*/ |
| 312 | 262 | |
| 313 | | if (state != tms9902[which].BRK) |
| 263 | if (state != tms9902->BRK) |
| 314 | 264 | { |
| 315 | | tms9902[which].BRK = state; |
| 265 | tms9902->BRK = state; |
| 316 | 266 | |
| 317 | | if (tms9902[which].brk_callback) |
| 318 | | (*tms9902[which].brk_callback)(which, state); |
| 267 | if (tms9902->intf->brk_callback) |
| 268 | (*tms9902->intf->brk_callback)(device, state); |
| 319 | 269 | } |
| 320 | 270 | } |
| 321 | 271 | |
| 322 | 272 | |
| 323 | | static void initiate_transmit(int which) |
| 273 | static void initiate_transmit(const device_config *device) |
| 324 | 274 | { |
| 275 | tms9902_t *tms9902 = get_token(device); |
| 276 | |
| 325 | 277 | /* Load transmit register */ |
| 326 | | tms9902[which].XSR = tms9902[which].XBR; |
| 327 | | tms9902[which].XSRE = 0; |
| 328 | | tms9902[which].XBRE = 1; |
| 329 | | field_interrupts(which); |
| 278 | tms9902->XSR = tms9902->XBR; |
| 279 | tms9902->XSRE = 0; |
| 280 | tms9902->XBRE = 1; |
| 281 | field_interrupts(device); |
| 330 | 282 | |
| 331 | 283 | /* Do transmit at once (I will add a timer delay some day, maybe) */ |
| 332 | 284 | |
| 333 | | if (tms9902[which].xmit_callback) |
| 334 | | (*tms9902[which].xmit_callback)(which, tms9902[which].XSR & (0xff >> (3-tms9902[which].RCL))); |
| 285 | if (tms9902->intf->xmit_callback) |
| 286 | (*tms9902->intf->xmit_callback)(device, tms9902->XSR & (0xff >> (3-tms9902->RCL))); |
| 335 | 287 | |
| 336 | | tms9902[which].XSRE = 1; |
| 288 | tms9902->XSRE = 1; |
| 337 | 289 | |
| 338 | | if ((! tms9902[which].XBRE) /*&& tms9902[which].RTS*/ && tms9902[which].CTS /*&& ! tms9902[which].BRK*/) |
| 290 | if ((! tms9902->XBRE) /*&& tms9902->RTS*/ && tms9902->CTS /*&& ! tms9902->BRK*/) |
| 339 | 291 | /* load next byte */ |
| 340 | | initiate_transmit(which); |
| 341 | | else if (tms9902[which].BRKON /*&& tms9902[which].RTS*/ && tms9902[which].CTS) |
| 292 | initiate_transmit(device); |
| 293 | else if (tms9902->BRKON /*&& tms9902->RTS*/ && tms9902->CTS) |
| 342 | 294 | /* enter break mode */ |
| 343 | | set_brk(which, 1); |
| 344 | | else if ((! tms9902[which].RTSON) && ((! tms9902[which].CTS) || (tms9902[which].XBRE && ! tms9902[which].BRK))) |
| 295 | set_brk(device, 1); |
| 296 | else if ((! tms9902->RTSON) && ((! tms9902->CTS) || (tms9902->XBRE && ! tms9902->BRK))) |
| 345 | 297 | /* clear RTS output */ |
| 346 | | set_rts(which, 0); |
| 298 | set_rts(device, 0); |
| 347 | 299 | } |
| 348 | 300 | |
| 349 | 301 | |
| r3833 | r3834 | |
| 365 | 317 | bit 13-15: not emulated, normally used for diagnostics |
| 366 | 318 | bit 16: RBINT (RBRL&RIENB) |
| 367 | 319 | */ |
| 368 | | int tms9902_cru_r(int which, int offset) |
| 320 | READ8_DEVICE_HANDLER( tms9902_cru_r ) |
| 369 | 321 | { |
| 370 | 322 | int answer = 0; |
| 323 | tms9902_t *tms9902 = get_token(device); |
| 371 | 324 | |
| 372 | 325 | offset &= 0x003; |
| 373 | 326 | |
| 374 | 327 | switch (offset) |
| 375 | 328 | { |
| 376 | 329 | case 0: |
| 377 | | answer = tms9902[which].RBR; |
| 330 | answer = tms9902->RBR; |
| 378 | 331 | break; |
| 379 | 332 | |
| 380 | 333 | case 1: |
| 381 | | answer = (tms9902[which].ROVER << 3) |
| 382 | | | (tms9902[which].ROVER << 1); |
| 334 | answer = (tms9902->ROVER << 3) |
| 335 | | (tms9902->ROVER << 1); |
| 383 | 336 | break; |
| 384 | 337 | |
| 385 | 338 | case 2: |
| 386 | | answer = (tms9902[which].XSRE << 7) |
| 387 | | | (tms9902[which].XBRE << 6) |
| 388 | | | (tms9902[which].RBRL << 5) |
| 389 | | | ((tms9902[which].DSCH & tms9902[which].DSCENB) << 4) |
| 390 | | | ((tms9902[which].TIMELP & tms9902[which].TIMENB) << 3) |
| 391 | | | ((tms9902[which].XBRE & tms9902[which].XBIENB) << 1) |
| 392 | | | (tms9902[which].RBRL & tms9902[which].RIENB); |
| 339 | answer = (tms9902->XSRE << 7) |
| 340 | | (tms9902->XBRE << 6) |
| 341 | | (tms9902->RBRL << 5) |
| 342 | | ((tms9902->DSCH & tms9902->DSCENB) << 4) |
| 343 | | ((tms9902->TIMELP & tms9902->TIMENB) << 3) |
| 344 | | ((tms9902->XBRE & tms9902->XBIENB) << 1) |
| 345 | | (tms9902->RBRL & tms9902->RIENB); |
| 393 | 346 | break; |
| 394 | 347 | |
| 395 | 348 | case 3: |
| 396 | | answer = (tms9902[which].INT << 7) |
| 397 | | | ((tms9902[which].register_select != 0) << 6) |
| 398 | | | (tms9902[which].DSCH << 5) |
| 399 | | | (tms9902[which].CTS << 4) |
| 400 | | | (tms9902[which].DSR << 3) |
| 401 | | | (tms9902[which].RTS << 2) |
| 402 | | | (tms9902[which].TIMELP << 1) |
| 403 | | | (tms9902[which].TIMERR); |
| 349 | answer = (tms9902->INT << 7) |
| 350 | | ((tms9902->register_select != 0) << 6) |
| 351 | | (tms9902->DSCH << 5) |
| 352 | | (tms9902->CTS << 4) |
| 353 | | (tms9902->DSR << 3) |
| 354 | | (tms9902->RTS << 2) |
| 355 | | (tms9902->TIMELP << 1) |
| 356 | | (tms9902->TIMERR); |
| 404 | 357 | break; |
| 405 | 358 | } |
| 406 | 359 | |
| r3833 | r3834 | |
| 413 | 366 | signification: |
| 414 | 367 | ... |
| 415 | 368 | */ |
| 416 | | void tms9902_cru_w(int which, int offset, int data) |
| 369 | WRITE8_DEVICE_HANDLER( tms9902_cru_w ) |
| 417 | 370 | { |
| 371 | tms9902_t *tms9902 = get_token(device); |
| 372 | |
| 418 | 373 | data &= 1; /* clear extra bits */ |
| 419 | 374 | offset &= 0x01F; |
| 420 | 375 | |
| r3833 | r3834 | |
| 435 | 390 | { |
| 436 | 391 | int mask = 1 << offset; |
| 437 | 392 | |
| 438 | | if (tms9902[which].register_select & register_select_LDCTRL) |
| 393 | if (tms9902->register_select & register_select_LDCTRL) |
| 439 | 394 | { /* Control Register */ |
| 440 | 395 | if (offset <= 7) |
| 441 | 396 | { |
| r3833 | r3834 | |
| 444 | 399 | case 0: |
| 445 | 400 | case 1: |
| 446 | 401 | if (data) |
| 447 | | tms9902[which].RCL |= mask; |
| 402 | tms9902->RCL |= mask; |
| 448 | 403 | else |
| 449 | | tms9902[which].RCL &= ~mask; |
| 404 | tms9902->RCL &= ~mask; |
| 450 | 405 | break; |
| 451 | 406 | |
| 452 | 407 | case 3: |
| 453 | | tms9902[which].CLK4M = data; |
| 408 | tms9902->CLK4M = data; |
| 454 | 409 | break; |
| 455 | 410 | |
| 456 | 411 | /* ... */ |
| 457 | 412 | } |
| 458 | 413 | |
| 459 | 414 | if (offset == 7) |
| 460 | | tms9902[which].register_select &= ~register_select_LDCTRL; |
| 415 | tms9902->register_select &= ~register_select_LDCTRL; |
| 461 | 416 | } |
| 462 | 417 | } |
| 463 | | else if (tms9902[which].register_select & register_select_LDIR) |
| 418 | else if (tms9902->register_select & register_select_LDIR) |
| 464 | 419 | { /* Interval Register */ |
| 465 | 420 | if (offset <= 7) |
| 466 | 421 | { |
| 467 | 422 | if (data) |
| 468 | | tms9902[which].TMR |= mask; |
| 423 | tms9902->TMR |= mask; |
| 469 | 424 | else |
| 470 | | tms9902[which].TMR &= ~mask; |
| 425 | tms9902->TMR &= ~mask; |
| 471 | 426 | |
| 472 | 427 | if (offset == 7) |
| 473 | 428 | { |
| 474 | | reload_interval_timer(which); |
| 475 | | tms9902[which].register_select &= ~register_select_LDIR; |
| 429 | reload_interval_timer(device); |
| 430 | tms9902->register_select &= ~register_select_LDIR; |
| 476 | 431 | } |
| 477 | 432 | } |
| 478 | 433 | } |
| 479 | | else if (tms9902[which].register_select & (register_select_LRDR | register_select_LXDR)) |
| 434 | else if (tms9902->register_select & (register_select_LRDR | register_select_LXDR)) |
| 480 | 435 | { /* Receive&Transmit Data Rate Register */ |
| 481 | 436 | if (offset < 10) |
| 482 | 437 | { |
| 483 | | if (tms9902[which].register_select & register_select_LRDR) |
| 438 | if (tms9902->register_select & register_select_LRDR) |
| 484 | 439 | { |
| 485 | 440 | if (data) |
| 486 | | tms9902[which].RDR |= mask; |
| 441 | tms9902->RDR |= mask; |
| 487 | 442 | else |
| 488 | | tms9902[which].RDR &= ~mask; |
| 443 | tms9902->RDR &= ~mask; |
| 489 | 444 | } |
| 490 | | if (tms9902[which].register_select & register_select_LXDR) |
| 445 | if (tms9902->register_select & register_select_LXDR) |
| 491 | 446 | { |
| 492 | 447 | if (data) |
| 493 | | tms9902[which].XDR |= mask; |
| 448 | tms9902->XDR |= mask; |
| 494 | 449 | else |
| 495 | | tms9902[which].XDR &= ~mask; |
| 450 | tms9902->XDR &= ~mask; |
| 496 | 451 | } |
| 497 | 452 | } |
| 498 | 453 | else if (offset == 10) |
| 499 | 454 | { |
| 500 | | if (tms9902[which].register_select & register_select_LRDR) |
| 501 | | tms9902[which].RDV8 = data; |
| 502 | | if (tms9902[which].register_select & register_select_LXDR) |
| 503 | | tms9902[which].XDV8 = data; |
| 455 | if (tms9902->register_select & register_select_LRDR) |
| 456 | tms9902->RDV8 = data; |
| 457 | if (tms9902->register_select & register_select_LXDR) |
| 458 | tms9902->XDV8 = data; |
| 504 | 459 | |
| 505 | 460 | /* set data rate */ |
| 506 | 461 | /* ... */ |
| 507 | 462 | |
| 508 | | tms9902[which].register_select &= ~ (register_select_LRDR | register_select_LXDR); |
| 463 | tms9902->register_select &= ~ (register_select_LRDR | register_select_LXDR); |
| 509 | 464 | } |
| 510 | 465 | } |
| 511 | 466 | else |
| r3833 | r3834 | |
| 513 | 468 | if (offset <= 7) |
| 514 | 469 | { |
| 515 | 470 | if (data) |
| 516 | | tms9902[which].XBR |= mask; |
| 471 | tms9902->XBR |= mask; |
| 517 | 472 | else |
| 518 | | tms9902[which].XBR &= ~mask; |
| 473 | tms9902->XBR &= ~mask; |
| 519 | 474 | |
| 520 | 475 | if (offset == 7) |
| 521 | 476 | { /* transmit */ |
| 522 | | tms9902[which].XBRE = 0; |
| 523 | | if (tms9902[which].XSRE && tms9902[which].RTS && tms9902[which].CTS && ! tms9902[which].BRK) |
| 477 | tms9902->XBRE = 0; |
| 478 | if (tms9902->XSRE && tms9902->RTS && tms9902->CTS && ! tms9902->BRK) |
| 524 | 479 | { |
| 525 | | initiate_transmit(which); |
| 480 | initiate_transmit(device); |
| 526 | 481 | } |
| 527 | 482 | } |
| 528 | 483 | } |
| r3833 | r3834 | |
| 537 | 492 | { |
| 538 | 493 | int mask = 1 << (offset - 0x0B); |
| 539 | 494 | |
| 540 | | if ((offset == 0x0D) && (! data) && (tms9902[which].register_select & register_select_LDIR)) |
| 495 | if ((offset == 0x0D) && (! data) && (tms9902->register_select & register_select_LDIR)) |
| 541 | 496 | /* clearing LDIR reloads the interval timer (right???) */ |
| 542 | | reload_interval_timer(which); |
| 497 | reload_interval_timer(device); |
| 543 | 498 | |
| 544 | 499 | if (data) |
| 545 | | tms9902[which].register_select |= mask; |
| 500 | tms9902->register_select |= mask; |
| 546 | 501 | else |
| 547 | | tms9902[which].register_select &= ~mask; |
| 502 | tms9902->register_select &= ~mask; |
| 548 | 503 | } |
| 549 | 504 | break; |
| 550 | 505 | |
| r3833 | r3834 | |
| 553 | 508 | break; |
| 554 | 509 | |
| 555 | 510 | case 0x10: /* RTSON */ |
| 556 | | tms9902[which].RTSON = data; |
| 557 | | if (data || (tms9902[which].XBRE && tms9902[which].XSRE && ! tms9902[which].BRK)) |
| 511 | tms9902->RTSON = data; |
| 512 | if (data || (tms9902->XBRE && tms9902->XSRE && ! tms9902->BRK)) |
| 558 | 513 | { |
| 559 | | set_rts(which, data); |
| 560 | | if (data && tms9902[which].CTS) |
| 514 | set_rts(device, data); |
| 515 | if (data && tms9902->CTS) |
| 561 | 516 | { |
| 562 | | if (tms9902[which].XSRE && (! tms9902[which].XBRE) && ! tms9902[which].BRK) |
| 563 | | initiate_transmit(which); |
| 564 | | else if (tms9902[which].BRKON) |
| 565 | | set_brk(which, 1); |
| 517 | if (tms9902->XSRE && (! tms9902->XBRE) && ! tms9902->BRK) |
| 518 | initiate_transmit(device); |
| 519 | else if (tms9902->BRKON) |
| 520 | set_brk(device, 1); |
| 566 | 521 | } |
| 567 | 522 | } |
| 568 | 523 | break; |
| 569 | 524 | |
| 570 | 525 | case 0x11: /* BRKON */ |
| 571 | | tms9902[which].BRKON = data; |
| 572 | | if (tms9902[which].BRK && ! data) |
| 526 | tms9902->BRKON = data; |
| 527 | if (tms9902->BRK && ! data) |
| 573 | 528 | { |
| 574 | | tms9902[which].BRK = 0; |
| 575 | | if ((! tms9902[which].XBRE) && tms9902[which].CTS) |
| 529 | tms9902->BRK = 0; |
| 530 | if ((! tms9902->XBRE) && tms9902->CTS) |
| 576 | 531 | /* transmit next byte */ |
| 577 | | initiate_transmit(which); |
| 578 | | else if (! tms9902[which].RTSON) |
| 532 | initiate_transmit(device); |
| 533 | else if (! tms9902->RTSON) |
| 579 | 534 | /* clear RTS */ |
| 580 | | set_rts(which, 0); |
| 535 | set_rts(device, 0); |
| 581 | 536 | } |
| 582 | | else if (tms9902[which].XBRE && tms9902[which].XSRE && tms9902[which].RTS && tms9902[which].CTS) |
| 537 | else if (tms9902->XBRE && tms9902->XSRE && tms9902->RTS && tms9902->CTS) |
| 583 | 538 | { |
| 584 | | set_brk(which, data); |
| 539 | set_brk(device, data); |
| 585 | 540 | } |
| 586 | 541 | break; |
| 587 | 542 | |
| 588 | 543 | case 0x12: /* RIENB */ |
| 589 | | tms9902[which].RIENB = data; |
| 590 | | tms9902[which].RBRL = 0; |
| 591 | | field_interrupts(which); |
| 544 | tms9902->RIENB = data; |
| 545 | tms9902->RBRL = 0; |
| 546 | field_interrupts(device); |
| 592 | 547 | break; |
| 593 | 548 | |
| 594 | 549 | case 0x13: /* XBIENB */ |
| 595 | | tms9902[which].XBIENB = data; |
| 596 | | field_interrupts(which); |
| 550 | tms9902->XBIENB = data; |
| 551 | field_interrupts(device); |
| 597 | 552 | break; |
| 598 | 553 | |
| 599 | 554 | case 0x14: /* TIMENB */ |
| 600 | | tms9902[which].TIMENB = data; |
| 601 | | tms9902[which].TIMELP = 0; |
| 602 | | tms9902[which].TIMERR = 0; |
| 603 | | field_interrupts(which); |
| 555 | tms9902->TIMENB = data; |
| 556 | tms9902->TIMELP = 0; |
| 557 | tms9902->TIMERR = 0; |
| 558 | field_interrupts(device); |
| 604 | 559 | break; |
| 605 | 560 | |
| 606 | 561 | case 0x15: /* DSCENB */ |
| 607 | | tms9902[which].DSCENB = data; |
| 608 | | tms9902[which].DSCH = 0; |
| 609 | | field_interrupts(which); |
| 562 | tms9902->DSCENB = data; |
| 563 | tms9902->DSCH = 0; |
| 564 | field_interrupts(device); |
| 610 | 565 | break; |
| 611 | 566 | |
| 612 | 567 | case 0x1F: /* RESET */ |
| 613 | | tms9902_reset(which); |
| 568 | device_reset_tms9902(device); |
| 614 | 569 | break; |
| 615 | 570 | } |
| 616 | 571 | } |
| 617 | 572 | |
| 618 | 573 | |
| 619 | | READ8_HANDLER ( tms9902_0_cru_r ) |
| 574 | /*------------------------------------------------- |
| 575 | DEVICE_STOP( tms9902 ) |
| 576 | -------------------------------------------------*/ |
| 577 | |
| 578 | static DEVICE_STOP( tms9902 ) |
| 620 | 579 | { |
| 621 | | return tms9902_cru_r(0, offset); |
| 580 | tms9902_t *tms9902 = get_token(device); |
| 581 | |
| 582 | if (tms9902->timer) |
| 583 | { |
| 584 | timer_reset(tms9902->timer, attotime_never); /* FIXME - timers should only be allocated once */ |
| 585 | tms9902->timer = NULL; |
| 586 | } |
| 622 | 587 | } |
| 623 | 588 | |
| 624 | | WRITE8_HANDLER ( tms9902_0_cru_w ) |
| 589 | /*------------------------------------------------- |
| 590 | DEVICE_RESET( tms9902 ) |
| 591 | -------------------------------------------------*/ |
| 592 | |
| 593 | static DEVICE_RESET( tms9902 ) |
| 625 | 594 | { |
| 626 | | tms9902_cru_w(0, offset, data); |
| 595 | tms9902_t *tms9902 = get_token(device); |
| 596 | |
| 597 | /* disable all interrupts */ |
| 598 | tms9902->DSCENB = 0; |
| 599 | tms9902->TIMENB = 0; |
| 600 | tms9902->XBIENB = 0; |
| 601 | tms9902->RIENB = 0; |
| 602 | if (tms9902->intf->int_callback) |
| 603 | (*tms9902->intf->int_callback)(device, 0); |
| 604 | /* initialize transmitter */ |
| 605 | tms9902->XBRE = 1; |
| 606 | tms9902->XSRE = 1; |
| 607 | /* initialize receiver */ |
| 608 | tms9902->RBRL = 0; |
| 609 | /* we probably need to clear receive error conditions, too... */ |
| 610 | /* clear RTS */ |
| 611 | tms9902->RTSON = 0; |
| 612 | tms9902->RTS = 0; |
| 613 | if (tms9902->intf->rts_callback) |
| 614 | (*tms9902->intf->rts_callback)(device, 0); |
| 615 | /* set all resister load flags to 1 */ |
| 616 | tms9902->register_select = 0xf; |
| 617 | /* clear break condition */ |
| 618 | tms9902->BRKON = 0; |
| 619 | tms9902->BRK = 0; |
| 620 | if (tms9902->intf->brk_callback) |
| 621 | (*tms9902->intf->brk_callback)(device, 0); |
| 622 | field_interrupts(device); |
| 623 | |
| 627 | 624 | } |
| 625 | |
| 626 | |
| 627 | /*------------------------------------------------- |
| 628 | DEVICE_START( tms9902 ) |
| 629 | -------------------------------------------------*/ |
| 630 | |
| 631 | static DEVICE_START( tms9902 ) |
| 632 | { |
| 633 | tms9902_t *tms9902 = get_token(device); |
| 634 | |
| 635 | assert(device != NULL); |
| 636 | assert(device->tag != NULL); |
| 637 | assert(strlen(device->tag) < 20); |
| 638 | assert(device->static_config != NULL); |
| 639 | |
| 640 | tms9902->intf = device->static_config; |
| 641 | |
| 642 | tms9902->clock_rate = tms9902->intf->clock_rate; |
| 643 | |
| 644 | tms9902->timer = timer_alloc(device->machine, decrementer_callback, (void *) device); |
| 645 | |
| 646 | return DEVICE_START_OK; |
| 647 | } |
| 648 | |
| 649 | |
| 650 | |
| 651 | /*------------------------------------------------- |
| 652 | DEVICE_SET_INFO( tms9902 ) |
| 653 | -------------------------------------------------*/ |
| 654 | |
| 655 | static DEVICE_SET_INFO( tms9902 ) |
| 656 | { |
| 657 | switch (state) |
| 658 | { |
| 659 | /* no parameters to set */ |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | |
| 664 | |
| 665 | /*------------------------------------------------- |
| 666 | DEVICE_GET_INFO( tms9902 ) |
| 667 | -------------------------------------------------*/ |
| 668 | |
| 669 | DEVICE_GET_INFO( tms9902 ) |
| 670 | { |
| 671 | switch (state) |
| 672 | { |
| 673 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 674 | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(tms9902_t); break; |
| 675 | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 676 | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break; |
| 677 | |
| 678 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 679 | case DEVINFO_FCT_SET_INFO: info->set_info = DEVICE_SET_INFO_NAME(tms9902); break; |
| 680 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(tms9902); break; |
| 681 | case DEVINFO_FCT_STOP: info->stop = DEVICE_STOP_NAME (tms9902); break; |
| 682 | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(tms9902); break; |
| 683 | |
| 684 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 685 | case DEVINFO_STR_NAME: info->s = "TMS9902"; break; |
| 686 | case DEVINFO_STR_FAMILY: info->s = "TMS9902"; break; |
| 687 | case DEVINFO_STR_VERSION: info->s = "1.0"; break; |
| 688 | case DEVINFO_STR_SOURCE_FILE: info->s = __FILE__; break; |
| 689 | case DEVINFO_STR_CREDITS: /* Nothing */ break; |
| 690 | } |
| 691 | } |
src/mess/machine/994x_ser.c
| r3833 | r3834 | |
| 29 | 29 | #define MAX_RS232_CARDS 1/*2*/ |
| 30 | 30 | |
| 31 | 31 | /* prototypes */ |
| 32 | | static void int_callback(int which, int INT); |
| 33 | | static void xmit_callback(int which, int data); |
| 34 | 32 | static int rs232_cru_r(running_machine *machine, int offset); |
| 35 | 33 | static void rs232_cru_w(running_machine *machine, int offset, int data); |
| 36 | 34 | static READ8_HANDLER(rs232_mem_r); |
| 37 | 35 | static WRITE8_HANDLER(rs232_mem_w); |
| 38 | | static void ti99_rs232_cleanup(running_machine *machine); |
| 39 | 36 | |
| 40 | 37 | /* pointer to the rs232 ROM data */ |
| 41 | 38 | static UINT8 *rs232_DSR; |
| r3833 | r3834 | |
| 67 | 64 | rs232_mem_w |
| 68 | 65 | }; |
| 69 | 66 | |
| 70 | | static const tms9902reset_param tms9902_params = |
| 71 | | { |
| 72 | | 3000000., /* clock rate (3MHz) */ |
| 73 | | int_callback, /* called when interrupt pin state changes */ |
| 74 | | NULL,//rts_callback, /* called when Request To Send pin state changes */ |
| 75 | | NULL,//brk_callback, /* called when BReaK state changes */ |
| 76 | | xmit_callback /* called when a character is transmitted */ |
| 77 | | }; |
| 78 | | |
| 79 | | |
| 80 | | |
| 81 | 67 | /* |
| 82 | 68 | Initialize pio unit and open image |
| 83 | 69 | */ |
| r3833 | r3834 | |
| 120 | 106 | */ |
| 121 | 107 | DEVICE_IMAGE_LOAD( ti99_4_rs232 ) |
| 122 | 108 | { |
| 109 | const device_config *tms9902 = NULL; |
| 110 | |
| 123 | 111 | int id = image_index_in_device(image); |
| 124 | 112 | |
| 125 | 113 | /*if ((id < 0) || (id >= 2*MAX_RS232_CARDS)) |
| 126 | 114 | return INIT_FAIL;*/ |
| 127 | 115 | if (id != 0) |
| 128 | 116 | return INIT_FAIL; |
| 129 | | |
| 117 | |
| 118 | if (id==0) { |
| 119 | tms9902 = device_list_find_by_tag(image->machine->config->devicelist, TMS9902, "tms9902_0"); |
| 120 | } |
| 121 | if (id==1) { |
| 122 | tms9902 = device_list_find_by_tag(image->machine->config->devicelist, TMS9902, "tms9902_1"); |
| 123 | } |
| 124 | |
| 130 | 125 | rs232_fp = image; |
| 131 | 126 | |
| 132 | 127 | if (rs232_fp) |
| 133 | 128 | { |
| 134 | | tms9902_set_cts(id, 1); |
| 135 | | tms9902_set_dsr(id, 1); |
| 129 | tms9902_set_cts(tms9902, 1); |
| 130 | tms9902_set_dsr(tms9902, 1); |
| 136 | 131 | } |
| 137 | 132 | else |
| 138 | 133 | { |
| 139 | | tms9902_set_cts(id, 0); |
| 140 | | tms9902_set_dsr(id, 0); |
| 134 | tms9902_set_cts(tms9902, 0); |
| 135 | tms9902_set_dsr(tms9902, 0); |
| 141 | 136 | } |
| 142 | 137 | |
| 143 | 138 | return INIT_PASS; |
| r3833 | r3834 | |
| 164 | 159 | void ti99_rs232_init(running_machine *machine) |
| 165 | 160 | { |
| 166 | 161 | rs232_DSR = memory_region(machine, region_dsr) + offset_rs232_dsr; |
| 167 | | tms9902_init(machine, 0, &tms9902_params); |
| 168 | | tms9902_init(machine, 1, &tms9902_params); |
| 169 | | |
| 170 | | add_exit_callback(machine, ti99_rs232_cleanup); |
| 171 | 162 | } |
| 172 | 163 | |
| 173 | 164 | /* |
| r3833 | r3834 | |
| 186 | 177 | cts1 = 0; |
| 187 | 178 | cts2 = 0; |
| 188 | 179 | led = 0; |
| 189 | | tms9902_reset(0); |
| 190 | | tms9902_reset(1); |
| 191 | 180 | } |
| 192 | 181 | |
| 193 | 182 | /* |
| 194 | | rs232 card clean-up |
| 183 | rs232 interrupt handler |
| 195 | 184 | */ |
| 196 | | static void ti99_rs232_cleanup(running_machine *machine) |
| 185 | static TMS9902_INT_CALLBACK( int_callback_0 ) |
| 197 | 186 | { |
| 198 | | tms9902_cleanup(0); |
| 199 | | tms9902_cleanup(1); |
| 187 | ti99_peb_set_ila_bit(inta_rs232_1_bit, INT); |
| 200 | 188 | } |
| 201 | 189 | |
| 202 | | /* |
| 203 | | rs232 interrupt handler |
| 204 | | */ |
| 205 | | static void int_callback(int which, int INT) |
| 190 | static TMS9902_INT_CALLBACK( int_callback_1 ) |
| 206 | 191 | { |
| 207 | | switch (which) |
| 208 | | { |
| 209 | | case 0: |
| 210 | | ti99_peb_set_ila_bit(inta_rs232_1_bit, INT); |
| 211 | | break; |
| 192 | ti99_peb_set_ila_bit(inta_rs232_2_bit, INT); |
| 193 | } |
| 212 | 194 | |
| 213 | | case 1: |
| 214 | | ti99_peb_set_ila_bit(inta_rs232_2_bit, INT); |
| 215 | | break; |
| 195 | static TMS9902_XMIT_CALLBACK( xmit_callback_0 ) |
| 196 | { |
| 197 | UINT8 buf = data; |
| 216 | 198 | |
| 217 | | case 2: |
| 218 | | ti99_peb_set_ila_bit(inta_rs232_3_bit, INT); |
| 219 | | break; |
| 220 | | |
| 221 | | case 3: |
| 222 | | ti99_peb_set_ila_bit(inta_rs232_4_bit, INT); |
| 223 | | break; |
| 224 | | } |
| 199 | if (rs232_fp) |
| 200 | image_fwrite(rs232_fp, &buf, 1); |
| 225 | 201 | } |
| 226 | 202 | |
| 227 | | static void xmit_callback(int which, int data) |
| 203 | static TMS9902_XMIT_CALLBACK( xmit_callback_1 ) |
| 228 | 204 | { |
| 229 | 205 | UINT8 buf = data; |
| 230 | 206 | |
| r3833 | r3834 | |
| 232 | 208 | image_fwrite(rs232_fp, &buf, 1); |
| 233 | 209 | } |
| 234 | 210 | |
| 211 | |
| 235 | 212 | /* |
| 236 | 213 | Read rs232 card CRU interface |
| 237 | 214 | |
| r3833 | r3834 | |
| 274 | 251 | |
| 275 | 252 | case 1: |
| 276 | 253 | /* first 9902 */ |
| 277 | | reply = tms9902_cru_r(0, offset); |
| 254 | reply = tms9902_cru_r(device_list_find_by_tag(machine->config->devicelist, TMS9902, "tms9902_0"), offset); |
| 278 | 255 | break; |
| 279 | 256 | |
| 280 | 257 | case 2: |
| 281 | 258 | /* second 9902 */ |
| 282 | | reply = tms9902_cru_r(1, offset); |
| 259 | reply = tms9902_cru_r(device_list_find_by_tag(machine->config->devicelist, TMS9902, "tms9902_1"), offset); |
| 283 | 260 | break; |
| 284 | 261 | |
| 285 | 262 | default: |
| r3833 | r3834 | |
| 375 | 352 | |
| 376 | 353 | case 1: |
| 377 | 354 | /* first 9902 */ |
| 378 | | tms9902_cru_w(0, offset, data); |
| 355 | tms9902_cru_w(device_list_find_by_tag(machine->config->devicelist, TMS9902, "tms9902_0"), offset, data); |
| 379 | 356 | break; |
| 380 | 357 | |
| 381 | 358 | case 2: |
| 382 | 359 | /* second 9902 */ |
| 383 | | tms9902_cru_w(1, offset, data); |
| 360 | tms9902_cru_w(device_list_find_by_tag(machine->config->devicelist, TMS9902, "tms9902_1"), offset, data); |
| 384 | 361 | break; |
| 385 | 362 | |
| 386 | 363 | default: |
| r3833 | r3834 | |
| 426 | 403 | /* DSR ROM: do nothing */ |
| 427 | 404 | } |
| 428 | 405 | } |
| 406 | |
| 407 | const tms9902_interface tms9902_params_0 = |
| 408 | { |
| 409 | 3000000., /* clock rate (3MHz) */ |
| 410 | int_callback_0, /* called when interrupt pin state changes */ |
| 411 | NULL,//rts_callback, /* called when Request To Send pin state changes */ |
| 412 | NULL,//brk_callback, /* called when BReaK state changes */ |
| 413 | xmit_callback_0 /* called when a character is transmitted */ |
| 414 | }; |
| 415 | |
| 416 | const tms9902_interface tms9902_params_1 = |
| 417 | { |
| 418 | 3000000., /* clock rate (3MHz) */ |
| 419 | int_callback_1, /* called when interrupt pin state changes */ |
| 420 | NULL,//rts_callback, /* called when Request To Send pin state changes */ |
| 421 | NULL,//brk_callback, /* called when BReaK state changes */ |
| 422 | xmit_callback_1 /* called when a character is transmitted */ |
| 423 | }; |
src/mess/drivers/tm990189.c
| r3833 | r3834 | |
| 80 | 80 | |
| 81 | 81 | static void hold_load(running_machine *machine); |
| 82 | 82 | |
| 83 | | static void rts_callback(int which, int RTS); |
| 84 | | static void xmit_callback(int which, int data); |
| 85 | 83 | |
| 86 | | static const tms9902reset_param tms9902_params = |
| 87 | | { |
| 88 | | 2000000., /* clock rate (2MHz) */ |
| 89 | | NULL,/*int_callback,*/ /* called when interrupt pin state changes */ |
| 90 | | rts_callback, /* called when Request To Send pin state changes */ |
| 91 | | NULL,/*brk_callback,*/ /* called when BReaK state changes */ |
| 92 | | xmit_callback /* called when a character is transmitted */ |
| 93 | | }; |
| 94 | | |
| 95 | 84 | static const device_config *rs232_fp; |
| 96 | 85 | static UINT8 rs232_rts; |
| 97 | 86 | static emu_timer *rs232_input_timer; |
| r3833 | r3834 | |
| 101 | 90 | displayena_timer = timer_alloc(machine, NULL, NULL); |
| 102 | 91 | |
| 103 | 92 | hold_load(machine); |
| 104 | | |
| 105 | | tms9902_init(machine, 0, &tms9902_params); |
| 106 | 93 | } |
| 107 | 94 | |
| 108 | 95 | static const TMS9928a_interface tms9918_interface = |
| r3833 | r3834 | |
| 128 | 115 | joy2y_timer = timer_alloc(machine, NULL, NULL); |
| 129 | 116 | |
| 130 | 117 | hold_load(machine); |
| 131 | | |
| 132 | | tms9902_init(machine, 0, &tms9902_params); |
| 133 | | |
| 118 | |
| 134 | 119 | TMS9928A_reset(); |
| 135 | 120 | } |
| 136 | 121 | |
| r3833 | r3834 | |
| 278 | 263 | tms9901 code |
| 279 | 264 | */ |
| 280 | 265 | |
| 281 | | static TMS9910_INT_CALLBACK ( usr9901_interrupt_callback ) |
| 266 | static TMS9901_INT_CALLBACK ( usr9901_interrupt_callback ) |
| 282 | 267 | { |
| 283 | 268 | ic_state = ic & 7; |
| 284 | 269 | |
| r3833 | r3834 | |
| 294 | 279 | LED_state &= ~(1 << offset); |
| 295 | 280 | } |
| 296 | 281 | |
| 297 | | static TMS9910_INT_CALLBACK( sys9901_interrupt_callback ) |
| 282 | static TMS9901_INT_CALLBACK( sys9901_interrupt_callback ) |
| 298 | 283 | { |
| 299 | 284 | (void)ic; |
| 300 | 285 | |
| r3833 | r3834 | |
| 375 | 360 | if (/*rs232_rts &&*/ /*(mame_ftell(rs232_fp) < mame_fsize(rs232_fp))*/1) |
| 376 | 361 | { |
| 377 | 362 | if (image_fread(rs232_fp, &buf, 1) == 1) |
| 378 | | tms9902_push_data(0, buf); |
| 363 | tms9902_push_data(device_list_find_by_tag(machine->config->devicelist, TMS9902, "tms9902"), buf); |
| 379 | 364 | } |
| 380 | 365 | } |
| 381 | 366 | |
| r3833 | r3834 | |
| 391 | 376 | |
| 392 | 377 | rs232_fp = image; |
| 393 | 378 | |
| 394 | | tms9902_set_dsr(id, 1); |
| 379 | tms9902_set_dsr(device_list_find_by_tag(image->machine->config->devicelist, TMS9902, "tms9902"), 1); |
| 395 | 380 | rs232_input_timer = timer_alloc(image->machine, rs232_input_callback, NULL); |
| 396 | 381 | timer_adjust_periodic(rs232_input_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(10)); |
| 397 | 382 | |
| r3833 | r3834 | |
| 410 | 395 | |
| 411 | 396 | rs232_fp = NULL; |
| 412 | 397 | |
| 413 | | tms9902_set_dsr(id, 0); |
| 398 | tms9902_set_dsr(device_list_find_by_tag(image->machine->config->devicelist, TMS9902, "tms9902"), 0); |
| 414 | 399 | |
| 415 | 400 | timer_reset(rs232_input_timer, attotime_never); /* FIXME - timers should only be allocated once */ |
| 416 | 401 | } |
| 417 | 402 | |
| 418 | | static void rts_callback(int which, int RTS) |
| 403 | static TMS9902_RST_CALLBACK( rts_callback ) |
| 419 | 404 | { |
| 420 | 405 | rs232_rts = RTS; |
| 421 | | tms9902_set_cts(which, RTS); |
| 406 | tms9902_set_cts(device, RTS); |
| 422 | 407 | } |
| 423 | 408 | |
| 424 | | static void xmit_callback(int which, int data) |
| 409 | static TMS9902_XMIT_CALLBACK( xmit_callback ) |
| 425 | 410 | { |
| 426 | 411 | UINT8 buf = data; |
| 427 | 412 | |
| r3833 | r3834 | |
| 657 | 642 | 0x3000-0x3fff: 4kb onboard ROM |
| 658 | 643 | */ |
| 659 | 644 | |
| 645 | static const tms9902_interface tms9902_params = |
| 646 | { |
| 647 | 2000000., /* clock rate (2MHz) */ |
| 648 | NULL,/*int_callback,*/ /* called when interrupt pin state changes */ |
| 649 | rts_callback, /* called when Request To Send pin state changes */ |
| 650 | NULL,/*brk_callback,*/ /* called when BReaK state changes */ |
| 651 | xmit_callback /* called when a character is transmitted */ |
| 652 | }; |
| 653 | |
| 660 | 654 | static ADDRESS_MAP_START(tm990_189_memmap, ADDRESS_SPACE_PROGRAM, 8) |
| 661 | 655 | |
| 662 | 656 | AM_RANGE(0x0000, 0x07ff) AM_RAM /* RAM */ |
| r3833 | r3834 | |
| 737 | 731 | static ADDRESS_MAP_START(tm990_189_writecru, ADDRESS_SPACE_IO, 8) |
| 738 | 732 | AM_RANGE(0x000, 0x1ff) AM_DEVWRITE(TMS9901, "tms9901_0", tms9901_cru_w) /* user I/O tms9901 */ |
| 739 | 733 | AM_RANGE(0x200, 0x3ff) AM_DEVWRITE(TMS9901, "tms9901_1", tms9901_cru_w) /* system I/O tms9901 */ |
| 740 | | AM_RANGE(0x400, 0x5ff) AM_WRITE(tms9902_0_cru_w) /* optional tms9902 */ |
| 734 | AM_RANGE(0x400, 0x5ff) AM_DEVWRITE(TMS9902, "tms9902", tms9902_cru_w) /* optional tms9902 */ |
| 741 | 735 | |
| 742 | 736 | AM_RANGE(0x0800,0x1fff)AM_WRITE(ext_instr_decode) /* external instruction decoding (IDLE, RSET, CKON, CKOF, LREX) */ |
| 743 | 737 | ADDRESS_MAP_END |
| r3833 | r3834 | |
| 745 | 739 | static ADDRESS_MAP_START(tm990_189_readcru, ADDRESS_SPACE_IO, 8) |
| 746 | 740 | AM_RANGE(0x00, 0x3f) AM_DEVREAD(TMS9901, "tms9901_0", tms9901_cru_r) /* user I/O tms9901 */ |
| 747 | 741 | AM_RANGE(0x40, 0x6f) AM_DEVREAD(TMS9901, "tms9901_1", tms9901_cru_r) /* system I/O tms9901 */ |
| 748 | | AM_RANGE(0x80, 0xcf) AM_READ(tms9902_0_cru_r) /* optional tms9902 */ |
| 742 | AM_RANGE(0x80, 0xcf) AM_DEVREAD(TMS9902, "tms9902", tms9902_cru_r) /* optional tms9902 */ |
| 749 | 743 | |
| 750 | 744 | ADDRESS_MAP_END |
| 751 | 745 | |
| r3833 | r3834 | |
| 792 | 786 | |
| 793 | 787 | MDRV_CASSETTE_ADD( "cassette", default_cassette_config ) |
| 794 | 788 | |
| 789 | /* tms9901 */ |
| 795 | 790 | MDRV_TMS9901_ADD("tms9901_0", usr9901reset_param) |
| 796 | 791 | MDRV_TMS9901_ADD("tms9901_1", sys9901reset_param) |
| 792 | /* tms9902 */ |
| 793 | MDRV_TMS9902_ADD("tms9902", tms9902_params) |
| 797 | 794 | MACHINE_DRIVER_END |
| 798 | 795 | |
| 799 | 796 | #define LEFT_BORDER 15 |
| r3833 | r3834 | |
| 833 | 830 | |
| 834 | 831 | MDRV_CASSETTE_ADD( "cassette", default_cassette_config ) |
| 835 | 832 | |
| 833 | /* tms9901 */ |
| 836 | 834 | MDRV_TMS9901_ADD("tms9901_0", usr9901reset_param) |
| 837 | | MDRV_TMS9901_ADD("tms9901_1", sys9901reset_param) |
| 835 | MDRV_TMS9901_ADD("tms9901_1", sys9901reset_param) |
| 836 | /* tms9902 */ |
| 837 | MDRV_TMS9902_ADD("tms9902", tms9902_params) |
| 838 | 838 | MACHINE_DRIVER_END |
| 839 | 839 | |
| 840 | 840 | |