src/mess/devices/cococart.c
| r9294 | r9295 | |
| 18 | 18 | #define CARTSLOT_TAG "cart" |
| 19 | 19 | #define LOG_LINE 0 |
| 20 | 20 | |
| 21 | /* TIMER_POOL: Must be power of two */ |
| 22 | #define TIMER_POOL 2 |
| 21 | 23 | |
| 22 | 24 | /*************************************************************************** |
| 23 | 25 | TYPE DEFINITIONS |
| r9294 | r9295 | |
| 26 | 28 | typedef struct _coco_cartridge_line coco_cartridge_line; |
| 27 | 29 | struct _coco_cartridge_line |
| 28 | 30 | { |
| 29 | | emu_timer *timer; |
| 30 | | UINT32 delay; /* in clock cycles */ |
| 31 | emu_timer *timer[TIMER_POOL]; |
| 32 | int timer_index; |
| 33 | int delay; |
| 31 | 34 | cococart_line_value value; |
| 32 | 35 | int line; |
| 33 | 36 | int q_count; |
| r9294 | r9295 | |
| 84 | 87 | running_device *cartslot; |
| 85 | 88 | coco_cartridge_t *cococart = get_token(device); |
| 86 | 89 | const cococart_config *config = (const cococart_config *) downcast<const legacy_device_config_base &>(device->baseconfig()).inline_config(); |
| 87 | | |
| 90 | int i; |
| 91 | |
| 88 | 92 | /* initialize */ |
| 89 | 93 | memset(cococart, 0, sizeof(*cococart)); |
| 90 | 94 | |
| r9294 | r9295 | |
| 103 | 107 | } |
| 104 | 108 | |
| 105 | 109 | /* finish setup */ |
| 106 | | cococart->cart_line.timer = timer_alloc(device->machine, cart_timer_callback, (void *) device); |
| 107 | | cococart->cart_line.delay = 0; |
| 108 | | cococart->cart_line.callback = config->cart_callback; |
| 109 | | cococart->nmi_line.timer = timer_alloc(device->machine, nmi_timer_callback, (void *) device); |
| 110 | | cococart->nmi_line.delay = 0; |
| 111 | | cococart->nmi_line.callback = config->nmi_callback; |
| 112 | | cococart->halt_line.timer = timer_alloc(device->machine, halt_timer_callback, (void *) device); |
| 113 | | cococart->halt_line.delay = 7; |
| 114 | | cococart->halt_line.callback = config->halt_callback; |
| 110 | |
| 111 | for( i=0; i<TIMER_POOL; i++ ) |
| 112 | { |
| 113 | cococart->cart_line.timer[i] = timer_alloc(device->machine, cart_timer_callback, (void *) device); |
| 114 | cococart->nmi_line.timer[i] = timer_alloc(device->machine, nmi_timer_callback, (void *) device); |
| 115 | cococart->halt_line.timer[i] = timer_alloc(device->machine, halt_timer_callback, (void *) device); |
| 116 | } |
| 117 | |
| 118 | cococart->cart_line.timer_index = 0; |
| 119 | cococart->cart_line.delay = 0; |
| 120 | cococart->cart_line.callback = config->cart_callback; |
| 121 | |
| 122 | cococart->nmi_line.timer_index = 0; |
| 123 | /* 12 allowed one more instruction to finished after the line is pulled */ |
| 124 | cococart->nmi_line.delay = 12; |
| 125 | cococart->nmi_line.callback = config->nmi_callback; |
| 126 | |
| 127 | cococart->halt_line.timer_index = 0; |
| 128 | /* 6 allowed one more instruction to finished after the line is pulled */ |
| 129 | cococart->halt_line.delay = 6; |
| 130 | cococart->halt_line.callback = config->halt_callback; |
| 115 | 131 | } |
| 116 | 132 | |
| 117 | 133 | |
| r9294 | r9295 | |
| 181 | 197 | line->value = value; |
| 182 | 198 | |
| 183 | 199 | if (LOG_LINE) |
| 184 | | logerror("[%s]: set_line(): %s <= %s", cpuexec_describe_context(device->machine), line_name, line_value_string(value)); |
| 200 | logerror("[%s]: set_line(): %s <= %s\n", cpuexec_describe_context(device->machine), line_name, line_value_string(value)); |
| 185 | 201 | |
| 186 | 202 | /* engage in a bit of gymnastics for this odious 'Q' value */ |
| 187 | 203 | switch(line->value) |
| r9294 | r9295 | |
| 249 | 265 | |
| 250 | 266 | static void set_line_timer(running_device *device, coco_cartridge_line *line, cococart_line_value value) |
| 251 | 267 | { |
| 252 | | /* calculate delay; it isn't clear why we have to do this every single time */ |
| 268 | /* calculate delay; delay dependant on cycles per second */ |
| 253 | 269 | attotime delay = (line->delay != 0) |
| 254 | 270 | ? device->machine->firstcpu->cycles_to_attotime(line->delay) |
| 255 | 271 | : attotime_zero; |
| 256 | 272 | |
| 257 | | timer_adjust_oneshot(line->timer, delay, (int) value); |
| 273 | timer_adjust_oneshot(line->timer[line->timer_index], delay, (int) value); |
| 274 | line->timer_index = (line->timer_index + 1) % TIMER_POOL; |
| 258 | 275 | } |
| 259 | 276 | |
| 260 | 277 | |