src/mess/includes/cbmserb.h
| r7067 | r7068 | |
| 1 | | /***************************************************************************** |
| 2 | | * |
| 3 | | * includes/cbmserb.h |
| 4 | | * |
| 5 | | ****************************************************************************/ |
| 6 | | |
| 7 | | #ifndef CBMSERB_H_ |
| 8 | | #define CBMSERB_H_ |
| 9 | | |
| 10 | | /*----------- defined in machine/cbmserb.c -----------*/ |
| 11 | | |
| 12 | | #include "devcb.h" |
| 13 | | |
| 14 | | /*************************************************************************** |
| 15 | | MACROS / CONSTANTS |
| 16 | | ***************************************************************************/ |
| 17 | | |
| 18 | | #define CBM_SERBUS DEVICE_GET_INFO_NAME(cbm_serial_bus) |
| 19 | | |
| 20 | | #define MDRV_CBM_SERBUS_ADD(_tag, _config) \ |
| 21 | | MDRV_DEVICE_ADD(_tag, CBM_SERBUS, 0) \ |
| 22 | | MDRV_DEVICE_CONFIG(_config) |
| 23 | | |
| 24 | | /*************************************************************************** |
| 25 | | TYPE DEFINITIONS |
| 26 | | ***************************************************************************/ |
| 27 | | |
| 28 | | typedef struct _cbm_serial_bus_interface cbm_serial_bus_interface; |
| 29 | | struct _cbm_serial_bus_interface |
| 30 | | { |
| 31 | | devcb_read8 read_atn_func; |
| 32 | | devcb_read8 read_clock_func; |
| 33 | | devcb_read8 read_data_func; |
| 34 | | devcb_read8 read_request_func; |
| 35 | | devcb_write8 write_atn_func; |
| 36 | | devcb_write8 write_clock_func; |
| 37 | | devcb_write8 write_data_func; |
| 38 | | devcb_write8 write_request_func; |
| 39 | | |
| 40 | | devcb_write8 write_reset_func; |
| 41 | | }; |
| 42 | | |
| 43 | | /*************************************************************************** |
| 44 | | PROTOTYPES |
| 45 | | ***************************************************************************/ |
| 46 | | |
| 47 | | /* device interface */ |
| 48 | | DEVICE_GET_INFO( cbm_serial_bus ); |
| 49 | | |
| 50 | | READ8_DEVICE_HANDLER( cbm_serial_request_read ); |
| 51 | | READ8_DEVICE_HANDLER( cbm_serial_atn_read ); |
| 52 | | READ8_DEVICE_HANDLER( cbm_serial_data_read ); |
| 53 | | READ8_DEVICE_HANDLER( cbm_serial_clock_read ); |
| 54 | | |
| 55 | | WRITE8_DEVICE_HANDLER( cbm_serial_request_write ); |
| 56 | | WRITE8_DEVICE_HANDLER( cbm_serial_atn_write ); |
| 57 | | WRITE8_DEVICE_HANDLER( cbm_serial_data_write ); |
| 58 | | WRITE8_DEVICE_HANDLER( cbm_serial_clock_write ); |
| 59 | | |
| 60 | | |
| 61 | | #endif /* CBMSERB_H_ */ |
src/mess/machine/cbmserb.c
| r7067 | r7068 | |
| 1 | | /*************************************************************************** |
| 2 | | |
| 3 | | Commodore Serial Bus |
| 4 | | |
| 5 | | |
| 6 | | |
| 7 | | 2009-05 FP: Changed the implementation to be a MAME device. However, |
| 8 | | the main code has been kept the same as before (to reduce the risk of |
| 9 | | regressions, at this early stage). More work will be eventually done |
| 10 | | to improve emulation and to allow more devices (possibly of different |
| 11 | | kinds) to be connected to the bus like in the real thing. |
| 12 | | Notice that, imho, the current implementation is not very satisfactory: |
| 13 | | it is not really emulating the serial bus, but (in some sense) the plug |
| 14 | | of the devices which would be connected to the serial bus. Hence, the |
| 15 | | provided handlers pass the serial state of the floppy drives to the CPU |
| 16 | | of the main machine. |
| 17 | | As a byproduct of this implementation, the serial_bus device is currently |
| 18 | | tied to the floppy drives (i.e. you will find MDRV_CBM_SERBUS_ADD used |
| 19 | | in the floppy drive MACHINE_DRIVERs, not in the main computer ones) |
| 20 | | |
| 21 | | In other words, don't use this driver as an example of the right way |
| 22 | | to implement serial devices in MAME/MESS! |
| 23 | | |
| 24 | | ***************************************************************************/ |
| 25 | | |
| 26 | | #include "driver.h" |
| 27 | | |
| 28 | | #include "includes/cbmserb.h" |
| 29 | | |
| 30 | | |
| 31 | | /*************************************************************************** |
| 32 | | TYPE DEFINITIONS |
| 33 | | ***************************************************************************/ |
| 34 | | |
| 35 | | typedef struct _cbm_serial_bus_t cbm_serial_bus_t; |
| 36 | | struct _cbm_serial_bus_t |
| 37 | | { |
| 38 | | devcb_resolved_read8 read_atn_func; |
| 39 | | devcb_resolved_read8 read_clock_func; |
| 40 | | devcb_resolved_read8 read_data_func; |
| 41 | | devcb_resolved_read8 read_request_func; |
| 42 | | devcb_resolved_write8 write_atn_func; |
| 43 | | devcb_resolved_write8 write_clock_func; |
| 44 | | devcb_resolved_write8 write_data_func; |
| 45 | | devcb_resolved_write8 write_request_func; |
| 46 | | |
| 47 | | devcb_resolved_write8 write_reset_func; |
| 48 | | }; |
| 49 | | |
| 50 | | /*************************************************************************** |
| 51 | | INLINE FUNCTIONS |
| 52 | | ***************************************************************************/ |
| 53 | | |
| 54 | | INLINE cbm_serial_bus_t *get_safe_token(const device_config *device) |
| 55 | | { |
| 56 | | assert(device != NULL); |
| 57 | | assert(device->token != NULL); |
| 58 | | assert(device->type == CBM_SERBUS); |
| 59 | | return (cbm_serial_bus_t *)device->token; |
| 60 | | } |
| 61 | | |
| 62 | | INLINE const cbm_serial_bus_interface *get_interface(const device_config *device) |
| 63 | | { |
| 64 | | assert(device != NULL); |
| 65 | | assert((device->type == CBM_SERBUS)); |
| 66 | | return (const cbm_serial_bus_interface *) device->static_config; |
| 67 | | } |
| 68 | | |
| 69 | | /*************************************************************************** |
| 70 | | IMPLEMENTATION |
| 71 | | ***************************************************************************/ |
| 72 | | |
| 73 | | |
| 74 | | /* bus handling */ |
| 75 | | READ8_DEVICE_HANDLER( cbm_serial_request_read ) |
| 76 | | { |
| 77 | | cbm_serial_bus_t *serbus = get_safe_token(device); |
| 78 | | UINT8 val; |
| 79 | | |
| 80 | | if (serbus->read_request_func.read != NULL) |
| 81 | | val = devcb_call_read8(&serbus->read_request_func, offset); |
| 82 | | else |
| 83 | | { |
| 84 | | logerror("%s:Serial Bus %s: Request is being read but has no handler\n", cpuexec_describe_context(device->machine), device->tag); |
| 85 | | val = 0; |
| 86 | | } |
| 87 | | |
| 88 | | return val; |
| 89 | | } |
| 90 | | |
| 91 | | WRITE8_DEVICE_HANDLER( cbm_serial_request_write ) |
| 92 | | { |
| 93 | | cbm_serial_bus_t *serbus = get_safe_token(device); |
| 94 | | |
| 95 | | if (serbus->write_request_func.write != NULL) |
| 96 | | devcb_call_write8(&serbus->write_request_func, offset, data); |
| 97 | | else |
| 98 | | logerror("%s:Serial Bus %s: Request is being written but has no handler\n", cpuexec_describe_context(device->machine), device->tag); |
| 99 | | } |
| 100 | | |
| 101 | | READ8_DEVICE_HANDLER( cbm_serial_atn_read ) |
| 102 | | { |
| 103 | | cbm_serial_bus_t *serbus = get_safe_token(device); |
| 104 | | UINT8 val; |
| 105 | | |
| 106 | | if (serbus->read_atn_func.read != NULL) |
| 107 | | val = devcb_call_read8(&serbus->read_atn_func, offset); |
| 108 | | else |
| 109 | | { |
| 110 | | logerror("%s:Serial Bus %s: ATN is being read but has no handler\n", cpuexec_describe_context(device->machine), device->tag); |
| 111 | | val = 0; |
| 112 | | } |
| 113 | | |
| 114 | | return val; |
| 115 | | } |
| 116 | | |
| 117 | | READ8_DEVICE_HANDLER( cbm_serial_data_read ) |
| 118 | | { |
| 119 | | cbm_serial_bus_t *serbus = get_safe_token(device); |
| 120 | | UINT8 val; |
| 121 | | |
| 122 | | if (serbus->read_data_func.read != NULL) |
| 123 | | val = devcb_call_read8(&serbus->read_data_func, offset); |
| 124 | | else |
| 125 | | { |
| 126 | | logerror("%s:Serial Bus %s: Data is being read but has no handler\n", cpuexec_describe_context(device->machine), device->tag); |
| 127 | | val = 0; |
| 128 | | } |
| 129 | | |
| 130 | | return val; |
| 131 | | } |
| 132 | | |
| 133 | | READ8_DEVICE_HANDLER( cbm_serial_clock_read ) |
| 134 | | { |
| 135 | | cbm_serial_bus_t *serbus = get_safe_token(device); |
| 136 | | UINT8 val; |
| 137 | | |
| 138 | | if (serbus->read_clock_func.read != NULL) |
| 139 | | val = devcb_call_read8(&serbus->read_clock_func, offset); |
| 140 | | else |
| 141 | | { |
| 142 | | logerror("%s:Serial Bus %s: Clock is being read but has no handler\n", cpuexec_describe_context(device->machine), device->tag); |
| 143 | | val = 0; |
| 144 | | } |
| 145 | | |
| 146 | | return val; |
| 147 | | } |
| 148 | | |
| 149 | | WRITE8_DEVICE_HANDLER( cbm_serial_atn_write ) |
| 150 | | { |
| 151 | | cbm_serial_bus_t *serbus = get_safe_token(device); |
| 152 | | |
| 153 | | if (serbus->write_atn_func.write != NULL) |
| 154 | | devcb_call_write8(&serbus->write_atn_func, offset, data); |
| 155 | | else |
| 156 | | logerror("%s:Serial Bus %s: ATN is being written but has no handler\n", cpuexec_describe_context(device->machine), device->tag); |
| 157 | | } |
| 158 | | |
| 159 | | WRITE8_DEVICE_HANDLER( cbm_serial_data_write ) |
| 160 | | { |
| 161 | | cbm_serial_bus_t *serbus = get_safe_token(device); |
| 162 | | |
| 163 | | if (serbus->write_data_func.write != NULL) |
| 164 | | devcb_call_write8(&serbus->write_data_func, offset, data); |
| 165 | | else |
| 166 | | logerror("%s:Serial Bus %s: Data is being written but has no handler\n", cpuexec_describe_context(device->machine), device->tag); |
| 167 | | } |
| 168 | | |
| 169 | | WRITE8_DEVICE_HANDLER( cbm_serial_clock_write ) |
| 170 | | { |
| 171 | | cbm_serial_bus_t *serbus = get_safe_token(device); |
| 172 | | |
| 173 | | if (serbus->write_clock_func.write != NULL) |
| 174 | | devcb_call_write8(&serbus->write_clock_func, offset, data); |
| 175 | | else |
| 176 | | logerror("%s:Serial Bus %s: Clock is being written but has no handler\n", cpuexec_describe_context(device->machine), device->tag); |
| 177 | | } |
| 178 | | |
| 179 | | |
| 180 | | /*------------------------------------------------- |
| 181 | | DEVICE_START( cbm_serial_bus ) |
| 182 | | -------------------------------------------------*/ |
| 183 | | |
| 184 | | static DEVICE_START( cbm_serial_bus ) |
| 185 | | { |
| 186 | | cbm_serial_bus_t *serbus = get_safe_token(device); |
| 187 | | const cbm_serial_bus_interface *intf = get_interface(device); |
| 188 | | |
| 189 | | memset(serbus, 0, sizeof(*serbus)); |
| 190 | | |
| 191 | | devcb_resolve_read8(&serbus->read_atn_func, &intf->read_atn_func, device); |
| 192 | | devcb_resolve_read8(&serbus->read_clock_func, &intf->read_clock_func, device); |
| 193 | | devcb_resolve_read8(&serbus->read_data_func, &intf->read_data_func, device); |
| 194 | | devcb_resolve_read8(&serbus->read_request_func, &intf->read_request_func, device); |
| 195 | | devcb_resolve_write8(&serbus->write_atn_func, &intf->write_atn_func, device); |
| 196 | | devcb_resolve_write8(&serbus->write_clock_func, &intf->write_clock_func, device); |
| 197 | | devcb_resolve_write8(&serbus->write_data_func, &intf->write_data_func, device); |
| 198 | | devcb_resolve_write8(&serbus->write_request_func, &intf->write_request_func, device); |
| 199 | | |
| 200 | | devcb_resolve_write8(&serbus->write_reset_func, &intf->write_reset_func, device); |
| 201 | | } |
| 202 | | |
| 203 | | /*------------------------------------------------- |
| 204 | | DEVICE_RESET( cbm_serial_bus ) |
| 205 | | -------------------------------------------------*/ |
| 206 | | |
| 207 | | static DEVICE_RESET( cbm_serial_bus ) |
| 208 | | { |
| 209 | | cbm_serial_bus_t *serbus = get_safe_token(device); |
| 210 | | |
| 211 | | if (serbus->write_reset_func.write != NULL) |
| 212 | | devcb_call_write8(&serbus->write_reset_func, 0, 0); |
| 213 | | else |
| 214 | | logerror("%s:Serial Bus %s: Reset is being written but has no handler\n", cpuexec_describe_context(device->machine), device->tag); |
| 215 | | } |
| 216 | | |
| 217 | | /*------------------------------------------------- |
| 218 | | DEVICE_GET_INFO( cbm_serial_bus ) |
| 219 | | -------------------------------------------------*/ |
| 220 | | |
| 221 | | DEVICE_GET_INFO( cbm_serial_bus ) |
| 222 | | { |
| 223 | | switch (state) |
| 224 | | { |
| 225 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 226 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(cbm_serial_bus_t); break; |
| 227 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 228 | | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break; |
| 229 | | |
| 230 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 231 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(cbm_serial_bus); break; |
| 232 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 233 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(cbm_serial_bus); break; |
| 234 | | |
| 235 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 236 | | case DEVINFO_STR_NAME: strcpy(info->s, "Commodore Serial Bus"); break; |
| 237 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "Commodore Serial Bus"); break; |
| 238 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 239 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 240 | | case DEVINFO_STR_CREDITS: /* Nothing */ break; |
| 241 | | } |
| 242 | | } |