src/mess/machine/cdp1871.c
| r9419 | r9420 | |
| 9 | 9 | |
| 10 | 10 | #include "emu.h" |
| 11 | 11 | #include "cdp1871.h" |
| 12 | #include "cpu/mcs48/mcs48.h" |
| 13 | #include "machine/devhelpr.h" |
| 12 | 14 | |
| 13 | | /*************************************************************************** |
| 14 | | PARAMETERS |
| 15 | | ***************************************************************************/ |
| 16 | 15 | |
| 16 | |
| 17 | //************************************************************************** |
| 18 | // MACROS / CONSTANTS |
| 19 | //************************************************************************** |
| 20 | |
| 17 | 21 | static const UINT8 CDP1871_KEY_CODES[4][11][8] = |
| 18 | 22 | { |
| 19 | 23 | // normal |
| r9419 | r9420 | |
| 77 | 81 | } |
| 78 | 82 | }; |
| 79 | 83 | |
| 80 | | /*************************************************************************** |
| 81 | | TYPE DEFINITIONS |
| 82 | | ***************************************************************************/ |
| 83 | 84 | |
| 84 | | typedef struct _cdp1871_t cdp1871_t; |
| 85 | | struct _cdp1871_t |
| 85 | |
| 86 | //************************************************************************** |
| 87 | // DEVICE DEFINITIONS |
| 88 | //************************************************************************** |
| 89 | |
| 90 | const device_type CDP1871 = cdp1871_device_config::static_alloc_device_config; |
| 91 | |
| 92 | |
| 93 | |
| 94 | //************************************************************************** |
| 95 | // DEVICE CONFIGURATION |
| 96 | //************************************************************************** |
| 97 | |
| 98 | GENERIC_DEVICE_CONFIG_SETUP(cdp1871, "RCA CDP1871") |
| 99 | |
| 100 | |
| 101 | //------------------------------------------------- |
| 102 | // device_config_complete - perform any |
| 103 | // operations now that the configuration is |
| 104 | // complete |
| 105 | //------------------------------------------------- |
| 106 | |
| 107 | void cdp1871_device_config::device_config_complete() |
| 86 | 108 | { |
| 87 | | devcb_resolved_write_line out_da_func; |
| 88 | | devcb_resolved_write_line out_rpt_func; |
| 89 | | devcb_resolved_read8 in_d1_func; |
| 90 | | devcb_resolved_read8 in_d2_func; |
| 91 | | devcb_resolved_read8 in_d3_func; |
| 92 | | devcb_resolved_read8 in_d4_func; |
| 93 | | devcb_resolved_read8 in_d5_func; |
| 94 | | devcb_resolved_read8 in_d6_func; |
| 95 | | devcb_resolved_read8 in_d7_func; |
| 96 | | devcb_resolved_read8 in_d8_func; |
| 97 | | devcb_resolved_read8 in_d9_func; |
| 98 | | devcb_resolved_read8 in_d10_func; |
| 99 | | devcb_resolved_read8 in_d11_func; |
| 100 | | devcb_resolved_read_line in_shift_func; |
| 101 | | devcb_resolved_read_line in_control_func; |
| 102 | | devcb_resolved_read_line in_alpha_func; |
| 109 | // inherit a copy of the static data |
| 110 | const cdp1871_interface *intf = reinterpret_cast<const cdp1871_interface *>(static_config()); |
| 111 | if (intf != NULL) |
| 112 | *static_cast<cdp1871_interface *>(this) = *intf; |
| 103 | 113 | |
| 104 | | int inhibit; /* scan counter clock inhibit */ |
| 105 | | int sense; /* sense input scan counter */ |
| 106 | | int drive; /* modifier inputs */ |
| 114 | // or initialize to defaults if none provided |
| 115 | else |
| 116 | { |
| 117 | memset(&out_da_func, 0, sizeof(out_da_func)); |
| 118 | memset(&out_rpt_func, 0, sizeof(out_rpt_func)); |
| 119 | // m_in_d_func[] |
| 120 | memset(&in_shift_func, 0, sizeof(in_shift_func)); |
| 121 | memset(&in_control_func, 0, sizeof(in_control_func)); |
| 122 | memset(&in_alpha_func, 0, sizeof(in_alpha_func)); |
| 123 | } |
| 124 | } |
| 107 | 125 | |
| 108 | | int shift; /* latched shift modifier */ |
| 109 | | int control; /* latched control modifier */ |
| 110 | 126 | |
| 111 | | int da; /* data available flag */ |
| 112 | | int next_da; /* next value of data available flag */ |
| 113 | | int rpt; /* repeat flag */ |
| 114 | | int next_rpt; /* next value of repeat flag */ |
| 115 | 127 | |
| 116 | | /* timers */ |
| 117 | | emu_timer *scan_timer; /* keyboard scan timer */ |
| 118 | | }; |
| 128 | //************************************************************************** |
| 129 | // LIVE DEVICE |
| 130 | //************************************************************************** |
| 119 | 131 | |
| 120 | | /*************************************************************************** |
| 121 | | INLINE FUNCTIONS |
| 122 | | ***************************************************************************/ |
| 132 | //------------------------------------------------- |
| 133 | // cdp1871_device - constructor |
| 134 | //------------------------------------------------- |
| 123 | 135 | |
| 124 | | INLINE cdp1871_t *get_safe_token(running_device *device) |
| 136 | cdp1871_device::cdp1871_device(running_machine &_machine, const cdp1871_device_config &config) |
| 137 | : device_t(_machine, config), |
| 138 | m_inhibit(false), |
| 139 | m_sense(0), |
| 140 | m_drive(0), |
| 141 | m_next_da(CLEAR_LINE), |
| 142 | m_next_rpt(CLEAR_LINE), |
| 143 | m_config(config) |
| 125 | 144 | { |
| 126 | | assert(device != NULL); |
| 127 | 145 | |
| 128 | | return (cdp1871_t *)downcast<legacy_device_base *>(device)->token(); |
| 129 | 146 | } |
| 130 | 147 | |
| 131 | | INLINE const cdp1871_interface *get_interface(running_device *device) |
| 148 | |
| 149 | //------------------------------------------------- |
| 150 | // device_start - device-specific startup |
| 151 | //------------------------------------------------- |
| 152 | |
| 153 | void cdp1871_device::device_start() |
| 132 | 154 | { |
| 133 | | assert(device != NULL); |
| 134 | | assert((device->type() == CDP1871)); |
| 135 | | return (const cdp1871_interface *) device->baseconfig().static_config(); |
| 155 | // resolve callbacks |
| 156 | devcb_resolve_write_line(&m_out_da_func, &m_config.out_da_func, this); |
| 157 | devcb_resolve_write_line(&m_out_rpt_func, &m_config.out_rpt_func, this); |
| 158 | devcb_resolve_read8(&m_in_d_func[0], &m_config.in_d1_func, this); |
| 159 | devcb_resolve_read8(&m_in_d_func[1], &m_config.in_d2_func, this); |
| 160 | devcb_resolve_read8(&m_in_d_func[2], &m_config.in_d3_func, this); |
| 161 | devcb_resolve_read8(&m_in_d_func[3], &m_config.in_d4_func, this); |
| 162 | devcb_resolve_read8(&m_in_d_func[4], &m_config.in_d5_func, this); |
| 163 | devcb_resolve_read8(&m_in_d_func[5], &m_config.in_d6_func, this); |
| 164 | devcb_resolve_read8(&m_in_d_func[6], &m_config.in_d7_func, this); |
| 165 | devcb_resolve_read8(&m_in_d_func[7], &m_config.in_d8_func, this); |
| 166 | devcb_resolve_read8(&m_in_d_func[8], &m_config.in_d9_func, this); |
| 167 | devcb_resolve_read8(&m_in_d_func[9], &m_config.in_d10_func, this); |
| 168 | devcb_resolve_read8(&m_in_d_func[10], &m_config.in_d11_func, this); |
| 169 | devcb_resolve_read_line(&m_in_shift_func, &m_config.in_shift_func, this); |
| 170 | devcb_resolve_read_line(&m_in_control_func, &m_config.in_control_func, this); |
| 171 | devcb_resolve_read_line(&m_in_alpha_func, &m_config.in_alpha_func, this); |
| 172 | |
| 173 | // set initial values |
| 174 | change_output_lines(); |
| 175 | |
| 176 | // allocate timers |
| 177 | m_scan_timer = device_timer_alloc(*this); |
| 178 | timer_adjust_periodic(m_scan_timer, attotime_zero, 0, ATTOTIME_IN_HZ(clock())); |
| 179 | |
| 180 | // register for state saving |
| 181 | state_save_register_device_item(this, 0, m_inhibit); |
| 182 | state_save_register_device_item(this, 0, m_sense); |
| 183 | state_save_register_device_item(this, 0, m_drive); |
| 184 | state_save_register_device_item(this, 0, m_shift); |
| 185 | state_save_register_device_item(this, 0, m_control); |
| 186 | state_save_register_device_item(this, 0, m_da); |
| 187 | state_save_register_device_item(this, 0, m_next_da); |
| 188 | state_save_register_device_item(this, 0, m_rpt); |
| 189 | state_save_register_device_item(this, 0, m_next_rpt); |
| 136 | 190 | } |
| 137 | 191 | |
| 138 | | /*************************************************************************** |
| 139 | | IMPLEMENTATION |
| 140 | | ***************************************************************************/ |
| 141 | 192 | |
| 142 | | /*------------------------------------------------- |
| 143 | | change_output_lines - change output line |
| 144 | | state |
| 145 | | -------------------------------------------------*/ |
| 193 | //------------------------------------------------- |
| 194 | // device_timer - handler timer events |
| 195 | //------------------------------------------------- |
| 146 | 196 | |
| 147 | | static void change_output_lines(running_device *device) |
| 197 | void cdp1871_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 148 | 198 | { |
| 149 | | cdp1871_t *cdp1871 = get_safe_token(device); |
| 199 | change_output_lines(); |
| 200 | clock_scan_counters(); |
| 201 | detect_keypress(); |
| 202 | } |
| 150 | 203 | |
| 151 | | if (cdp1871->next_da != cdp1871->da) |
| 204 | |
| 205 | //------------------------------------------------- |
| 206 | // change_output_lines - change output lines |
| 207 | //------------------------------------------------- |
| 208 | |
| 209 | void cdp1871_device::change_output_lines() |
| 210 | { |
| 211 | if (m_next_da != m_da) |
| 152 | 212 | { |
| 153 | | cdp1871->da = cdp1871->next_da; |
| 213 | m_da = m_next_da; |
| 154 | 214 | |
| 155 | | devcb_call_write_line(&cdp1871->out_da_func, cdp1871->da); |
| 215 | devcb_call_write_line(&m_out_da_func, m_da); |
| 156 | 216 | } |
| 157 | 217 | |
| 158 | | if (cdp1871->next_rpt != cdp1871->rpt) |
| 218 | if (m_next_rpt != m_rpt) |
| 159 | 219 | { |
| 160 | | cdp1871->rpt = cdp1871->next_rpt; |
| 220 | m_rpt = m_next_rpt; |
| 161 | 221 | |
| 162 | | devcb_call_write_line(&cdp1871->out_rpt_func, cdp1871->rpt); |
| 222 | devcb_call_write_line(&m_out_rpt_func, m_rpt); |
| 163 | 223 | } |
| 164 | 224 | } |
| 165 | 225 | |
| 166 | | /*------------------------------------------------- |
| 167 | | clock_scan_counters - clock the keyboard |
| 168 | | scan counters |
| 169 | | -------------------------------------------------*/ |
| 170 | 226 | |
| 171 | | static void clock_scan_counters(running_device *device) |
| 172 | | { |
| 173 | | cdp1871_t *cdp1871 = get_safe_token(device); |
| 227 | //------------------------------------------------- |
| 228 | // clock_scan_counters - clock the keyboard |
| 229 | // scan counters |
| 230 | //------------------------------------------------- |
| 174 | 231 | |
| 175 | | if (!cdp1871->inhibit) |
| 232 | void cdp1871_device::clock_scan_counters() |
| 233 | { |
| 234 | if (!m_inhibit) |
| 176 | 235 | { |
| 177 | | cdp1871->sense++; |
| 236 | m_sense++; |
| 178 | 237 | |
| 179 | | if (cdp1871->sense == 8) |
| 238 | if (m_sense == 8) |
| 180 | 239 | { |
| 181 | | cdp1871->sense = 0; |
| 182 | | cdp1871->drive++; |
| 240 | m_sense = 0; |
| 241 | m_drive++; |
| 183 | 242 | |
| 184 | | if (cdp1871->drive == 11) |
| 243 | if (m_drive == 11) |
| 185 | 244 | { |
| 186 | | cdp1871->drive = 0; |
| 245 | m_drive = 0; |
| 187 | 246 | } |
| 188 | 247 | } |
| 189 | 248 | } |
| 190 | 249 | } |
| 191 | 250 | |
| 192 | | /*------------------------------------------------- |
| 193 | | detect_keypress - detect key press |
| 194 | | -------------------------------------------------*/ |
| 195 | 251 | |
| 196 | | static void detect_keypress(running_device *device) |
| 197 | | { |
| 198 | | cdp1871_t *cdp1871 = get_safe_token(device); |
| 252 | //------------------------------------------------- |
| 253 | // detect_keypress - detect key press |
| 254 | //------------------------------------------------- |
| 199 | 255 | |
| 256 | void cdp1871_device::detect_keypress() |
| 257 | { |
| 200 | 258 | UINT8 data = 0; |
| 201 | 259 | |
| 202 | | switch (cdp1871->drive) |
| 203 | | { |
| 204 | | case 0: data = devcb_call_read8(&cdp1871->in_d1_func, 0); break; |
| 205 | | case 1: data = devcb_call_read8(&cdp1871->in_d2_func, 0); break; |
| 206 | | case 2: data = devcb_call_read8(&cdp1871->in_d3_func, 0); break; |
| 207 | | case 3: data = devcb_call_read8(&cdp1871->in_d4_func, 0); break; |
| 208 | | case 4: data = devcb_call_read8(&cdp1871->in_d5_func, 0); break; |
| 209 | | case 5: data = devcb_call_read8(&cdp1871->in_d6_func, 0); break; |
| 210 | | case 6: data = devcb_call_read8(&cdp1871->in_d7_func, 0); break; |
| 211 | | case 7: data = devcb_call_read8(&cdp1871->in_d8_func, 0); break; |
| 212 | | case 8: data = devcb_call_read8(&cdp1871->in_d9_func, 0); break; |
| 213 | | case 9: data = devcb_call_read8(&cdp1871->in_d10_func, 0); break; |
| 214 | | case 10: data = devcb_call_read8(&cdp1871->in_d11_func, 0); break; |
| 215 | | } |
| 260 | data = devcb_call_read8(&m_in_d_func[m_drive], 0); |
| 216 | 261 | |
| 217 | | if (data == (1 << cdp1871->sense)) |
| 262 | if (data == (1 << m_sense)) |
| 218 | 263 | { |
| 219 | | if (!cdp1871->inhibit) |
| 264 | if (!m_inhibit) |
| 220 | 265 | { |
| 221 | | cdp1871->shift = devcb_call_read_line(&cdp1871->in_shift_func); |
| 222 | | cdp1871->control = devcb_call_read_line(&cdp1871->in_control_func); |
| 223 | | cdp1871->inhibit = 1; |
| 224 | | cdp1871->next_da = ASSERT_LINE; |
| 266 | m_shift = devcb_call_read_line(&m_in_shift_func); |
| 267 | m_control = devcb_call_read_line(&m_in_control_func); |
| 268 | m_inhibit = true; |
| 269 | m_next_da = ASSERT_LINE; |
| 225 | 270 | } |
| 226 | 271 | else |
| 227 | 272 | { |
| 228 | | cdp1871->next_rpt = ASSERT_LINE; |
| 273 | m_next_rpt = ASSERT_LINE; |
| 229 | 274 | } |
| 230 | 275 | } |
| 231 | 276 | else |
| 232 | 277 | { |
| 233 | | cdp1871->inhibit = 0; |
| 234 | | cdp1871->next_rpt = CLEAR_LINE; |
| 278 | m_inhibit = false; |
| 279 | m_next_rpt = CLEAR_LINE; |
| 235 | 280 | } |
| 236 | 281 | } |
| 237 | 282 | |
| 238 | | /*------------------------------------------------- |
| 239 | | TIMER_CALLBACK( cdp1871_scan_tick ) |
| 240 | | -------------------------------------------------*/ |
| 241 | 283 | |
| 242 | | static TIMER_CALLBACK( cdp1871_scan_tick ) |
| 243 | | { |
| 244 | | running_device *device = (running_device *)ptr; |
| 284 | //------------------------------------------------- |
| 285 | // data_r - keyboard data read |
| 286 | //------------------------------------------------- |
| 245 | 287 | |
| 246 | | change_output_lines(device); |
| 247 | | clock_scan_counters(device); |
| 248 | | detect_keypress(device); |
| 249 | | } |
| 250 | | |
| 251 | | /*------------------------------------------------- |
| 252 | | cdp1871_data_r - interface retrieving |
| 253 | | keyboard data |
| 254 | | -------------------------------------------------*/ |
| 255 | | |
| 256 | | READ8_DEVICE_HANDLER( cdp1871_data_r ) |
| 288 | READ8_MEMBER( cdp1871_device::data_r ) |
| 257 | 289 | { |
| 258 | | cdp1871_t *cdp1871 = get_safe_token(device); |
| 259 | | |
| 260 | 290 | int table = 0; |
| 261 | | int alpha = devcb_call_read_line(&cdp1871->in_alpha_func); |
| 291 | int alpha = devcb_call_read_line(&m_in_alpha_func); |
| 262 | 292 | |
| 263 | | if (cdp1871->control) table = 3; else if (cdp1871->shift) table = 2; else if (alpha) table = 1; |
| 293 | if (m_control) table = 3; else if (m_shift) table = 2; else if (alpha) table = 1; |
| 264 | 294 | |
| 265 | 295 | // reset DA on next TPB |
| 296 | m_next_da = CLEAR_LINE; |
| 266 | 297 | |
| 267 | | cdp1871->next_da = CLEAR_LINE; |
| 268 | | |
| 269 | | return CDP1871_KEY_CODES[table][cdp1871->drive][cdp1871->sense]; |
| 298 | return CDP1871_KEY_CODES[table][m_drive][m_sense]; |
| 270 | 299 | } |
| 271 | 300 | |
| 272 | | /*------------------------------------------------- |
| 273 | | cdp1871_da_r - keyboard data available |
| 274 | | -------------------------------------------------*/ |
| 275 | 301 | |
| 276 | | READ_LINE_DEVICE_HANDLER( cdp1871_da_r ) |
| 277 | | { |
| 278 | | cdp1871_t *cdp1871 = get_safe_token(device); |
| 302 | //------------------------------------------------- |
| 303 | // da_r - data available |
| 304 | //------------------------------------------------- |
| 279 | 305 | |
| 280 | | return cdp1871->da; |
| 281 | | } |
| 282 | | |
| 283 | | /*------------------------------------------------- |
| 284 | | cdp1871_rpt_r - keyboard repeat |
| 285 | | -------------------------------------------------*/ |
| 286 | | |
| 287 | | READ_LINE_DEVICE_HANDLER( cdp1871_rpt_r ) |
| 306 | READ_LINE_MEMBER( cdp1871_device::da_r ) |
| 288 | 307 | { |
| 289 | | cdp1871_t *cdp1871 = get_safe_token(device); |
| 290 | | |
| 291 | | return cdp1871->rpt; |
| 308 | return m_da; |
| 292 | 309 | } |
| 293 | 310 | |
| 294 | | /*------------------------------------------------- |
| 295 | | DEVICE_START( cdp1871 ) |
| 296 | | -------------------------------------------------*/ |
| 297 | 311 | |
| 298 | | static DEVICE_START( cdp1871 ) |
| 299 | | { |
| 300 | | cdp1871_t *cdp1871 = get_safe_token(device); |
| 301 | | const cdp1871_interface *intf = get_interface(device); |
| 312 | //------------------------------------------------- |
| 313 | // rpt_r - keyboard repeat |
| 314 | //------------------------------------------------- |
| 302 | 315 | |
| 303 | | /* resolve callbacks */ |
| 304 | | devcb_resolve_write_line(&cdp1871->out_da_func, &intf->out_da_func, device); |
| 305 | | devcb_resolve_write_line(&cdp1871->out_rpt_func, &intf->out_rpt_func, device); |
| 306 | | devcb_resolve_read8(&cdp1871->in_d1_func, &intf->in_d1_func, device); |
| 307 | | devcb_resolve_read8(&cdp1871->in_d2_func, &intf->in_d2_func, device); |
| 308 | | devcb_resolve_read8(&cdp1871->in_d3_func, &intf->in_d3_func, device); |
| 309 | | devcb_resolve_read8(&cdp1871->in_d4_func, &intf->in_d4_func, device); |
| 310 | | devcb_resolve_read8(&cdp1871->in_d5_func, &intf->in_d5_func, device); |
| 311 | | devcb_resolve_read8(&cdp1871->in_d6_func, &intf->in_d6_func, device); |
| 312 | | devcb_resolve_read8(&cdp1871->in_d7_func, &intf->in_d7_func, device); |
| 313 | | devcb_resolve_read8(&cdp1871->in_d8_func, &intf->in_d8_func, device); |
| 314 | | devcb_resolve_read8(&cdp1871->in_d9_func, &intf->in_d9_func, device); |
| 315 | | devcb_resolve_read8(&cdp1871->in_d10_func, &intf->in_d10_func, device); |
| 316 | | devcb_resolve_read8(&cdp1871->in_d11_func, &intf->in_d11_func, device); |
| 317 | | devcb_resolve_read_line(&cdp1871->in_shift_func, &intf->in_shift_func, device); |
| 318 | | devcb_resolve_read_line(&cdp1871->in_control_func, &intf->in_control_func, device); |
| 319 | | devcb_resolve_read_line(&cdp1871->in_alpha_func, &intf->in_alpha_func, device); |
| 320 | | |
| 321 | | /* set initial values */ |
| 322 | | cdp1871->next_da = CLEAR_LINE; |
| 323 | | cdp1871->next_rpt = CLEAR_LINE; |
| 324 | | change_output_lines(device); |
| 325 | | |
| 326 | | /* create the timers */ |
| 327 | | cdp1871->scan_timer = timer_alloc(device->machine, cdp1871_scan_tick, (void *)device); |
| 328 | | timer_adjust_periodic(cdp1871->scan_timer, attotime_zero, 0, ATTOTIME_IN_HZ(device->clock())); |
| 329 | | |
| 330 | | /* register for state saving */ |
| 331 | | state_save_register_device_item(device, 0, cdp1871->inhibit); |
| 332 | | state_save_register_device_item(device, 0, cdp1871->sense); |
| 333 | | state_save_register_device_item(device, 0, cdp1871->drive); |
| 334 | | state_save_register_device_item(device, 0, cdp1871->shift); |
| 335 | | state_save_register_device_item(device, 0, cdp1871->control); |
| 336 | | state_save_register_device_item(device, 0, cdp1871->da); |
| 337 | | state_save_register_device_item(device, 0, cdp1871->next_da); |
| 338 | | state_save_register_device_item(device, 0, cdp1871->rpt); |
| 339 | | state_save_register_device_item(device, 0, cdp1871->next_rpt); |
| 340 | | } |
| 341 | | |
| 342 | | /*------------------------------------------------- |
| 343 | | DEVICE_GET_INFO( cdp1871 ) |
| 344 | | -------------------------------------------------*/ |
| 345 | | |
| 346 | | DEVICE_GET_INFO( cdp1871 ) |
| 316 | READ_LINE_MEMBER( cdp1871_device::rpt_r ) |
| 347 | 317 | { |
| 348 | | switch (state) |
| 349 | | { |
| 350 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 351 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(cdp1871_t); break; |
| 352 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 353 | | |
| 354 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 355 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(cdp1871); break; |
| 356 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 357 | | case DEVINFO_FCT_RESET: /* Nothing */ break; |
| 358 | | |
| 359 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 360 | | case DEVINFO_STR_NAME: strcpy(info->s, "RCA CDP1871"); break; |
| 361 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "RCA CDP1800"); break; |
| 362 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 363 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 364 | | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright MESS Team"); break; |
| 365 | | } |
| 318 | return m_rpt; |
| 366 | 319 | } |
| 367 | | |
| 368 | | DEFINE_LEGACY_DEVICE(CDP1871, cdp1871); |
src/mess/machine/i8155.c
| r9419 | r9420 | |
| 15 | 15 | |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | #include "emu.h" |
| 18 | 19 | #include "i8155.h" |
| 19 | 20 | |
| 20 | | /*************************************************************************** |
| 21 | | PARAMETERS |
| 22 | | ***************************************************************************/ |
| 23 | 21 | |
| 22 | |
| 23 | //************************************************************************** |
| 24 | // MACROS / CONSTANTS |
| 25 | //************************************************************************** |
| 26 | |
| 24 | 27 | #define LOG 0 |
| 25 | 28 | |
| 26 | 29 | enum |
| 27 | 30 | { |
| 28 | | I8155_REGISTER_COMMAND = 0, |
| 29 | | I8155_REGISTER_STATUS = 0, |
| 30 | | I8155_REGISTER_PORT_A, |
| 31 | | I8155_REGISTER_PORT_B, |
| 32 | | I8155_REGISTER_PORT_C, |
| 33 | | I8155_REGISTER_TIMER_LOW, |
| 34 | | I8155_REGISTER_TIMER_HIGH |
| 31 | REGISTER_COMMAND = 0, |
| 32 | REGISTER_STATUS = 0, |
| 33 | REGISTER_PORT_A, |
| 34 | REGISTER_PORT_B, |
| 35 | REGISTER_PORT_C, |
| 36 | REGISTER_TIMER_LOW, |
| 37 | REGISTER_TIMER_HIGH |
| 35 | 38 | }; |
| 36 | 39 | |
| 37 | 40 | enum |
| 38 | 41 | { |
| 39 | | I8155_PORT_A = 0, |
| 40 | | I8155_PORT_B, |
| 41 | | I8155_PORT_C, |
| 42 | | I8155_PORT_COUNT |
| 42 | PORT_A = 0, |
| 43 | PORT_B, |
| 44 | PORT_C, |
| 45 | PORT_COUNT |
| 43 | 46 | }; |
| 44 | 47 | |
| 45 | 48 | enum |
| 46 | 49 | { |
| 47 | | I8155_PORT_MODE_INPUT = 0, |
| 48 | | I8155_PORT_MODE_OUTPUT, |
| 49 | | I8155_PORT_MODE_STROBED_PORT_A, /* not supported */ |
| 50 | | I8155_PORT_MODE_STROBED /* not supported */ |
| 50 | PORT_MODE_INPUT = 0, |
| 51 | PORT_MODE_OUTPUT, |
| 52 | PORT_MODE_STROBED_PORT_A, // not supported |
| 53 | PORT_MODE_STROBED // not supported |
| 51 | 54 | }; |
| 52 | 55 | |
| 53 | | #define I8155_COMMAND_PA 0x01 |
| 54 | | #define I8155_COMMAND_PB 0x02 |
| 55 | | #define I8155_COMMAND_PC_MASK 0x0c |
| 56 | | #define I8155_COMMAND_PC_ALT_1 0x00 |
| 57 | | #define I8155_COMMAND_PC_ALT_2 0x0c |
| 58 | | #define I8155_COMMAND_PC_ALT_3 0x04 /* not supported */ |
| 59 | | #define I8155_COMMAND_PC_ALT_4 0x08 /* not supported */ |
| 60 | | #define I8155_COMMAND_IEA 0x10 /* not supported */ |
| 61 | | #define I8155_COMMAND_IEB 0x20 /* not supported */ |
| 62 | | #define I8155_COMMAND_TM_MASK 0xc0 |
| 63 | | #define I8155_COMMAND_TM_NOP 0x00 |
| 64 | | #define I8155_COMMAND_TM_STOP 0x40 |
| 65 | | #define I8155_COMMAND_TM_STOP_AFTER_TC 0x80 |
| 66 | | #define I8155_COMMAND_TM_START 0xc0 |
| 56 | #define COMMAND_PA 0x01 |
| 57 | #define COMMAND_PB 0x02 |
| 58 | #define COMMAND_PC_MASK 0x0c |
| 59 | #define COMMAND_PC_ALT_1 0x00 |
| 60 | #define COMMAND_PC_ALT_2 0x0c |
| 61 | #define COMMAND_PC_ALT_3 0x04 // not supported |
| 62 | #define COMMAND_PC_ALT_4 0x08 // not supported |
| 63 | #define COMMAND_IEA 0x10 // not supported |
| 64 | #define COMMAND_IEB 0x20 // not supported |
| 65 | #define COMMAND_TM_MASK 0xc0 |
| 66 | #define COMMAND_TM_NOP 0x00 |
| 67 | #define COMMAND_TM_STOP 0x40 |
| 68 | #define COMMAND_TM_STOP_AFTER_TC 0x80 |
| 69 | #define COMMAND_TM_START 0xc0 |
| 67 | 70 | |
| 68 | | #define I8155_STATUS_INTR_A 0x01 /* not supported */ |
| 69 | | #define I8155_STATUS_A_BF 0x02 /* not supported */ |
| 70 | | #define I8155_STATUS_INTE_A 0x04 /* not supported */ |
| 71 | | #define I8155_STATUS_INTR_B 0x08 /* not supported */ |
| 72 | | #define I8155_STATUS_B_BF 0x10 /* not supported */ |
| 73 | | #define I8155_STATUS_INTE_B 0x20 /* not supported */ |
| 74 | | #define I8155_STATUS_TIMER 0x40 |
| 71 | #define STATUS_INTR_A 0x01 // not supported |
| 72 | #define STATUS_A_BF 0x02 // not supported |
| 73 | #define STATUS_INTE_A 0x04 // not supported |
| 74 | #define STATUS_INTR_B 0x08 // not supported |
| 75 | #define STATUS_B_BF 0x10 // not supported |
| 76 | #define STATUS_INTE_B 0x20 // not supported |
| 77 | #define STATUS_TIMER 0x40 |
| 75 | 78 | |
| 76 | | #define I8155_TIMER_MODE_MASK 0xc0 |
| 77 | | #define I8155_TIMER_MODE_LOW 0x00 |
| 78 | | #define I8155_TIMER_MODE_SQUARE_WAVE 0x40 |
| 79 | | #define I8155_TIMER_MODE_SINGLE_PULSE 0x80 |
| 80 | | #define I8155_TIMER_MODE_AUTOMATIC_RELOAD 0xc0 |
| 79 | #define TIMER_MODE_MASK 0xc0 |
| 80 | #define TIMER_MODE_LOW 0x00 |
| 81 | #define TIMER_MODE_SQUARE_WAVE 0x40 |
| 82 | #define TIMER_MODE_SINGLE_PULSE 0x80 |
| 83 | #define TIMER_MODE_AUTOMATIC_RELOAD 0xc0 |
| 81 | 84 | |
| 82 | | /*************************************************************************** |
| 83 | | TYPE DEFINITIONS |
| 84 | | ***************************************************************************/ |
| 85 | 85 | |
| 86 | | typedef struct _i8155_t i8155_t; |
| 87 | | struct _i8155_t |
| 86 | |
| 87 | //************************************************************************** |
| 88 | // GLOBAL VARIABLES |
| 89 | //************************************************************************** |
| 90 | |
| 91 | // devices |
| 92 | const device_type I8155 = i8155_device_config::static_alloc_device_config; |
| 93 | |
| 94 | |
| 95 | // default address map |
| 96 | static ADDRESS_MAP_START( i8155, 0, 8 ) |
| 97 | AM_RANGE(0x00, 0xff) AM_RAM |
| 98 | ADDRESS_MAP_END |
| 99 | |
| 100 | |
| 101 | |
| 102 | //************************************************************************** |
| 103 | // DEVICE CONFIGURATION |
| 104 | //************************************************************************** |
| 105 | |
| 106 | //------------------------------------------------- |
| 107 | // i8155_device_config - constructor |
| 108 | //------------------------------------------------- |
| 109 | |
| 110 | i8155_device_config::i8155_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 111 | : device_config(mconfig, static_alloc_device_config, "Intel 8155", tag, owner, clock), |
| 112 | device_config_memory_interface(mconfig, *this), |
| 113 | m_space_config("ram", ENDIANNESS_LITTLE, 8, 8, 0, NULL, *ADDRESS_MAP_NAME(i8155)) |
| 88 | 114 | { |
| 89 | | devcb_resolved_read8 in_port_func[I8155_PORT_COUNT]; |
| 90 | | devcb_resolved_write8 out_port_func[I8155_PORT_COUNT]; |
| 91 | | devcb_resolved_write_line out_to_func; |
| 115 | } |
| 92 | 116 | |
| 93 | | /* memory */ |
| 94 | | UINT8 ram[256]; /* RAM */ |
| 95 | 117 | |
| 96 | | /* registers */ |
| 97 | | UINT8 command; /* command register */ |
| 98 | | UINT8 status; /* status register */ |
| 99 | | UINT8 output[3]; /* output latches */ |
| 118 | //------------------------------------------------- |
| 119 | // static_alloc_device_config - allocate a new |
| 120 | // configuration object |
| 121 | //------------------------------------------------- |
| 100 | 122 | |
| 101 | | /* counter */ |
| 102 | | UINT16 count_length; /* count length register */ |
| 103 | | UINT16 counter; /* counter register */ |
| 104 | | int to; /* timer output */ |
| 123 | device_config *i8155_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 124 | { |
| 125 | return global_alloc(i8155_device_config(mconfig, tag, owner, clock)); |
| 126 | } |
| 105 | 127 | |
| 106 | | /* timers */ |
| 107 | | emu_timer *timer; /* counter timer */ |
| 108 | | }; |
| 109 | 128 | |
| 110 | | /*************************************************************************** |
| 111 | | INLINE FUNCTIONS |
| 112 | | ***************************************************************************/ |
| 129 | //------------------------------------------------- |
| 130 | // alloc_device - allocate a new device object |
| 131 | //------------------------------------------------- |
| 113 | 132 | |
| 114 | | INLINE i8155_t *get_safe_token(running_device *device) |
| 133 | device_t *i8155_device_config::alloc_device(running_machine &machine) const |
| 115 | 134 | { |
| 116 | | assert(device != NULL); |
| 117 | | return (i8155_t *)downcast<legacy_device_base *>(device)->token(); |
| 135 | return auto_alloc(&machine, i8155_device(machine, *this)); |
| 118 | 136 | } |
| 119 | 137 | |
| 120 | | INLINE const i8155_interface *get_interface(running_device *device) |
| 138 | |
| 139 | //------------------------------------------------- |
| 140 | // memory_space_config - return a description of |
| 141 | // any address spaces owned by this device |
| 142 | //------------------------------------------------- |
| 143 | |
| 144 | const address_space_config *i8155_device_config::memory_space_config(int spacenum) const |
| 121 | 145 | { |
| 122 | | assert(device != NULL); |
| 123 | | assert(device->type() == I8155); |
| 124 | | return (const i8155_interface *) device->baseconfig().static_config(); |
| 146 | return (spacenum == 0) ? &m_space_config : NULL; |
| 125 | 147 | } |
| 126 | 148 | |
| 127 | | INLINE UINT8 get_timer_mode(i8155_t *i8155) |
| 149 | |
| 150 | //------------------------------------------------- |
| 151 | // device_config_complete - perform any |
| 152 | // operations now that the configuration is |
| 153 | // complete |
| 154 | //------------------------------------------------- |
| 155 | |
| 156 | void i8155_device_config::device_config_complete() |
| 128 | 157 | { |
| 129 | | return (i8155->count_length >> 8) & I8155_TIMER_MODE_MASK; |
| 158 | // inherit a copy of the static data |
| 159 | const i8155_interface *intf = reinterpret_cast<const i8155_interface *>(static_config()); |
| 160 | if (intf != NULL) |
| 161 | *static_cast<i8155_interface *>(this) = *intf; |
| 162 | |
| 163 | // or initialize to defaults if none provided |
| 164 | else |
| 165 | { |
| 166 | memset(&in_pa_func, 0, sizeof(in_pa_func)); |
| 167 | memset(&out_pa_func, 0, sizeof(out_pa_func)); |
| 168 | memset(&in_pb_func, 0, sizeof(in_pb_func)); |
| 169 | memset(&out_pb_func, 0, sizeof(out_pb_func)); |
| 170 | memset(&in_pc_func, 0, sizeof(in_pc_func)); |
| 171 | memset(&out_pc_func, 0, sizeof(out_pc_func)); |
| 172 | memset(&out_to_func, 0, sizeof(out_to_func)); |
| 173 | } |
| 130 | 174 | } |
| 131 | 175 | |
| 132 | | INLINE void timer_output(i8155_t *i8155) |
| 176 | |
| 177 | |
| 178 | //************************************************************************** |
| 179 | // INLINE HELPERS |
| 180 | //************************************************************************** |
| 181 | |
| 182 | inline UINT8 i8155_device::get_timer_mode() |
| 133 | 183 | { |
| 134 | | devcb_call_write_line(&i8155->out_to_func, i8155->to); |
| 184 | return (m_count_length >> 8) & TIMER_MODE_MASK; |
| 185 | } |
| 135 | 186 | |
| 136 | | if (LOG) logerror("8155 Timer Output: %u\n", i8155->to); |
| 187 | inline void i8155_device::timer_output() |
| 188 | { |
| 189 | devcb_call_write_line(&m_out_to_func, m_to); |
| 190 | |
| 191 | if (LOG) logerror("8155 '%s' Timer Output: %u\n", tag(), m_to); |
| 137 | 192 | } |
| 138 | 193 | |
| 139 | | INLINE void pulse_timer_output(i8155_t *i8155) |
| 194 | inline void i8155_device::pulse_timer_output() |
| 140 | 195 | { |
| 141 | | i8155->to = 0; timer_output(i8155); |
| 142 | | i8155->to = 1; timer_output(i8155); |
| 196 | m_to = 0; timer_output(); |
| 197 | m_to = 1; timer_output(); |
| 143 | 198 | } |
| 144 | 199 | |
| 145 | | INLINE int get_port_mode(i8155_t *i8155, int port) |
| 200 | inline int i8155_device::get_port_mode(int port) |
| 146 | 201 | { |
| 147 | 202 | int mode = -1; |
| 148 | 203 | |
| 149 | 204 | switch (port) |
| 150 | 205 | { |
| 151 | | case I8155_PORT_A: |
| 152 | | mode = (i8155->command & I8155_COMMAND_PA) ? I8155_PORT_MODE_OUTPUT : I8155_PORT_MODE_INPUT; |
| 206 | case PORT_A: |
| 207 | mode = (m_command & COMMAND_PA) ? PORT_MODE_OUTPUT : PORT_MODE_INPUT; |
| 153 | 208 | break; |
| 154 | 209 | |
| 155 | | case I8155_PORT_B: |
| 156 | | mode = (i8155->command & I8155_COMMAND_PB) ? I8155_PORT_MODE_OUTPUT : I8155_PORT_MODE_INPUT; |
| 210 | case PORT_B: |
| 211 | mode = (m_command & COMMAND_PB) ? PORT_MODE_OUTPUT : PORT_MODE_INPUT; |
| 157 | 212 | break; |
| 158 | 213 | |
| 159 | | case I8155_PORT_C: |
| 160 | | switch (i8155->command & I8155_COMMAND_PC_MASK) |
| 214 | case PORT_C: |
| 215 | switch (m_command & COMMAND_PC_MASK) |
| 161 | 216 | { |
| 162 | | case I8155_COMMAND_PC_ALT_1: mode = I8155_PORT_MODE_INPUT; break; |
| 163 | | case I8155_COMMAND_PC_ALT_2: mode = I8155_PORT_MODE_OUTPUT; break; |
| 164 | | case I8155_COMMAND_PC_ALT_3: mode = I8155_PORT_MODE_STROBED_PORT_A; break; |
| 165 | | case I8155_COMMAND_PC_ALT_4: mode = I8155_PORT_MODE_STROBED; break; |
| 217 | case COMMAND_PC_ALT_1: mode = PORT_MODE_INPUT; break; |
| 218 | case COMMAND_PC_ALT_2: mode = PORT_MODE_OUTPUT; break; |
| 219 | case COMMAND_PC_ALT_3: mode = PORT_MODE_STROBED_PORT_A; break; |
| 220 | case COMMAND_PC_ALT_4: mode = PORT_MODE_STROBED; break; |
| 166 | 221 | } |
| 167 | 222 | break; |
| 168 | 223 | } |
| r9419 | r9420 | |
| 170 | 225 | return mode; |
| 171 | 226 | } |
| 172 | 227 | |
| 173 | | INLINE UINT8 read_port(i8155_t *i8155, int port) |
| 228 | inline UINT8 i8155_device::read_port(int port) |
| 174 | 229 | { |
| 175 | 230 | UINT8 data = 0; |
| 176 | 231 | |
| 177 | 232 | switch (port) |
| 178 | 233 | { |
| 179 | | case I8155_PORT_A: |
| 180 | | case I8155_PORT_B: |
| 181 | | switch (get_port_mode(i8155, port)) |
| 234 | case PORT_A: |
| 235 | case PORT_B: |
| 236 | switch (get_port_mode(port)) |
| 182 | 237 | { |
| 183 | | case I8155_PORT_MODE_INPUT: |
| 184 | | data = devcb_call_read8(&i8155->in_port_func[port], 0); |
| 238 | case PORT_MODE_INPUT: |
| 239 | data = devcb_call_read8(&m_in_port_func[port], 0); |
| 185 | 240 | break; |
| 186 | 241 | |
| 187 | | case I8155_PORT_MODE_OUTPUT: |
| 188 | | data = i8155->output[port]; |
| 242 | case PORT_MODE_OUTPUT: |
| 243 | data = m_output[port]; |
| 189 | 244 | break; |
| 190 | 245 | } |
| 191 | 246 | break; |
| 192 | 247 | |
| 193 | | case I8155_PORT_C: |
| 194 | | switch (get_port_mode(i8155, I8155_PORT_C)) |
| 248 | case PORT_C: |
| 249 | switch (get_port_mode(PORT_C)) |
| 195 | 250 | { |
| 196 | | case I8155_PORT_MODE_INPUT: |
| 197 | | data = devcb_call_read8(&i8155->in_port_func[port], 0) & 0x3f; |
| 251 | case PORT_MODE_INPUT: |
| 252 | data = devcb_call_read8(&m_in_port_func[port], 0) & 0x3f; |
| 198 | 253 | break; |
| 199 | 254 | |
| 200 | | case I8155_PORT_MODE_OUTPUT: |
| 201 | | data = i8155->output[port] & 0x3f; |
| 255 | case PORT_MODE_OUTPUT: |
| 256 | data = m_output[port] & 0x3f; |
| 202 | 257 | break; |
| 203 | 258 | |
| 204 | 259 | default: |
| 205 | | logerror("8155 Unsupported Port C mode!\n"); |
| 260 | logerror("8155 '%s' Unsupported Port C mode!\n", tag()); |
| 206 | 261 | } |
| 207 | 262 | break; |
| 208 | 263 | } |
| r9419 | r9420 | |
| 210 | 265 | return data; |
| 211 | 266 | } |
| 212 | 267 | |
| 213 | | INLINE void write_port(i8155_t *i8155, int port, UINT8 data) |
| 268 | inline void i8155_device::write_port(int port, UINT8 data) |
| 214 | 269 | { |
| 215 | | switch (get_port_mode(i8155, port)) |
| 270 | switch (get_port_mode(port)) |
| 216 | 271 | { |
| 217 | | case I8155_PORT_MODE_OUTPUT: |
| 218 | | i8155->output[port] = data; |
| 219 | | devcb_call_write8(&i8155->out_port_func[port], 0, i8155->output[port]); |
| 272 | case PORT_MODE_OUTPUT: |
| 273 | m_output[port] = data; |
| 274 | devcb_call_write8(&m_out_port_func[port], 0, m_output[port]); |
| 220 | 275 | break; |
| 221 | 276 | } |
| 222 | 277 | } |
| 223 | 278 | |
| 224 | | /*************************************************************************** |
| 225 | | IMPLEMENTATION |
| 226 | | ***************************************************************************/ |
| 227 | 279 | |
| 228 | | /*------------------------------------------------- |
| 229 | | TIMER_CALLBACK( counter_tick ) |
| 230 | | -------------------------------------------------*/ |
| 280 | //************************************************************************** |
| 281 | // LIVE DEVICE |
| 282 | //************************************************************************** |
| 231 | 283 | |
| 232 | | static TIMER_CALLBACK( counter_tick ) |
| 284 | //------------------------------------------------- |
| 285 | // i8155_device - constructor |
| 286 | //------------------------------------------------- |
| 287 | |
| 288 | i8155_device::i8155_device(running_machine &_machine, const i8155_device_config &config) |
| 289 | : device_t(_machine, config), |
| 290 | device_memory_interface(_machine, config, *this), |
| 291 | m_config(config) |
| 233 | 292 | { |
| 234 | | running_device *device = (running_device *)ptr; |
| 235 | | i8155_t *i8155 = get_safe_token(device); |
| 236 | 293 | |
| 237 | | /* count down */ |
| 238 | | i8155->counter--; |
| 294 | } |
| 239 | 295 | |
| 240 | | if (get_timer_mode(i8155) == I8155_TIMER_MODE_LOW) |
| 296 | |
| 297 | //------------------------------------------------- |
| 298 | // device_start - device-specific startup |
| 299 | //------------------------------------------------- |
| 300 | |
| 301 | void i8155_device::device_start() |
| 302 | { |
| 303 | // resolve callbacks |
| 304 | devcb_resolve_read8(&m_in_port_func[0], &m_config.in_pa_func, this); |
| 305 | devcb_resolve_read8(&m_in_port_func[1], &m_config.in_pb_func, this); |
| 306 | devcb_resolve_read8(&m_in_port_func[2], &m_config.in_pc_func, this); |
| 307 | devcb_resolve_write8(&m_out_port_func[0], &m_config.out_pa_func, this); |
| 308 | devcb_resolve_write8(&m_out_port_func[1], &m_config.out_pb_func, this); |
| 309 | devcb_resolve_write8(&m_out_port_func[2], &m_config.out_pc_func, this); |
| 310 | devcb_resolve_write_line(&m_out_to_func, &m_config.out_to_func, this); |
| 311 | |
| 312 | // allocate timers |
| 313 | m_timer = device_timer_alloc(*this); |
| 314 | |
| 315 | // register for state saving |
| 316 | state_save_register_device_item(this, 0, m_command); |
| 317 | state_save_register_device_item(this, 0, m_status); |
| 318 | state_save_register_device_item_array(this, 0, m_output); |
| 319 | state_save_register_device_item(this, 0, m_count_length); |
| 320 | state_save_register_device_item(this, 0, m_counter); |
| 321 | state_save_register_device_item(this, 0, m_to); |
| 322 | } |
| 323 | |
| 324 | |
| 325 | //------------------------------------------------- |
| 326 | // device_reset - device-specific reset |
| 327 | //------------------------------------------------- |
| 328 | |
| 329 | void i8155_device::device_reset() |
| 330 | { |
| 331 | // clear output registers |
| 332 | m_output[PORT_A] = 0; |
| 333 | m_output[PORT_B] = 0; |
| 334 | m_output[PORT_C] = 0; |
| 335 | |
| 336 | // set ports to input mode |
| 337 | register_w(REGISTER_COMMAND, m_command & ~(COMMAND_PA | COMMAND_PB | COMMAND_PC_MASK)); |
| 338 | |
| 339 | // clear timer flag |
| 340 | m_status &= ~STATUS_TIMER; |
| 341 | |
| 342 | // stop counting |
| 343 | timer_enable(m_timer, 0); |
| 344 | |
| 345 | // clear timer output |
| 346 | m_to = 1; |
| 347 | timer_output(); |
| 348 | } |
| 349 | |
| 350 | |
| 351 | //------------------------------------------------- |
| 352 | // device_timer - handler timer events |
| 353 | //------------------------------------------------- |
| 354 | |
| 355 | void i8155_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 356 | { |
| 357 | // count down |
| 358 | m_counter--; |
| 359 | |
| 360 | if (get_timer_mode() == TIMER_MODE_LOW) |
| 241 | 361 | { |
| 242 | | /* pulse on every count */ |
| 243 | | pulse_timer_output(i8155); |
| 362 | // pulse on every count |
| 363 | pulse_timer_output(); |
| 244 | 364 | } |
| 245 | 365 | |
| 246 | | if (i8155->counter == 0) |
| 366 | if (m_counter == 0) |
| 247 | 367 | { |
| 248 | | if (LOG) logerror("8155 Timer Count Reached\n"); |
| 368 | if (LOG) logerror("8155 '%s' Timer Count Reached\n", tag()); |
| 249 | 369 | |
| 250 | | switch (i8155->command & I8155_COMMAND_TM_MASK) |
| 370 | switch (m_command & COMMAND_TM_MASK) |
| 251 | 371 | { |
| 252 | | case I8155_COMMAND_TM_STOP_AFTER_TC: |
| 253 | | /* stop timer */ |
| 254 | | timer_enable(i8155->timer, 0); |
| 372 | case COMMAND_TM_STOP_AFTER_TC: |
| 373 | // stop timer |
| 374 | timer_enable(m_timer, 0); |
| 255 | 375 | |
| 256 | | if (LOG) logerror("8155 Timer Stopped\n"); |
| 376 | if (LOG) logerror("8155 '%s' Timer Stopped\n", tag()); |
| 257 | 377 | break; |
| 258 | 378 | } |
| 259 | 379 | |
| 260 | | switch (get_timer_mode(i8155)) |
| 380 | switch (get_timer_mode()) |
| 261 | 381 | { |
| 262 | | case I8155_TIMER_MODE_SQUARE_WAVE: |
| 263 | | /* toggle timer output */ |
| 264 | | i8155->to = !i8155->to; |
| 265 | | timer_output(i8155); |
| 382 | case TIMER_MODE_SQUARE_WAVE: |
| 383 | // toggle timer output |
| 384 | m_to = !m_to; |
| 385 | timer_output(); |
| 266 | 386 | break; |
| 267 | 387 | |
| 268 | | case I8155_TIMER_MODE_SINGLE_PULSE: |
| 269 | | /* single pulse upon TC being reached */ |
| 270 | | pulse_timer_output(i8155); |
| 388 | case TIMER_MODE_SINGLE_PULSE: |
| 389 | // single pulse upon TC being reached |
| 390 | pulse_timer_output(); |
| 271 | 391 | |
| 272 | | /* clear timer mode setting */ |
| 273 | | i8155->command &= ~I8155_COMMAND_TM_MASK; |
| 392 | // clear timer mode setting |
| 393 | m_command &= ~COMMAND_TM_MASK; |
| 274 | 394 | break; |
| 275 | 395 | |
| 276 | | case I8155_TIMER_MODE_AUTOMATIC_RELOAD: |
| 277 | | /* automatic reload, i.e. single pulse every time TC is reached */ |
| 278 | | pulse_timer_output(i8155); |
| 396 | case TIMER_MODE_AUTOMATIC_RELOAD: |
| 397 | // automatic reload, i.e. single pulse every time TC is reached |
| 398 | pulse_timer_output(); |
| 279 | 399 | break; |
| 280 | 400 | } |
| 281 | 401 | |
| 282 | | /* set timer flag */ |
| 283 | | i8155->status |= I8155_STATUS_TIMER; |
| 402 | // set timer flag |
| 403 | m_status |= STATUS_TIMER; |
| 284 | 404 | |
| 285 | | /* reload timer counter */ |
| 286 | | i8155->counter = i8155->count_length & 0x3fff; |
| 405 | // reload timer counter |
| 406 | m_counter = m_count_length & 0x3fff; |
| 287 | 407 | } |
| 288 | 408 | } |
| 289 | 409 | |
| 290 | | /*------------------------------------------------- |
| 291 | | i8155_register_r - register read |
| 292 | | -------------------------------------------------*/ |
| 293 | 410 | |
| 294 | | READ8_DEVICE_HANDLER( i8155_r ) |
| 411 | //------------------------------------------------- |
| 412 | // io_r - register read |
| 413 | //------------------------------------------------- |
| 414 | |
| 415 | READ8_MEMBER( i8155_device::io_r ) |
| 295 | 416 | { |
| 296 | | i8155_t *i8155 = get_safe_token(device); |
| 297 | | |
| 298 | 417 | UINT8 data = 0; |
| 299 | 418 | |
| 300 | 419 | switch (offset & 0x03) |
| 301 | 420 | { |
| 302 | | case I8155_REGISTER_STATUS: |
| 303 | | data = i8155->status; |
| 421 | case REGISTER_STATUS: |
| 422 | data = m_status; |
| 304 | 423 | |
| 305 | | /* clear timer flag */ |
| 306 | | i8155->status &= ~I8155_STATUS_TIMER; |
| 424 | // clear timer flag |
| 425 | m_status &= ~STATUS_TIMER; |
| 307 | 426 | break; |
| 308 | 427 | |
| 309 | | case I8155_REGISTER_PORT_A: |
| 310 | | data = read_port(i8155, I8155_PORT_A); |
| 428 | case REGISTER_PORT_A: |
| 429 | data = read_port(PORT_A); |
| 311 | 430 | break; |
| 312 | 431 | |
| 313 | | case I8155_REGISTER_PORT_B: |
| 314 | | data = read_port(i8155, I8155_PORT_B); |
| 432 | case REGISTER_PORT_B: |
| 433 | data = read_port(PORT_B); |
| 315 | 434 | break; |
| 316 | 435 | |
| 317 | | case I8155_REGISTER_PORT_C: |
| 318 | | data = read_port(i8155, I8155_PORT_C); |
| 436 | case REGISTER_PORT_C: |
| 437 | data = read_port(PORT_C); |
| 319 | 438 | break; |
| 320 | 439 | } |
| 321 | 440 | |
| 322 | 441 | return data; |
| 323 | 442 | } |
| 324 | 443 | |
| 325 | | /*------------------------------------------------- |
| 326 | | i8155_register_w - register write |
| 327 | | -------------------------------------------------*/ |
| 328 | 444 | |
| 329 | | WRITE8_DEVICE_HANDLER( i8155_w ) |
| 445 | //------------------------------------------------- |
| 446 | // register_w - register write |
| 447 | //------------------------------------------------- |
| 448 | |
| 449 | void i8155_device::register_w(int offset, UINT8 data) |
| 330 | 450 | { |
| 331 | | i8155_t *i8155 = get_safe_token(device); |
| 332 | | |
| 333 | 451 | switch (offset & 0x07) |
| 334 | 452 | { |
| 335 | | case I8155_REGISTER_COMMAND: |
| 336 | | i8155->command = data; |
| 453 | case REGISTER_COMMAND: |
| 454 | m_command = data; |
| 337 | 455 | |
| 338 | | if (LOG) logerror("8155 Port A Mode: %s\n", (data & I8155_COMMAND_PA) ? "output" : "input"); |
| 339 | | if (LOG) logerror("8155 Port B Mode: %s\n", (data & I8155_COMMAND_PB) ? "output" : "input"); |
| 456 | if (LOG) logerror("8155 '%s' Port A Mode: %s\n", tag(), (data & COMMAND_PA) ? "output" : "input"); |
| 457 | if (LOG) logerror("8155 '%s' Port B Mode: %s\n", tag(), (data & COMMAND_PB) ? "output" : "input"); |
| 340 | 458 | |
| 341 | | if (LOG) logerror("8155 Port A Interrupt: %s\n", (data & I8155_COMMAND_IEA) ? "enabled" : "disabled"); |
| 342 | | if (LOG) logerror("8155 Port B Interrupt: %s\n", (data & I8155_COMMAND_IEB) ? "enabled" : "disabled"); |
| 459 | if (LOG) logerror("8155 '%s' Port A Interrupt: %s\n", tag(), (data & COMMAND_IEA) ? "enabled" : "disabled"); |
| 460 | if (LOG) logerror("8155 '%s' Port B Interrupt: %s\n", tag(), (data & COMMAND_IEB) ? "enabled" : "disabled"); |
| 343 | 461 | |
| 344 | | switch (data & I8155_COMMAND_PC_MASK) |
| 462 | switch (data & COMMAND_PC_MASK) |
| 345 | 463 | { |
| 346 | | case I8155_COMMAND_PC_ALT_1: |
| 347 | | if (LOG) logerror("8155 Port C Mode: Alt 1\n"); |
| 464 | case COMMAND_PC_ALT_1: |
| 465 | if (LOG) logerror("8155 '%s' Port C Mode: Alt 1\n", tag()); |
| 348 | 466 | break; |
| 349 | 467 | |
| 350 | | case I8155_COMMAND_PC_ALT_2: |
| 351 | | if (LOG) logerror("8155 Port C Mode: Alt 2\n"); |
| 468 | case COMMAND_PC_ALT_2: |
| 469 | if (LOG) logerror("8155 '%s' Port C Mode: Alt 2\n", tag()); |
| 352 | 470 | break; |
| 353 | 471 | |
| 354 | | case I8155_COMMAND_PC_ALT_3: |
| 355 | | if (LOG) logerror("8155 Port C Mode: Alt 3\n"); |
| 472 | case COMMAND_PC_ALT_3: |
| 473 | if (LOG) logerror("8155 '%s' Port C Mode: Alt 3\n", tag()); |
| 356 | 474 | break; |
| 357 | 475 | |
| 358 | | case I8155_COMMAND_PC_ALT_4: |
| 359 | | if (LOG) logerror("8155 Port C Mode: Alt 4\n"); |
| 476 | case COMMAND_PC_ALT_4: |
| 477 | if (LOG) logerror("8155 '%s' Port C Mode: Alt 4\n", tag()); |
| 360 | 478 | break; |
| 361 | 479 | } |
| 362 | 480 | |
| 363 | | switch (data & I8155_COMMAND_TM_MASK) |
| 481 | switch (data & COMMAND_TM_MASK) |
| 364 | 482 | { |
| 365 | | case I8155_COMMAND_TM_NOP: |
| 366 | | /* do not affect counter operation */ |
| 483 | case COMMAND_TM_NOP: |
| 484 | // do not affect counter operation |
| 367 | 485 | break; |
| 368 | 486 | |
| 369 | | case I8155_COMMAND_TM_STOP: |
| 370 | | /* NOP if timer has not started, stop counting if the timer is running */ |
| 371 | | if (LOG) logerror("8155 Timer Command: Stop\n"); |
| 372 | | timer_enable(i8155->timer, 0); |
| 487 | case COMMAND_TM_STOP: |
| 488 | // NOP if timer has not started, stop counting if the timer is running |
| 489 | if (LOG) logerror("8155 '%s' Timer Command: Stop\n", tag()); |
| 490 | timer_enable(m_timer, 0); |
| 373 | 491 | break; |
| 374 | 492 | |
| 375 | | case I8155_COMMAND_TM_STOP_AFTER_TC: |
| 376 | | /* stop immediately after present TC is reached (NOP if timer has not started) */ |
| 377 | | if (LOG) logerror("8155 Timer Command: Stop after TC\n"); |
| 493 | case COMMAND_TM_STOP_AFTER_TC: |
| 494 | // stop immediately after present TC is reached (NOP if timer has not started) |
| 495 | if (LOG) logerror("8155 '%s' Timer Command: Stop after TC\n", tag()); |
| 378 | 496 | break; |
| 379 | 497 | |
| 380 | | case I8155_COMMAND_TM_START: |
| 381 | | if (LOG) logerror("8155 Timer Command: Start\n"); |
| 498 | case COMMAND_TM_START: |
| 499 | if (LOG) logerror("8155 '%s' Timer Command: Start\n", tag()); |
| 382 | 500 | |
| 383 | | if (timer_enabled(i8155->timer)) |
| 501 | if (timer_enabled(m_timer)) |
| 384 | 502 | { |
| 385 | | /* if timer is running, start the new mode and CNT length immediately after present TC is reached */ |
| 503 | // if timer is running, start the new mode and CNT length immediately after present TC is reached |
| 386 | 504 | } |
| 387 | 505 | else |
| 388 | 506 | { |
| 389 | | /* load mode and CNT length and start immediately after loading (if timer is not running) */ |
| 390 | | i8155->counter = i8155->count_length; |
| 391 | | timer_adjust_periodic(i8155->timer, attotime_zero, 0, ATTOTIME_IN_HZ(device->clock())); |
| 507 | // load mode and CNT length and start immediately after loading (if timer is not running) |
| 508 | m_counter = m_count_length; |
| 509 | timer_adjust_periodic(m_timer, attotime_zero, 0, ATTOTIME_IN_HZ(clock())); |
| 392 | 510 | } |
| 393 | 511 | break; |
| 394 | 512 | } |
| 395 | 513 | break; |
| 396 | 514 | |
| 397 | | case I8155_REGISTER_PORT_A: |
| 398 | | write_port(i8155, I8155_PORT_A, data); |
| 515 | case REGISTER_PORT_A: |
| 516 | write_port(PORT_A, data); |
| 399 | 517 | break; |
| 400 | 518 | |
| 401 | | case I8155_REGISTER_PORT_B: |
| 402 | | write_port(i8155, I8155_PORT_B, data); |
| 519 | case REGISTER_PORT_B: |
| 520 | write_port(PORT_B, data); |
| 403 | 521 | break; |
| 404 | 522 | |
| 405 | | case I8155_REGISTER_PORT_C: |
| 406 | | write_port(i8155, I8155_PORT_C, data); |
| 523 | case REGISTER_PORT_C: |
| 524 | write_port(PORT_C, data); |
| 407 | 525 | break; |
| 408 | 526 | |
| 409 | | case I8155_REGISTER_TIMER_LOW: |
| 410 | | i8155->count_length = (i8155->count_length & 0xff00) | data; |
| 411 | | if (LOG) logerror("8155 Count Length Low: %04x\n", i8155->count_length); |
| 527 | case REGISTER_TIMER_LOW: |
| 528 | m_count_length = (m_count_length & 0xff00) | data; |
| 529 | if (LOG) logerror("8155 '%s' Count Length Low: %04x\n", tag(), m_count_length); |
| 412 | 530 | break; |
| 413 | 531 | |
| 414 | | case I8155_REGISTER_TIMER_HIGH: |
| 415 | | i8155->count_length = (data << 8) | (i8155->count_length & 0xff); |
| 416 | | if (LOG) logerror("8155 Count Length High: %04x\n", i8155->count_length); |
| 532 | case REGISTER_TIMER_HIGH: |
| 533 | m_count_length = (data << 8) | (m_count_length & 0xff); |
| 534 | if (LOG) logerror("8155 '%s' Count Length High: %04x\n", tag(), m_count_length); |
| 417 | 535 | |
| 418 | | switch (data & I8155_TIMER_MODE_MASK) |
| 536 | switch (data & TIMER_MODE_MASK) |
| 419 | 537 | { |
| 420 | | case I8155_TIMER_MODE_LOW: |
| 421 | | /* puts out LOW during second half of count */ |
| 422 | | if (LOG) logerror("8155 Timer Mode: LOW\n"); |
| 538 | case TIMER_MODE_LOW: |
| 539 | // puts out LOW during second half of count |
| 540 | if (LOG) logerror("8155 '%s' Timer Mode: LOW\n", tag()); |
| 423 | 541 | break; |
| 424 | 542 | |
| 425 | | case I8155_TIMER_MODE_SQUARE_WAVE: |
| 426 | | /* square wave, i.e. the period of the square wave equals the count length programmed with automatic reload at terminal count */ |
| 427 | | if (LOG) logerror("8155 Timer Mode: Square wave\n"); |
| 543 | case TIMER_MODE_SQUARE_WAVE: |
| 544 | // square wave, i.e. the period of the square wave equals the count length programmed with automatic reload at terminal count |
| 545 | if (LOG) logerror("8155 '%s' Timer Mode: Square wave\n", tag()); |
| 428 | 546 | break; |
| 429 | 547 | |
| 430 | | case I8155_TIMER_MODE_SINGLE_PULSE: |
| 431 | | /* single pulse upon TC being reached */ |
| 432 | | if (LOG) logerror("8155 Timer Mode: Single pulse\n"); |
| 548 | case TIMER_MODE_SINGLE_PULSE: |
| 549 | // single pulse upon TC being reached |
| 550 | if (LOG) logerror("8155 '%s' Timer Mode: Single pulse\n", tag()); |
| 433 | 551 | break; |
| 434 | 552 | |
| 435 | | case I8155_TIMER_MODE_AUTOMATIC_RELOAD: |
| 436 | | /* automatic reload, i.e. single pulse every time TC is reached */ |
| 437 | | if (LOG) logerror("8155 Timer Mode: Automatic reload\n"); |
| 553 | case TIMER_MODE_AUTOMATIC_RELOAD: |
| 554 | // automatic reload, i.e. single pulse every time TC is reached |
| 555 | if (LOG) logerror("8155 '%s' Timer Mode: Automatic reload\n", tag()); |
| 438 | 556 | break; |
| 439 | 557 | } |
| 440 | 558 | break; |
| 441 | 559 | } |
| 442 | 560 | } |
| 443 | 561 | |
| 444 | | /*------------------------------------------------- |
| 445 | | i8155_ram_r - memory read |
| 446 | | -------------------------------------------------*/ |
| 562 | //------------------------------------------------- |
| 563 | // io_w - register write |
| 564 | //------------------------------------------------- |
| 447 | 565 | |
| 448 | | READ8_DEVICE_HANDLER( i8155_ram_r ) |
| 566 | WRITE8_MEMBER( i8155_device::io_w ) |
| 449 | 567 | { |
| 450 | | i8155_t *i8155 = get_safe_token(device); |
| 451 | | |
| 452 | | return i8155->ram[offset & 0xff]; |
| 568 | register_w(offset, data); |
| 453 | 569 | } |
| 454 | 570 | |
| 455 | | /*------------------------------------------------- |
| 456 | | i8155_ram_w - memory write |
| 457 | | -------------------------------------------------*/ |
| 458 | 571 | |
| 459 | | WRITE8_DEVICE_HANDLER( i8155_ram_w ) |
| 460 | | { |
| 461 | | i8155_t *i8155 = get_safe_token(device); |
| 572 | //------------------------------------------------- |
| 573 | // memory_r - internal RAM read |
| 574 | //------------------------------------------------- |
| 462 | 575 | |
| 463 | | i8155->ram[offset & 0xff] = data; |
| 464 | | } |
| 465 | | |
| 466 | | /*------------------------------------------------- |
| 467 | | DEVICE_START( i8155 ) |
| 468 | | -------------------------------------------------*/ |
| 469 | | |
| 470 | | static DEVICE_START( i8155 ) |
| 576 | READ8_MEMBER( i8155_device::memory_r ) |
| 471 | 577 | { |
| 472 | | i8155_t *i8155 = (i8155_t *)downcast<legacy_device_base *>(device)->token(); |
| 473 | | const i8155_interface *intf = get_interface(device); |
| 474 | | |
| 475 | | /* resolve callbacks */ |
| 476 | | devcb_resolve_read8(&i8155->in_port_func[0], &intf->in_pa_func, device); |
| 477 | | devcb_resolve_read8(&i8155->in_port_func[1], &intf->in_pb_func, device); |
| 478 | | devcb_resolve_read8(&i8155->in_port_func[2], &intf->in_pc_func, device); |
| 479 | | devcb_resolve_write8(&i8155->out_port_func[0], &intf->out_pa_func, device); |
| 480 | | devcb_resolve_write8(&i8155->out_port_func[1], &intf->out_pb_func, device); |
| 481 | | devcb_resolve_write8(&i8155->out_port_func[2], &intf->out_pc_func, device); |
| 482 | | devcb_resolve_write_line(&i8155->out_to_func, &intf->out_to_func, device); |
| 483 | | |
| 484 | | /* create the timers */ |
| 485 | | i8155->timer = timer_alloc(device->machine, counter_tick, (void *)device); |
| 486 | | |
| 487 | | /* register for state saving */ |
| 488 | | state_save_register_device_item(device, 0, i8155->command); |
| 489 | | state_save_register_device_item(device, 0, i8155->status); |
| 490 | | state_save_register_device_item_array(device, 0, i8155->output); |
| 491 | | state_save_register_device_item(device, 0, i8155->count_length); |
| 492 | | state_save_register_device_item(device, 0, i8155->counter); |
| 493 | | state_save_register_device_item_array(device, 0, i8155->ram); |
| 494 | | state_save_register_device_item(device, 0, i8155->to); |
| 578 | return this->space()->read_byte(offset); |
| 495 | 579 | } |
| 496 | 580 | |
| 497 | | /*------------------------------------------------- |
| 498 | | DEVICE_RESET( i8155 ) |
| 499 | | -------------------------------------------------*/ |
| 500 | 581 | |
| 501 | | static DEVICE_RESET( i8155 ) |
| 502 | | { |
| 503 | | i8155_t *i8155 = (i8155_t *)downcast<legacy_device_base *>(device)->token(); |
| 582 | //------------------------------------------------- |
| 583 | // memory_w - internal RAM write |
| 584 | //------------------------------------------------- |
| 504 | 585 | |
| 505 | | /* clear output registers */ |
| 506 | | i8155->output[I8155_PORT_A] = 0; |
| 507 | | i8155->output[I8155_PORT_B] = 0; |
| 508 | | i8155->output[I8155_PORT_C] = 0; |
| 509 | | |
| 510 | | /* set ports to input mode */ |
| 511 | | i8155_w(device, I8155_REGISTER_COMMAND, i8155->command & ~(I8155_COMMAND_PA | I8155_COMMAND_PB | I8155_COMMAND_PC_MASK)); |
| 512 | | |
| 513 | | /* clear timer flag */ |
| 514 | | i8155->status &= ~I8155_STATUS_TIMER; |
| 515 | | |
| 516 | | /* stop counting */ |
| 517 | | timer_enable(i8155->timer, 0); |
| 518 | | |
| 519 | | /* clear timer output */ |
| 520 | | i8155->to = 1; |
| 521 | | timer_output(i8155); |
| 522 | | } |
| 523 | | |
| 524 | | /*------------------------------------------------- |
| 525 | | DEVICE_GET_INFO( i8155 ) |
| 526 | | -------------------------------------------------*/ |
| 527 | | |
| 528 | | DEVICE_GET_INFO( i8155 ) |
| 586 | WRITE8_MEMBER( i8155_device::memory_w ) |
| 529 | 587 | { |
| 530 | | switch (state) |
| 531 | | { |
| 532 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 533 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 534 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(i8155_t); break; |
| 535 | | |
| 536 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 537 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(i8155); break; |
| 538 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 539 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(i8155); break; |
| 540 | | |
| 541 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 542 | | case DEVINFO_STR_NAME: strcpy(info->s, "Intel 8155"); break; |
| 543 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "Intel MCS-85"); break; |
| 544 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 545 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 546 | | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright the MESS Team"); break; |
| 547 | | } |
| 588 | this->space()->write_byte(offset, data); |
| 548 | 589 | } |
| 549 | | |
| 550 | | DEFINE_LEGACY_DEVICE(I8155, i8155); |
src/mess/machine/i8212.c
| r9419 | r9420 | |
| 8 | 8 | **********************************************************************/ |
| 9 | 9 | |
| 10 | 10 | #include "emu.h" |
| 11 | #include "machine/devhelpr.h" |
| 11 | 12 | #include "i8212.h" |
| 12 | 13 | |
| 13 | | /*************************************************************************** |
| 14 | | PARAMETERS |
| 15 | | ***************************************************************************/ |
| 16 | 14 | |
| 17 | | #define LOG 1 |
| 18 | 15 | |
| 19 | | /*************************************************************************** |
| 20 | | TYPE DEFINITIONS |
| 21 | | ***************************************************************************/ |
| 16 | //************************************************************************** |
| 17 | // MACROS / CONSTANTS |
| 18 | //************************************************************************** |
| 22 | 19 | |
| 23 | | typedef struct _i8212_t i8212_t; |
| 24 | | struct _i8212_t |
| 25 | | { |
| 26 | | devcb_resolved_write_line out_int_func; |
| 27 | | devcb_resolved_read8 in_di_func; |
| 28 | | devcb_resolved_write8 out_do_func; |
| 20 | #define LOG 0 |
| 29 | 21 | |
| 30 | | int md; /* mode */ |
| 31 | | int stb; /* strobe */ |
| 32 | | UINT8 data; /* data latch */ |
| 33 | | }; |
| 34 | 22 | |
| 35 | | /*************************************************************************** |
| 36 | | INLINE FUNCTIONS |
| 37 | | ***************************************************************************/ |
| 38 | 23 | |
| 39 | | INLINE i8212_t *get_safe_token(running_device *device) |
| 40 | | { |
| 41 | | assert(device != NULL); |
| 42 | | return (i8212_t *)downcast<legacy_device_base *>(device)->token(); |
| 43 | | } |
| 24 | //************************************************************************** |
| 25 | // GLOBAL VARIABLES |
| 26 | //************************************************************************** |
| 44 | 27 | |
| 45 | | INLINE const i8212_interface *get_interface(running_device *device) |
| 46 | | { |
| 47 | | assert(device != NULL); |
| 48 | | assert((device->type() == I8212)); |
| 49 | | return (const i8212_interface *) device->baseconfig().static_config(); |
| 50 | | } |
| 28 | // devices |
| 29 | const device_type I8212 = i8212_device_config::static_alloc_device_config; |
| 51 | 30 | |
| 52 | | /*************************************************************************** |
| 53 | | IMPLEMENTATION |
| 54 | | ***************************************************************************/ |
| 55 | 31 | |
| 56 | | /*------------------------------------------------- |
| 57 | | i8212_r - data output read |
| 58 | | -------------------------------------------------*/ |
| 59 | 32 | |
| 60 | | READ8_DEVICE_HANDLER( i8212_r ) |
| 61 | | { |
| 62 | | i8212_t *i8212 = get_safe_token(device); |
| 33 | //************************************************************************** |
| 34 | // DEVICE CONFIGURATION |
| 35 | //************************************************************************** |
| 63 | 36 | |
| 64 | | /* clear interrupt line */ |
| 65 | | devcb_call_write_line(&i8212->out_int_func, CLEAR_LINE); |
| 37 | GENERIC_DEVICE_CONFIG_SETUP(i8212, "Intel 8212") |
| 66 | 38 | |
| 67 | | if (LOG) logerror("I8212 '%s' INT: %u\n", device->tag(), CLEAR_LINE); |
| 68 | 39 | |
| 69 | | return i8212->data; |
| 70 | | } |
| 40 | //------------------------------------------------- |
| 41 | // device_config_complete - perform any |
| 42 | // operations now that the configuration is |
| 43 | // complete |
| 44 | //------------------------------------------------- |
| 71 | 45 | |
| 72 | | /*------------------------------------------------- |
| 73 | | i8212_w - data input write |
| 74 | | -------------------------------------------------*/ |
| 75 | | |
| 76 | | WRITE8_DEVICE_HANDLER( i8212_w ) |
| 46 | void i8212_device_config::device_config_complete() |
| 77 | 47 | { |
| 78 | | i8212_t *i8212 = get_safe_token(device); |
| 48 | // inherit a copy of the static data |
| 49 | const i8212_interface *intf = reinterpret_cast<const i8212_interface *>(static_config()); |
| 50 | if (intf != NULL) |
| 51 | *static_cast<i8212_interface *>(this) = *intf; |
| 79 | 52 | |
| 80 | | /* latch data */ |
| 81 | | i8212->data = data; |
| 82 | | |
| 83 | | /* output data */ |
| 84 | | devcb_call_write8(&i8212->out_do_func, 0, i8212->data); |
| 53 | // or initialize to defaults if none provided |
| 54 | else |
| 55 | { |
| 56 | memset(&out_int_func, 0, sizeof(out_int_func)); |
| 57 | memset(&in_di_func, 0, sizeof(in_di_func)); |
| 58 | memset(&out_do_func, 0, sizeof(out_do_func)); |
| 59 | } |
| 85 | 60 | } |
| 86 | 61 | |
| 87 | | /*------------------------------------------------- |
| 88 | | i8212_md_w - mode write |
| 89 | | -------------------------------------------------*/ |
| 90 | 62 | |
| 91 | | #ifdef UNUSED_FUNCTION |
| 92 | | WRITE_LINE_DEVICE_HANDLER( i8212_md_w ) |
| 93 | | { |
| 94 | | i8212_t *i8212 = get_safe_token(device); |
| 95 | 63 | |
| 96 | | if (LOG) logerror("I8212 '%s' Mode: %s\n", device->tag(), state ? "output" : "input"); |
| 64 | //************************************************************************** |
| 65 | // LIVE DEVICE |
| 66 | //************************************************************************** |
| 97 | 67 | |
| 98 | | i8212->md = state; |
| 68 | //------------------------------------------------- |
| 69 | // i8212_device - constructor |
| 70 | //------------------------------------------------- |
| 71 | |
| 72 | i8212_device::i8212_device(running_machine &_machine, const i8212_device_config &config) |
| 73 | : device_t(_machine, config), |
| 74 | m_md(I8212_MODE_INPUT), |
| 75 | m_stb(0), |
| 76 | m_config(config) |
| 77 | { |
| 78 | |
| 99 | 79 | } |
| 100 | | #endif |
| 101 | 80 | |
| 102 | | /*------------------------------------------------- |
| 103 | | i8212_stb_w - strobe write |
| 104 | | -------------------------------------------------*/ |
| 105 | 81 | |
| 106 | | WRITE_LINE_DEVICE_HANDLER( i8212_stb_w ) |
| 82 | //------------------------------------------------- |
| 83 | // device_start - device-specific startup |
| 84 | //------------------------------------------------- |
| 85 | |
| 86 | void i8212_device::device_start() |
| 107 | 87 | { |
| 108 | | i8212_t *i8212 = get_safe_token(device); |
| 88 | // resolve callbacks |
| 89 | devcb_resolve_write_line(&m_out_int_func, &m_config.out_int_func, this); |
| 90 | devcb_resolve_read8(&m_in_di_func, &m_config.in_di_func, this); |
| 91 | devcb_resolve_write8(&m_out_do_func, &m_config.out_do_func, this); |
| 109 | 92 | |
| 110 | | if (LOG) logerror("I8212 '%s' STB: %u\n", device->tag(), state); |
| 93 | // register for state saving |
| 94 | state_save_register_device_item(this, 0, m_md); |
| 95 | state_save_register_device_item(this, 0, m_stb); |
| 96 | state_save_register_device_item(this, 0, m_data); |
| 97 | } |
| 111 | 98 | |
| 112 | | if (i8212->md == I8212_MODE_INPUT) |
| 113 | | { |
| 114 | | if (i8212->stb && !state) |
| 115 | | { |
| 116 | | /* input data */ |
| 117 | | i8212->data = devcb_call_read8(&i8212->in_di_func, 0); |
| 118 | 99 | |
| 119 | | /* assert interrupt line */ |
| 120 | | devcb_call_write_line(&i8212->out_int_func, ASSERT_LINE); |
| 100 | //------------------------------------------------- |
| 101 | // device_reset - device-specific reset |
| 102 | //------------------------------------------------- |
| 121 | 103 | |
| 122 | | if (LOG) logerror("I8212 '%s' INT: %u\n", device->tag(), ASSERT_LINE); |
| 123 | | } |
| 124 | | } |
| 104 | void i8212_device::device_reset() |
| 105 | { |
| 106 | m_data = 0; |
| 125 | 107 | |
| 126 | | i8212->stb = state; |
| 108 | if (m_md == I8212_MODE_OUTPUT) |
| 109 | { |
| 110 | // output data |
| 111 | devcb_call_write8(&m_out_do_func, 0, m_data); |
| 112 | } |
| 127 | 113 | } |
| 128 | 114 | |
| 129 | | /*------------------------------------------------- |
| 130 | | DEVICE_START( i8212 ) |
| 131 | | -------------------------------------------------*/ |
| 132 | 115 | |
| 133 | | static DEVICE_START( i8212 ) |
| 116 | //------------------------------------------------- |
| 117 | // data_r - data latch read |
| 118 | //------------------------------------------------- |
| 119 | |
| 120 | READ8_MEMBER( i8212_device::data_r ) |
| 134 | 121 | { |
| 135 | | i8212_t *i8212 = get_safe_token(device); |
| 136 | | const i8212_interface *intf = get_interface(device); |
| 122 | // clear interrupt line |
| 123 | devcb_call_write_line(&m_out_int_func, CLEAR_LINE); |
| 137 | 124 | |
| 138 | | /* resolve callbacks */ |
| 139 | | devcb_resolve_write_line(&i8212->out_int_func, &intf->out_int_func, device); |
| 140 | | devcb_resolve_read8(&i8212->in_di_func, &intf->in_di_func, device); |
| 141 | | devcb_resolve_write8(&i8212->out_do_func, &intf->out_do_func, device); |
| 125 | if (LOG) logerror("I8212 '%s' INT: %u\n", tag(), CLEAR_LINE); |
| 142 | 126 | |
| 143 | | /* register for state saving */ |
| 144 | | state_save_register_device_item(device, 0, i8212->md); |
| 145 | | state_save_register_device_item(device, 0, i8212->stb); |
| 146 | | state_save_register_device_item(device, 0, i8212->data); |
| 127 | return m_data; |
| 147 | 128 | } |
| 148 | 129 | |
| 149 | | /*------------------------------------------------- |
| 150 | | DEVICE_RESET( i8212 ) |
| 151 | | -------------------------------------------------*/ |
| 152 | 130 | |
| 153 | | static DEVICE_RESET( i8212 ) |
| 131 | //------------------------------------------------- |
| 132 | // data_w - data latch write |
| 133 | //------------------------------------------------- |
| 134 | |
| 135 | WRITE8_MEMBER( i8212_device::data_w ) |
| 154 | 136 | { |
| 155 | | i8212_t *i8212 = get_safe_token(device); |
| 137 | // latch data |
| 138 | m_data = data; |
| 156 | 139 | |
| 157 | | i8212->data = 0; |
| 140 | // output data |
| 141 | devcb_call_write8(&m_out_do_func, 0, m_data); |
| 142 | } |
| 158 | 143 | |
| 159 | | if (i8212->md == I8212_MODE_OUTPUT) |
| 160 | | { |
| 161 | | /* output data */ |
| 162 | | devcb_call_write8(&i8212->out_do_func, 0, i8212->data); |
| 163 | | } |
| 144 | |
| 145 | //------------------------------------------------- |
| 146 | // md_w - mode write |
| 147 | //------------------------------------------------- |
| 148 | |
| 149 | WRITE_LINE_MEMBER( i8212_device::md_w ) |
| 150 | { |
| 151 | if (LOG) logerror("I8212 '%s' Mode: %s\n", tag(), state ? "output" : "input"); |
| 152 | |
| 153 | m_md = state; |
| 164 | 154 | } |
| 165 | 155 | |
| 166 | | /*------------------------------------------------- |
| 167 | | DEVICE_GET_INFO( i8212 ) |
| 168 | | -------------------------------------------------*/ |
| 169 | 156 | |
| 170 | | DEVICE_GET_INFO( i8212 ) |
| 157 | //------------------------------------------------- |
| 158 | // stb_w - data strobe write |
| 159 | //------------------------------------------------- |
| 160 | |
| 161 | WRITE_LINE_MEMBER( i8212_device::stb_w ) |
| 171 | 162 | { |
| 172 | | switch (state) |
| 163 | if (LOG) logerror("I8212 '%s' STB: %u\n", tag(), state); |
| 164 | |
| 165 | if (m_md == I8212_MODE_INPUT) |
| 173 | 166 | { |
| 174 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 175 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(i8212_t); break; |
| 176 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 167 | if (m_stb && !state) |
| 168 | { |
| 169 | // input data |
| 170 | m_data = devcb_call_read8(&m_in_di_func, 0); |
| 177 | 171 | |
| 178 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 179 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(i8212); break; |
| 180 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 181 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(i8212); break; |
| 172 | // assert interrupt line |
| 173 | devcb_call_write_line(&m_out_int_func, ASSERT_LINE); |
| 182 | 174 | |
| 183 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 184 | | case DEVINFO_STR_NAME: strcpy(info->s, "Intel 8212"); break; |
| 185 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "Intel MCS-80"); break; |
| 186 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 187 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 188 | | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright MESS Team"); break; |
| 175 | if (LOG) logerror("I8212 '%s' INT: %u\n", tag(), ASSERT_LINE); |
| 176 | } |
| 189 | 177 | } |
| 190 | | } |
| 191 | 178 | |
| 192 | | DEFINE_LEGACY_DEVICE(I8212, i8212); |
| 179 | m_stb = state; |
| 180 | } |
src/mess/machine/i8355.c
| r9419 | r9420 | |
| 7 | 7 | |
| 8 | 8 | **********************************************************************/ |
| 9 | 9 | |
| 10 | | /* |
| 10 | #include "emu.h" |
| 11 | #include "i8355.h" |
| 11 | 12 | |
| 12 | | TODO: |
| 13 | 13 | |
| 14 | | - attempt to direct-map |
| 15 | 14 | |
| 16 | | */ |
| 15 | //************************************************************************** |
| 16 | // MACROS / CONSTANTS |
| 17 | //************************************************************************** |
| 17 | 18 | |
| 18 | | #include "i8355.h" |
| 19 | | |
| 20 | | /*************************************************************************** |
| 21 | | PARAMETERS |
| 22 | | ***************************************************************************/ |
| 23 | | |
| 24 | 19 | #define LOG 0 |
| 25 | 20 | |
| 26 | 21 | enum |
| 27 | 22 | { |
| 28 | | I8355_REGISTER_PORT_A = 0, |
| 29 | | I8355_REGISTER_PORT_B, |
| 30 | | I8355_REGISTER_PORT_A_DDR, |
| 31 | | I8355_REGISTER_PORT_B_DDR |
| 23 | REGISTER_PORT_A = 0, |
| 24 | REGISTER_PORT_B, |
| 25 | REGISTER_PORT_A_DDR, |
| 26 | REGISTER_PORT_B_DDR |
| 32 | 27 | }; |
| 33 | 28 | |
| 34 | 29 | enum |
| r9419 | r9420 | |
| 38 | 33 | PORT_COUNT |
| 39 | 34 | }; |
| 40 | 35 | |
| 41 | | /*************************************************************************** |
| 42 | | TYPE DEFINITIONS |
| 43 | | ***************************************************************************/ |
| 44 | 36 | |
| 45 | | typedef struct _i8355_t i8355_t; |
| 46 | | struct _i8355_t |
| 47 | | { |
| 48 | | devcb_resolved_read8 in_rom_func; |
| 49 | | devcb_resolved_read8 in_port_func[PORT_COUNT]; |
| 50 | | devcb_resolved_write8 out_port_func[PORT_COUNT]; |
| 51 | 37 | |
| 52 | | /* registers */ |
| 53 | | UINT8 output[PORT_COUNT]; /* output latches */ |
| 54 | | UINT8 ddr[PORT_COUNT]; /* DDR latches */ |
| 38 | //************************************************************************** |
| 39 | // GLOBAL VARIABLES |
| 40 | //************************************************************************** |
| 55 | 41 | |
| 56 | | /* ROM */ |
| 57 | | const UINT8 *rom; /* ROM */ |
| 58 | | }; |
| 42 | // devices |
| 43 | const device_type I8355 = i8355_device_config::static_alloc_device_config; |
| 59 | 44 | |
| 60 | | /*************************************************************************** |
| 61 | | INLINE FUNCTIONS |
| 62 | | ***************************************************************************/ |
| 63 | 45 | |
| 64 | | INLINE i8355_t *get_safe_token(running_device *device) |
| 46 | // default address map |
| 47 | static ADDRESS_MAP_START( i8355, 0, 8 ) |
| 48 | AM_RANGE(0x000, 0x7ff) AM_ROM |
| 49 | ADDRESS_MAP_END |
| 50 | |
| 51 | |
| 52 | |
| 53 | //************************************************************************** |
| 54 | // DEVICE CONFIGURATION |
| 55 | //************************************************************************** |
| 56 | |
| 57 | //------------------------------------------------- |
| 58 | // i8355_device_config - constructor |
| 59 | //------------------------------------------------- |
| 60 | |
| 61 | i8355_device_config::i8355_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 62 | : device_config(mconfig, static_alloc_device_config, "Intel 8355", tag, owner, clock), |
| 63 | device_config_memory_interface(mconfig, *this), |
| 64 | m_space_config("ram", ENDIANNESS_LITTLE, 8, 11, 0, NULL, *ADDRESS_MAP_NAME(i8355)) |
| 65 | 65 | { |
| 66 | | assert(device != NULL); |
| 67 | | return (i8355_t *)downcast<legacy_device_base *>(device)->token(); |
| 68 | 66 | } |
| 69 | 67 | |
| 70 | | INLINE const i8355_interface *get_interface(running_device *device) |
| 68 | |
| 69 | //------------------------------------------------- |
| 70 | // static_alloc_device_config - allocate a new |
| 71 | // configuration object |
| 72 | //------------------------------------------------- |
| 73 | |
| 74 | device_config *i8355_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 71 | 75 | { |
| 72 | | assert(device != NULL); |
| 73 | | assert(device->type() == I8355); |
| 74 | | return (const i8355_interface *) device->baseconfig().static_config(); |
| 76 | return global_alloc(i8355_device_config(mconfig, tag, owner, clock)); |
| 75 | 77 | } |
| 76 | 78 | |
| 77 | | INLINE UINT8 read_port(i8355_t *i8355, int port) |
| 79 | |
| 80 | //------------------------------------------------- |
| 81 | // alloc_device - allocate a new device object |
| 82 | //------------------------------------------------- |
| 83 | |
| 84 | device_t *i8355_device_config::alloc_device(running_machine &machine) const |
| 78 | 85 | { |
| 79 | | UINT8 data = i8355->output[port] & i8355->ddr[port]; |
| 86 | return auto_alloc(&machine, i8355_device(machine, *this)); |
| 87 | } |
| 80 | 88 | |
| 81 | | if (i8355->ddr[port] != 0xff) |
| 82 | | { |
| 83 | | data |= devcb_call_read8(&i8355->in_port_func[port], 0) & ~i8355->ddr[port]; |
| 84 | | } |
| 85 | 89 | |
| 86 | | return data; |
| 90 | //------------------------------------------------- |
| 91 | // memory_space_config - return a description of |
| 92 | // any address spaces owned by this device |
| 93 | //------------------------------------------------- |
| 94 | |
| 95 | const address_space_config *i8355_device_config::memory_space_config(int spacenum) const |
| 96 | { |
| 97 | return (spacenum == 0) ? &m_space_config : NULL; |
| 87 | 98 | } |
| 88 | 99 | |
| 89 | | INLINE void write_port(i8355_t *i8355, int port, UINT8 data) |
| 100 | |
| 101 | //------------------------------------------------- |
| 102 | // device_config_complete - perform any |
| 103 | // operations now that the configuration is |
| 104 | // complete |
| 105 | //------------------------------------------------- |
| 106 | |
| 107 | void i8355_device_config::device_config_complete() |
| 90 | 108 | { |
| 91 | | i8355->output[port] = data; |
| 109 | // inherit a copy of the static data |
| 110 | const i8355_interface *intf = reinterpret_cast<const i8355_interface *>(static_config()); |
| 111 | if (intf != NULL) |
| 112 | *static_cast<i8355_interface *>(this) = *intf; |
| 92 | 113 | |
| 93 | | devcb_call_write8(&i8355->out_port_func[port], 0, i8355->output[port] & i8355->ddr[port]); |
| 114 | // or initialize to defaults if none provided |
| 115 | else |
| 116 | { |
| 117 | memset(&in_pa_func, 0, sizeof(in_pa_func)); |
| 118 | memset(&out_pa_func, 0, sizeof(out_pa_func)); |
| 119 | memset(&in_pb_func, 0, sizeof(in_pb_func)); |
| 120 | memset(&out_pb_func, 0, sizeof(out_pb_func)); |
| 121 | } |
| 94 | 122 | } |
| 95 | 123 | |
| 96 | | /*************************************************************************** |
| 97 | | IMPLEMENTATION |
| 98 | | ***************************************************************************/ |
| 99 | 124 | |
| 100 | | /*------------------------------------------------- |
| 101 | | i8355_register_r - register read |
| 102 | | -------------------------------------------------*/ |
| 103 | 125 | |
| 104 | | READ8_DEVICE_HANDLER( i8355_r ) |
| 126 | //************************************************************************** |
| 127 | // INLINE HELPERS |
| 128 | //************************************************************************** |
| 129 | |
| 130 | //------------------------------------------------- |
| 131 | // read_port - read from input port |
| 132 | //------------------------------------------------- |
| 133 | |
| 134 | inline UINT8 i8355_device::read_port(int port) |
| 105 | 135 | { |
| 106 | | i8355_t *i8355 = get_safe_token(device); |
| 107 | | int port = offset & 0x01; |
| 136 | UINT8 data = m_output[port] & m_ddr[port]; |
| 108 | 137 | |
| 109 | | UINT8 data = 0; |
| 110 | | |
| 111 | | switch (offset & 0x03) |
| 138 | if (m_ddr[port] != 0xff) |
| 112 | 139 | { |
| 113 | | case I8355_REGISTER_PORT_A: |
| 114 | | case I8355_REGISTER_PORT_B: |
| 115 | | data = read_port(i8355, port); |
| 116 | | break; |
| 117 | | |
| 118 | | case I8355_REGISTER_PORT_A_DDR: |
| 119 | | case I8355_REGISTER_PORT_B_DDR: |
| 120 | | /* write only */ |
| 121 | | break; |
| 140 | data |= devcb_call_read8(&m_in_port_func[port], 0) & ~m_ddr[port]; |
| 122 | 141 | } |
| 123 | 142 | |
| 124 | 143 | return data; |
| 125 | 144 | } |
| 126 | 145 | |
| 127 | | /*------------------------------------------------- |
| 128 | | i8355_register_w - register write |
| 129 | | -------------------------------------------------*/ |
| 130 | 146 | |
| 131 | | WRITE8_DEVICE_HANDLER( i8355_w ) |
| 147 | //------------------------------------------------- |
| 148 | // write_port - write to output port |
| 149 | //------------------------------------------------- |
| 150 | |
| 151 | inline void i8355_device::write_port(int port, UINT8 data) |
| 132 | 152 | { |
| 133 | | i8355_t *i8355 = get_safe_token(device); |
| 134 | | int port = offset & 0x01; |
| 153 | m_output[port] = data; |
| 135 | 154 | |
| 136 | | switch (offset & 0x03) |
| 137 | | { |
| 138 | | case I8355_REGISTER_PORT_A: |
| 139 | | case I8355_REGISTER_PORT_B: |
| 140 | | if (LOG) logerror("I8355 '%s' Port %c Write %02x\n", device->tag(), 'A' + port, data); |
| 141 | | write_port(i8355, port, data); |
| 142 | | break; |
| 143 | | |
| 144 | | case I8355_REGISTER_PORT_A_DDR: |
| 145 | | case I8355_REGISTER_PORT_B_DDR: |
| 146 | | if (LOG) logerror("I8355 '%s' Port %c DDR: %02x\n", device->tag(), 'A' + port, data); |
| 147 | | i8355->ddr[port] = data; |
| 148 | | write_port(i8355, port, data); |
| 149 | | break; |
| 150 | | } |
| 155 | devcb_call_write8(&m_out_port_func[port], 0, m_output[port] & m_ddr[port]); |
| 151 | 156 | } |
| 152 | 157 | |
| 153 | | /*------------------------------------------------- |
| 154 | | i8355_rom_r - memory read |
| 155 | | -------------------------------------------------*/ |
| 156 | 158 | |
| 157 | | READ8_DEVICE_HANDLER( i8355_rom_r ) |
| 159 | |
| 160 | //************************************************************************** |
| 161 | // LIVE DEVICE |
| 162 | //************************************************************************** |
| 163 | |
| 164 | //------------------------------------------------- |
| 165 | // i8355_device - constructor |
| 166 | //------------------------------------------------- |
| 167 | |
| 168 | i8355_device::i8355_device(running_machine &_machine, const i8355_device_config &config) |
| 169 | : device_t(_machine, config), |
| 170 | device_memory_interface(_machine, config, *this), |
| 171 | m_config(config) |
| 158 | 172 | { |
| 159 | | i8355_t *i8355 = get_safe_token(device); |
| 160 | 173 | |
| 161 | | return i8355->rom[offset & 0x7ff]; |
| 162 | 174 | } |
| 163 | 175 | |
| 164 | | /*------------------------------------------------- |
| 165 | | DEVICE_START( i8355 ) |
| 166 | | -------------------------------------------------*/ |
| 167 | 176 | |
| 168 | | static DEVICE_START( i8355 ) |
| 177 | //------------------------------------------------- |
| 178 | // device_start - device-specific startup |
| 179 | //------------------------------------------------- |
| 180 | |
| 181 | void i8355_device::device_start() |
| 169 | 182 | { |
| 170 | | i8355_t *i8355 = (i8355_t *)downcast<legacy_device_base *>(device)->token(); |
| 171 | | const i8355_interface *intf = get_interface(device); |
| 183 | // resolve callbacks |
| 184 | devcb_resolve_read8(&m_in_port_func[0], &m_config.in_pa_func, this); |
| 185 | devcb_resolve_read8(&m_in_port_func[1], &m_config.in_pb_func, this); |
| 186 | devcb_resolve_write8(&m_out_port_func[0], &m_config.out_pa_func, this); |
| 187 | devcb_resolve_write8(&m_out_port_func[1], &m_config.out_pb_func, this); |
| 172 | 188 | |
| 173 | | /* resolve callbacks */ |
| 174 | | devcb_resolve_read8(&i8355->in_port_func[PORT_A], &intf->in_pa_func, device); |
| 175 | | devcb_resolve_read8(&i8355->in_port_func[PORT_B], &intf->in_pb_func, device); |
| 176 | | devcb_resolve_write8(&i8355->out_port_func[PORT_A], &intf->out_pa_func, device); |
| 177 | | devcb_resolve_write8(&i8355->out_port_func[PORT_B], &intf->out_pb_func, device); |
| 189 | // register for state saving |
| 190 | state_save_register_device_item_array(this, 0, m_output); |
| 191 | state_save_register_device_item_array(this, 0, m_ddr); |
| 192 | } |
| 178 | 193 | |
| 179 | | /* find memory region */ |
| 180 | | i8355->rom = memory_region(device->machine, device->tag()); |
| 181 | | assert(i8355->rom != NULL); |
| 182 | 194 | |
| 183 | | /* register for state saving */ |
| 184 | | state_save_register_device_item_array(device, 0, i8355->output); |
| 185 | | state_save_register_device_item_array(device, 0, i8355->ddr); |
| 195 | //------------------------------------------------- |
| 196 | // device_reset - device-specific reset |
| 197 | //------------------------------------------------- |
| 198 | |
| 199 | void i8355_device::device_reset() |
| 200 | { |
| 201 | // set ports to input mode |
| 202 | m_ddr[PORT_A] = 0; |
| 203 | m_ddr[PORT_B] = 0; |
| 186 | 204 | } |
| 187 | 205 | |
| 188 | | /*------------------------------------------------- |
| 189 | | DEVICE_RESET( i8355 ) |
| 190 | | -------------------------------------------------*/ |
| 191 | 206 | |
| 192 | | static DEVICE_RESET( i8355 ) |
| 207 | //------------------------------------------------- |
| 208 | // io_r - register read |
| 209 | //------------------------------------------------- |
| 210 | |
| 211 | READ8_MEMBER( i8355_device::io_r ) |
| 193 | 212 | { |
| 194 | | i8355_t *i8355 = (i8355_t *)downcast<legacy_device_base *>(device)->token(); |
| 213 | int port = offset & 0x01; |
| 195 | 214 | |
| 196 | | /* set ports to input mode */ |
| 197 | | i8355->ddr[PORT_A] = 0; |
| 198 | | i8355->ddr[PORT_B] = 0; |
| 215 | UINT8 data = 0; |
| 216 | |
| 217 | switch (offset & 0x03) |
| 218 | { |
| 219 | case REGISTER_PORT_A: |
| 220 | case REGISTER_PORT_B: |
| 221 | data = read_port(port); |
| 222 | break; |
| 223 | |
| 224 | case REGISTER_PORT_A_DDR: |
| 225 | case REGISTER_PORT_B_DDR: |
| 226 | // write only |
| 227 | break; |
| 228 | } |
| 229 | |
| 230 | return data; |
| 199 | 231 | } |
| 200 | 232 | |
| 201 | | /*------------------------------------------------- |
| 202 | | DEVICE_GET_INFO( i8355 ) |
| 203 | | -------------------------------------------------*/ |
| 204 | 233 | |
| 205 | | DEVICE_GET_INFO( i8355 ) |
| 234 | //------------------------------------------------- |
| 235 | // io_w - register write |
| 236 | //------------------------------------------------- |
| 237 | |
| 238 | WRITE8_MEMBER( i8355_device::io_w ) |
| 206 | 239 | { |
| 207 | | switch (state) |
| 240 | int port = offset & 0x01; |
| 241 | |
| 242 | switch (offset & 0x03) |
| 208 | 243 | { |
| 209 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 210 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 211 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(i8355_t); break; |
| 244 | case REGISTER_PORT_A: |
| 245 | case REGISTER_PORT_B: |
| 246 | if (LOG) logerror("I8355 '%s' Port %c Write %02x\n", tag(), 'A' + port, data); |
| 247 | |
| 248 | write_port(port, data); |
| 249 | break; |
| 212 | 250 | |
| 213 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 214 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(i8355); break; |
| 215 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 216 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(i8355); break; |
| 217 | | |
| 218 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 219 | | case DEVINFO_STR_NAME: strcpy(info->s, "Intel 8355"); break; |
| 220 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "Intel MCS-85"); break; |
| 221 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 222 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 223 | | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright the MESS Team"); break; |
| 251 | case REGISTER_PORT_A_DDR: |
| 252 | case REGISTER_PORT_B_DDR: |
| 253 | if (LOG) logerror("I8355 '%s' Port %c DDR: %02x\n", tag(), 'A' + port, data); |
| 254 | |
| 255 | m_ddr[port] = data; |
| 256 | write_port(port, data); |
| 257 | break; |
| 224 | 258 | } |
| 225 | 259 | } |
| 226 | 260 | |
| 227 | | DEFINE_LEGACY_DEVICE(I8355, i8355); |
| 261 | |
| 262 | //------------------------------------------------- |
| 263 | // memory_r - internal ROM read |
| 264 | //------------------------------------------------- |
| 265 | |
| 266 | READ8_MEMBER( i8355_device::memory_r ) |
| 267 | { |
| 268 | return this->space()->read_byte(offset); |
| 269 | } |