src/mess/machine/ti99/crubus.c
| r14515 | r14516 | |
| 1 | | /* |
| 2 | | TI-99 CRU Bus |
| 3 | | */ |
| 4 | | |
| 5 | | #include "emu.h" |
| 6 | | #include "crubus.h" |
| 7 | | |
| 8 | | #define MAXCRU 20 |
| 9 | | |
| 10 | | typedef struct _crubus_dev |
| 11 | | { |
| 12 | | /* The device. */ |
| 13 | | device_t *device; |
| 14 | | |
| 15 | | /* Read access. */ |
| 16 | | cru_read_function cru_read; |
| 17 | | |
| 18 | | /* Write access. */ |
| 19 | | cru_write_function cru_write; |
| 20 | | |
| 21 | | /* Address bits involved. The CRU makes use of the address bus. */ |
| 22 | | UINT16 address_mask; |
| 23 | | |
| 24 | | /* Value of the address bits which are involved for selecting for read. */ |
| 25 | | UINT16 select; |
| 26 | | |
| 27 | | } crubus_dev; |
| 28 | | |
| 29 | | typedef struct _crubus_state |
| 30 | | { |
| 31 | | crubus_dev component[MAXCRU]; |
| 32 | | /* Management function */ |
| 33 | | int devindex; |
| 34 | | |
| 35 | | } crubus_state; |
| 36 | | |
| 37 | | INLINE crubus_state *get_safe_token(device_t *device) |
| 38 | | { |
| 39 | | assert(device != NULL); |
| 40 | | assert(device->type() == CRUBUS); |
| 41 | | |
| 42 | | return (crubus_state *)downcast<legacy_device_base *>(device)->token(); |
| 43 | | } |
| 44 | | |
| 45 | | static void cru_mount_device(device_t *device, device_t *crudev, UINT16 address_mask, UINT16 address_bits, cru_read_function cruread, cru_write_function cruwrite) |
| 46 | | { |
| 47 | | crubus_state *crubus = get_safe_token(device); |
| 48 | | int index = crubus->devindex++; |
| 49 | | // logerror("register cru device %lx\n", (long unsigned int)crudev); |
| 50 | | if (index < MAXCRU) |
| 51 | | { |
| 52 | | if (crubus->component[index].device == NULL) |
| 53 | | { |
| 54 | | crubus->component[index].device = crudev; |
| 55 | | crubus->component[index].cru_read = cruread; |
| 56 | | crubus->component[index].cru_write = cruwrite; |
| 57 | | crubus->component[index].address_mask = address_mask; |
| 58 | | crubus->component[index].select = address_bits; |
| 59 | | } |
| 60 | | } |
| 61 | | } |
| 62 | | |
| 63 | | /*************************************************************************** |
| 64 | | ACCESSOR FUNCTIONS |
| 65 | | ***************************************************************************/ |
| 66 | | |
| 67 | | READ8_DEVICE_HANDLER( ti99_crubus_r ) |
| 68 | | { |
| 69 | | crubus_state *crubus = get_safe_token(device); |
| 70 | | UINT8 reply = 0; |
| 71 | | |
| 72 | | for (int i=0; i < MAXCRU; i++) |
| 73 | | { |
| 74 | | crubus_dev *crudev = &crubus->component[i]; |
| 75 | | if (crubus->component[i].device != NULL) |
| 76 | | { |
| 77 | | if (crudev->cru_read != NULL) |
| 78 | | { |
| 79 | | if (((offset<<4) & crudev->address_mask)==crudev->select) |
| 80 | | { |
| 81 | | // CRU read is implemented as an 8-bit read access. |
| 82 | | // We shift the address for the sake of readability |
| 83 | | // Each read access returns 8 consecutive CRU bits |
| 84 | | // Shift 4 = addr*8*2 |
| 85 | | crudev->cru_read(crudev->device, offset<<4, &reply); |
| 86 | | } |
| 87 | | } |
| 88 | | } |
| 89 | | } |
| 90 | | // printf("cru read %04x = %02x\n", offset<<4, reply); |
| 91 | | |
| 92 | | return reply; |
| 93 | | } |
| 94 | | |
| 95 | | WRITE8_DEVICE_HANDLER( ti99_crubus_w ) |
| 96 | | { |
| 97 | | crubus_state *crubus = get_safe_token(device); |
| 98 | | |
| 99 | | // printf("cru write %04x = %02x\n", offset<<1, data); |
| 100 | | for (int i=0; i < MAXCRU; i++) |
| 101 | | { |
| 102 | | crubus_dev *crudev = &crubus->component[i]; |
| 103 | | if (crubus->component[i].device != NULL) |
| 104 | | { |
| 105 | | if (crudev->cru_write != NULL) |
| 106 | | { |
| 107 | | if (((offset<<1) & crudev->address_mask)==crudev->select) |
| 108 | | { |
| 109 | | // CRU write is implemented as a 1-bit access |
| 110 | | crudev->cru_write(crudev->device, offset<<1, data); |
| 111 | | } |
| 112 | | } |
| 113 | | } |
| 114 | | } |
| 115 | | } |
| 116 | | |
| 117 | | /*************************************************************************** |
| 118 | | DEVICE FUNCTIONS |
| 119 | | ***************************************************************************/ |
| 120 | | |
| 121 | | static DEVICE_START( crubus ) |
| 122 | | { |
| 123 | | int i = 0; |
| 124 | | int done=FALSE; |
| 125 | | cruconf_device *cons = (cruconf_device*)device->static_config(); |
| 126 | | crubus_state *crubus = get_safe_token(device); |
| 127 | | |
| 128 | | logerror("start CRU bus\n"); |
| 129 | | |
| 130 | | crubus->devindex = 0; |
| 131 | | |
| 132 | | while (!done) |
| 133 | | { |
| 134 | | if (cons[i].name != NULL) |
| 135 | | { |
| 136 | | device_t *dev = device->machine().device(cons[i].name); |
| 137 | | if (dev!=NULL) |
| 138 | | cru_mount_device(device, dev, cons[i].address_mask, cons[i].select_pattern, cons[i].read, cons[i].write); |
| 139 | | else |
| 140 | | logerror("ti99_crubus: Device %s not found.\n", cons[i].name); |
| 141 | | } |
| 142 | | else done=TRUE; |
| 143 | | i++; |
| 144 | | } |
| 145 | | } |
| 146 | | |
| 147 | | static DEVICE_STOP( crubus ) |
| 148 | | { |
| 149 | | logerror("stop CRU bus\n"); |
| 150 | | } |
| 151 | | |
| 152 | | static DEVICE_RESET( crubus ) |
| 153 | | { |
| 154 | | logerror("reset CRU bus\n"); |
| 155 | | } |
| 156 | | |
| 157 | | static const char DEVTEMPLATE_SOURCE[] = __FILE__; |
| 158 | | |
| 159 | | #define DEVTEMPLATE_ID(p,s) p##crubus##s |
| 160 | | #define DEVTEMPLATE_FEATURES DT_HAS_START | DT_HAS_STOP | DT_HAS_RESET |
| 161 | | #define DEVTEMPLATE_NAME "TI99 CRU bus system" |
| 162 | | #define DEVTEMPLATE_FAMILY "Internal devices" |
| 163 | | #include "devtempl.h" |
| 164 | | |
| 165 | | DEFINE_LEGACY_DEVICE( CRUBUS, crubus ); |