src/mess/machine/74145.c
| r3810 | r3811 | |
| 46 | 46 | #include "74145.h" |
| 47 | 47 | |
| 48 | 48 | |
| 49 | | |
| 50 | 49 | /***************************************************************************** |
| 51 | | Macros |
| 52 | | *****************************************************************************/ |
| 53 | | |
| 54 | | |
| 55 | | #define MAX_74145 (1) |
| 56 | | |
| 57 | | |
| 58 | | |
| 59 | | /***************************************************************************** |
| 60 | 50 | Type definitions |
| 61 | 51 | *****************************************************************************/ |
| 62 | 52 | |
| 63 | 53 | |
| 64 | | typedef struct _ttl74145_state ttl74145_state; |
| 65 | | struct _ttl74145_state |
| 54 | typedef struct _ttl74145_t ttl74145_t; |
| 55 | struct _ttl74145_t |
| 66 | 56 | { |
| 67 | 57 | /* Pointer to our interface */ |
| 68 | 58 | const ttl74145_interface *intf; |
| r3810 | r3811 | |
| 71 | 61 | UINT16 number; |
| 72 | 62 | }; |
| 73 | 63 | |
| 74 | | |
| 75 | | |
| 76 | 64 | /***************************************************************************** |
| 77 | | Global variables |
| 65 | Implementation |
| 78 | 66 | *****************************************************************************/ |
| 79 | 67 | |
| 68 | INLINE ttl74145_t *get_safe_token(const device_config *device) |
| 69 | { |
| 70 | assert(device != NULL); |
| 71 | assert(device->token != NULL); |
| 80 | 72 | |
| 81 | | static ttl74145_state ttl74145[MAX_74145]; |
| 73 | return (ttl74145_t *)device->token; |
| 74 | } |
| 82 | 75 | |
| 76 | WRITE8_DEVICE_HANDLER( ttl74145_w ) { |
| 77 | /* Decode number */ |
| 78 | ttl74145_t *ttl74145 = get_safe_token(device); |
| 79 | UINT16 new_number = bcd_2_dec(data & 0x0f); |
| 80 | |
| 81 | /* Call output callbacks if the number changed */ |
| 82 | if (new_number != ttl74145->number) |
| 83 | { |
| 84 | const ttl74145_interface *i = ttl74145->intf; |
| 85 | |
| 86 | if (i->output_line_0) i->output_line_0(device, new_number == 0); |
| 87 | if (i->output_line_1) i->output_line_1(device, new_number == 1); |
| 88 | if (i->output_line_2) i->output_line_2(device, new_number == 2); |
| 89 | if (i->output_line_3) i->output_line_3(device, new_number == 3); |
| 90 | if (i->output_line_4) i->output_line_4(device, new_number == 4); |
| 91 | if (i->output_line_5) i->output_line_5(device, new_number == 5); |
| 92 | if (i->output_line_6) i->output_line_6(device, new_number == 6); |
| 93 | if (i->output_line_7) i->output_line_7(device, new_number == 7); |
| 94 | if (i->output_line_8) i->output_line_8(device, new_number == 8); |
| 95 | if (i->output_line_9) i->output_line_9(device, new_number == 9); |
| 96 | } |
| 97 | |
| 98 | /* Update state */ |
| 99 | ttl74145->number = new_number; |
| 100 | } |
| 83 | 101 | |
| 102 | READ16_DEVICE_HANDLER( ttl74145_r ) { |
| 103 | ttl74145_t *ttl74145 = get_safe_token(device); |
| 104 | |
| 105 | return ttl74145->number; |
| 106 | } |
| 84 | 107 | |
| 85 | | /***************************************************************************** |
| 86 | | Implementation |
| 87 | | *****************************************************************************/ |
| 108 | /* Device Interface */ |
| 88 | 109 | |
| 89 | | |
| 90 | | /* Config */ |
| 91 | | void ttl74145_config(running_machine *machine, int which, const ttl74145_interface *intf) |
| 110 | static DEVICE_START( ttl74145 ) |
| 92 | 111 | { |
| 93 | | assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, |
| 94 | | "Can only call ttl74145_config at init time!"); |
| 95 | | assert_always(which < MAX_74145, |
| 96 | | "'which' exceeds maximum number of configured 74145s!"); |
| 112 | ttl74145_t *ttl74145 = get_safe_token(device); |
| 113 | // validate arguments |
| 97 | 114 | |
| 98 | | /* Assign interface */ |
| 99 | | ttl74145[which].intf = intf; |
| 115 | assert(device != NULL); |
| 116 | assert(device->tag != NULL); |
| 117 | assert(strlen(device->tag) < 20); |
| 118 | assert(device->static_config != NULL); |
| 100 | 119 | |
| 101 | | /* Initialize */ |
| 102 | | ttl74145_reset(which); |
| 120 | ttl74145->intf = device->static_config; |
| 121 | ttl74145->number = 0; |
| 122 | |
| 123 | // register for state saving |
| 124 | state_save_register_item(device->machine, "ttl74145", device->tag, 0, ttl74145->number); |
| 125 | return DEVICE_START_OK; |
| 103 | 126 | } |
| 104 | 127 | |
| 128 | static DEVICE_RESET( ttl74145 ) |
| 129 | { |
| 130 | ttl74145_t *ttl74145 = get_safe_token(device); |
| 131 | ttl74145->number = 0; |
| 132 | } |
| 105 | 133 | |
| 106 | | /* Reset */ |
| 107 | | void ttl74145_reset(int which) |
| 134 | static DEVICE_SET_INFO( ttl74145 ) |
| 108 | 135 | { |
| 109 | | ttl74145[which].number = 0; |
| 136 | switch (state) |
| 137 | { |
| 138 | /* no parameters to set */ |
| 139 | } |
| 110 | 140 | } |
| 111 | 141 | |
| 112 | | |
| 113 | | /* Data Write */ |
| 114 | | static void ttl74145_write(int which, offs_t offset, UINT8 data) |
| 142 | DEVICE_GET_INFO( ttl74145 ) |
| 115 | 143 | { |
| 116 | | /* Decode number */ |
| 117 | | UINT16 new_number = bcd_2_dec(data & 0x0f); |
| 118 | | |
| 119 | | /* Call output callbacks if the number changed */ |
| 120 | | if (new_number != ttl74145[which].number) |
| 144 | switch (state) |
| 121 | 145 | { |
| 122 | | const ttl74145_interface *i = ttl74145[which].intf; |
| 146 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 147 | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(ttl74145_t); break; |
| 148 | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 149 | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break; |
| 123 | 150 | |
| 124 | | if (i->output_line_0) i->output_line_0(new_number == 0); |
| 125 | | if (i->output_line_1) i->output_line_1(new_number == 1); |
| 126 | | if (i->output_line_2) i->output_line_2(new_number == 2); |
| 127 | | if (i->output_line_3) i->output_line_3(new_number == 3); |
| 128 | | if (i->output_line_4) i->output_line_4(new_number == 4); |
| 129 | | if (i->output_line_5) i->output_line_5(new_number == 5); |
| 130 | | if (i->output_line_6) i->output_line_6(new_number == 6); |
| 131 | | if (i->output_line_7) i->output_line_7(new_number == 7); |
| 132 | | if (i->output_line_8) i->output_line_8(new_number == 8); |
| 133 | | if (i->output_line_9) i->output_line_9(new_number == 9); |
| 151 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 152 | case DEVINFO_FCT_SET_INFO: info->set_info = DEVICE_SET_INFO_NAME(ttl74145); break; |
| 153 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(ttl74145); break; |
| 154 | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 155 | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(ttl74145); break; |
| 156 | |
| 157 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 158 | case DEVINFO_STR_NAME: info->s = "TTL74145"; break; |
| 159 | case DEVINFO_STR_FAMILY: info->s = "TTL74145"; break; |
| 160 | case DEVINFO_STR_VERSION: info->s = "1.0"; break; |
| 161 | case DEVINFO_STR_SOURCE_FILE: info->s = __FILE__; break; |
| 162 | case DEVINFO_STR_CREDITS: info->s = "Copyright MESS Team"; break; |
| 134 | 163 | } |
| 135 | | |
| 136 | | /* Update state */ |
| 137 | | ttl74145[which].number = new_number; |
| 138 | 164 | } |
| 139 | | |
| 140 | | |
| 141 | | WRITE8_HANDLER( ttl74145_0_w ) { ttl74145_write(0, offset, data); } |
| 142 | | READ16_HANDLER( ttl74145_0_r ) { return ttl74145[0].number; } |
src/mess/machine/74145.h
| r3810 | r3811 | |
| 7 | 7 | #ifndef TTL74145_H_ |
| 8 | 8 | #define TTL74145_H_ |
| 9 | 9 | |
| 10 | /*************************************************************************** |
| 11 | MACROS |
| 12 | ***************************************************************************/ |
| 13 | |
| 14 | #define TTL74145 DEVICE_GET_INFO_NAME(ttl74145) |
| 15 | |
| 16 | /*************************************************************************** |
| 17 | TYPE DEFINITIONS |
| 18 | ***************************************************************************/ |
| 19 | |
| 20 | typedef void (*ttl74145_output_line_func)(const device_config *device, int state); |
| 21 | #define TTL74145_OUTPUT_LINE(name) void name(const device_config *device, int state ) |
| 22 | |
| 23 | |
| 10 | 24 | /* Interface */ |
| 11 | 25 | typedef struct _ttl74145_interface ttl74145_interface; |
| 12 | 26 | struct _ttl74145_interface |
| 13 | 27 | { |
| 14 | 28 | /* Outputs */ |
| 15 | | void (*output_line_0)(int state); |
| 16 | | void (*output_line_1)(int state); |
| 17 | | void (*output_line_2)(int state); |
| 18 | | void (*output_line_3)(int state); |
| 19 | | void (*output_line_4)(int state); |
| 20 | | void (*output_line_5)(int state); |
| 21 | | void (*output_line_6)(int state); |
| 22 | | void (*output_line_7)(int state); |
| 23 | | void (*output_line_8)(int state); |
| 24 | | void (*output_line_9)(int state); |
| 29 | ttl74145_output_line_func output_line_0; |
| 30 | ttl74145_output_line_func output_line_1; |
| 31 | ttl74145_output_line_func output_line_2; |
| 32 | ttl74145_output_line_func output_line_3; |
| 33 | ttl74145_output_line_func output_line_4; |
| 34 | ttl74145_output_line_func output_line_5; |
| 35 | ttl74145_output_line_func output_line_6; |
| 36 | ttl74145_output_line_func output_line_7; |
| 37 | ttl74145_output_line_func output_line_8; |
| 38 | ttl74145_output_line_func output_line_9; |
| 25 | 39 | }; |
| 26 | 40 | |
| 27 | | /* Configuration */ |
| 28 | | void ttl74145_config(running_machine *machine, int which, const ttl74145_interface *intf); |
| 29 | | void ttl74145_reset(int which); |
| 30 | 41 | |
| 42 | /*************************************************************************** |
| 43 | FUNCTION PROTOTYPES |
| 44 | ***************************************************************************/ |
| 45 | |
| 46 | /* device interface */ |
| 47 | DEVICE_GET_INFO( ttl74145 ); |
| 48 | |
| 31 | 49 | /* Standard handlers */ |
| 32 | | WRITE8_HANDLER( ttl74145_0_w ); |
| 33 | | READ16_HANDLER( ttl74145_0_r ); |
| 50 | WRITE8_DEVICE_HANDLER( ttl74145_w ); |
| 51 | READ16_DEVICE_HANDLER( ttl74145_r ); |
| 34 | 52 | |
| 53 | /*************************************************************************** |
| 54 | DEVICE CONFIGURATION MACROS |
| 55 | ***************************************************************************/ |
| 56 | |
| 57 | #define MDRV_TTL74145_ADD(_tag, _intrf) \ |
| 58 | MDRV_DEVICE_ADD(_tag, TTL74145) \ |
| 59 | MDRV_DEVICE_CONFIG(_intrf) |
| 60 | |
| 61 | |
| 35 | 62 | #endif /*TTL74145_H_*/ |
src/mess/machine/sym1.c
| r3810 | r3811 | |
| 33 | 33 | ******************************************************************************/ |
| 34 | 34 | |
| 35 | 35 | |
| 36 | | static void sym1_74145_output_0_w(int state) |
| 36 | TTL74145_OUTPUT_LINE(sym1_74145_output_0_w) |
| 37 | 37 | { |
| 38 | 38 | if (state) timer_adjust_oneshot(led_update, LED_REFRESH_DELAY, 0); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | |
| 42 | | static void sym1_74145_output_1_w(int state) |
| 42 | TTL74145_OUTPUT_LINE(sym1_74145_output_1_w) |
| 43 | 43 | { |
| 44 | 44 | if (state) timer_adjust_oneshot(led_update, LED_REFRESH_DELAY, 1); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | |
| 48 | | static void sym1_74145_output_2_w(int state) |
| 48 | TTL74145_OUTPUT_LINE(sym1_74145_output_2_w) |
| 49 | 49 | { |
| 50 | 50 | if (state) timer_adjust_oneshot(led_update, LED_REFRESH_DELAY, 2); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
| 54 | | static void sym1_74145_output_3_w(int state) |
| 54 | TTL74145_OUTPUT_LINE(sym1_74145_output_3_w) |
| 55 | 55 | { |
| 56 | 56 | if (state) timer_adjust_oneshot(led_update, LED_REFRESH_DELAY, 3); |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | |
| 60 | | static void sym1_74145_output_4_w(int state) |
| 60 | TTL74145_OUTPUT_LINE(sym1_74145_output_4_w) |
| 61 | 61 | { |
| 62 | 62 | if (state) timer_adjust_oneshot(led_update, LED_REFRESH_DELAY, 4); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | |
| 66 | | static void sym1_74145_output_5_w(int state) |
| 66 | TTL74145_OUTPUT_LINE(sym1_74145_output_5_w) |
| 67 | 67 | { |
| 68 | 68 | if (state) timer_adjust_oneshot(led_update, LED_REFRESH_DELAY, 5); |
| 69 | 69 | } |
| r3810 | r3811 | |
| 76 | 76 | |
| 77 | 77 | |
| 78 | 78 | /* The speaker is connected to output 6 of the 74145 */ |
| 79 | | static void sym1_74145_output_6_w(int state) |
| 79 | TTL74145_OUTPUT_LINE(sym1_74145_output_6_w) |
| 80 | 80 | { |
| 81 | 81 | speaker_level_w(0, state); |
| 82 | 82 | } |
| r3810 | r3811 | |
| 137 | 137 | riot_port_b = data; |
| 138 | 138 | |
| 139 | 139 | /* first 4 pins are connected to the 74145 */ |
| 140 | | ttl74145_0_w( cpu_get_address_space( device->machine->cpu[0], ADDRESS_SPACE_PROGRAM ), 0, data & 0x0f); |
| 140 | ttl74145_w( (device_config*)device_list_find_by_tag( device->machine->config->devicelist, TTL74145, "ttl74145" ), 0, data & 0x0f); |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | |
| r3810 | r3811 | |
| 150 | 150 | }; |
| 151 | 151 | |
| 152 | 152 | |
| 153 | | static const ttl74145_interface ttl74145_intf = |
| 153 | const ttl74145_interface sym1_ttl74145_intf = |
| 154 | 154 | { |
| 155 | 155 | sym1_74145_output_0_w, /* connected to DS0 */ |
| 156 | 156 | sym1_74145_output_1_w, /* connected to DS1 */ |
| r3810 | r3811 | |
| 287 | 287 | via_config(1, &via1); |
| 288 | 288 | via_config(2, &via2); |
| 289 | 289 | |
| 290 | | /* configure 74145 */ |
| 291 | | ttl74145_config(machine, 0, &ttl74145_intf); |
| 292 | | |
| 293 | 290 | /* allocate a timer to refresh the led display */ |
| 294 | 291 | led_update = timer_alloc(machine, led_refresh, NULL); |
| 295 | 292 | } |
| r3810 | r3811 | |
| 298 | 295 | MACHINE_RESET( sym1 ) |
| 299 | 296 | { |
| 300 | 297 | via_reset(); |
| 301 | | ttl74145_reset(0); |
| 302 | 298 | |
| 303 | 299 | /* make 0xf800 to 0xffff point to the last half of the monitor ROM |
| 304 | 300 | so that the CPU can find its reset vectors */ |
src/mess/drivers/acrnsys1.c
| r3810 | r3811 | |
| 35 | 35 | |
| 36 | 36 | static WRITE8_DEVICE_HANDLER( ins8154_b1_port_a_w ) |
| 37 | 37 | { |
| 38 | | ttl74145_0_w(cpu_get_address_space(device->machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0, data & 0x07); |
| 38 | ttl74145_w((device_config*)device_list_find_by_tag( device->machine->config->devicelist, TTL74145, "ttl74145" ), 0, data & 0x07); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | static WRITE8_DEVICE_HANDLER( acrnsys1_led_segment_w ) |
| r3810 | r3811 | |
| 54 | 54 | NULL |
| 55 | 55 | }; |
| 56 | 56 | |
| 57 | | static void acrnsys1_7445_output_0_w(int state) { if (state) key_digit = 0; } |
| 58 | | static void acrnsys1_7445_output_1_w(int state) { if (state) key_digit = 1; } |
| 59 | | static void acrnsys1_7445_output_2_w(int state) { if (state) key_digit = 2; } |
| 60 | | static void acrnsys1_7445_output_3_w(int state) { if (state) key_digit = 3; } |
| 61 | | static void acrnsys1_7445_output_4_w(int state) { if (state) key_digit = 4; } |
| 62 | | static void acrnsys1_7445_output_5_w(int state) { if (state) key_digit = 5; } |
| 63 | | static void acrnsys1_7445_output_6_w(int state) { if (state) key_digit = 6; } |
| 64 | | static void acrnsys1_7445_output_7_w(int state) { if (state) key_digit = 7; } |
| 57 | TTL74145_OUTPUT_LINE ( acrnsys1_7445_output_0_w ) { if (state) key_digit = 0; } |
| 58 | TTL74145_OUTPUT_LINE ( acrnsys1_7445_output_1_w ) { if (state) key_digit = 1; } |
| 59 | TTL74145_OUTPUT_LINE ( acrnsys1_7445_output_2_w ) { if (state) key_digit = 2; } |
| 60 | TTL74145_OUTPUT_LINE ( acrnsys1_7445_output_3_w ) { if (state) key_digit = 3; } |
| 61 | TTL74145_OUTPUT_LINE ( acrnsys1_7445_output_4_w ) { if (state) key_digit = 4; } |
| 62 | TTL74145_OUTPUT_LINE ( acrnsys1_7445_output_5_w ) { if (state) key_digit = 5; } |
| 63 | TTL74145_OUTPUT_LINE ( acrnsys1_7445_output_6_w ) { if (state) key_digit = 6; } |
| 64 | TTL74145_OUTPUT_LINE ( acrnsys1_7445_output_7_w ) { if (state) key_digit = 7; } |
| 65 | 65 | |
| 66 | 66 | static const ttl74145_interface ic8_7445 = |
| 67 | 67 | { |
| r3810 | r3811 | |
| 79 | 79 | |
| 80 | 80 | static DRIVER_INIT( acrnsys1 ) |
| 81 | 81 | { |
| 82 | | ttl74145_config(machine, 0, &ic8_7445); |
| 83 | 82 | } |
| 84 | 83 | |
| 85 | 84 | static MACHINE_RESET( acrnsys1 ) |
| 86 | 85 | { |
| 87 | | ttl74145_reset(0); |
| 88 | 86 | } |
| 89 | 87 | |
| 90 | 88 | |
| r3810 | r3811 | |
| 97 | 95 | AM_RANGE(0x0000, 0x03ff) AM_RAM |
| 98 | 96 | AM_RANGE(0x0e00, 0x0e7f) AM_MIRROR(0x100) AM_DEVREADWRITE(INS8154, "b1", ins8154_r, ins8154_w) |
| 99 | 97 | AM_RANGE(0x0e80, 0x0eff) AM_MIRROR(0x100) AM_RAM |
| 100 | | AM_RANGE(0xfe00, 0xffff) AM_MIRROR(0x600) AM_ROM |
| 98 | AM_RANGE(0xfe00, 0xffff) AM_ROM |
| 101 | 99 | ADDRESS_MAP_END |
| 102 | 100 | |
| 103 | 101 | |
| r3810 | r3811 | |
| 189 | 187 | MDRV_DEVICE_CONFIG(ins8154_b1) |
| 190 | 188 | |
| 191 | 189 | MDRV_DEFAULT_LAYOUT(layout_acrnsys1) |
| 190 | |
| 191 | MDRV_TTL74145_ADD("ttl74145", ic8_7445) |
| 192 | 192 | MACHINE_DRIVER_END |
| 193 | 193 | |
| 194 | 194 | |