src/mess/includes/cbmserb.h
| r3894 | r3895 | |
| 15 | 15 | struct _cbm_serial_interface |
| 16 | 16 | { |
| 17 | 17 | int serial; /* This is just a parameter, to log which interface is in use */ |
| 18 | | void (*serial_reset_write)(int level); |
| 19 | | int (*serial_request_read)(void); |
| 20 | | void (*serial_request_write)(int level); |
| 21 | | int (*serial_atn_read)(void); |
| 22 | | int (*serial_data_read)(void); |
| 23 | | int (*serial_clock_read)(void); |
| 24 | | void (*serial_atn_write)(int level); |
| 25 | | void (*serial_data_write)(int level); |
| 26 | | void (*serial_clock_write)(int level); |
| 18 | void (*serial_reset_write)(running_machine *machine, int level); |
| 19 | int (*serial_request_read)(running_machine *machine); |
| 20 | void (*serial_request_write)(running_machine *machine, int level); |
| 21 | int (*serial_atn_read)(running_machine *machine); |
| 22 | int (*serial_data_read)(running_machine *machine); |
| 23 | int (*serial_clock_read)(running_machine *machine); |
| 24 | void (*serial_atn_write)(running_machine *machine, int level); |
| 25 | void (*serial_data_write)(running_machine *machine, int level); |
| 26 | void (*serial_clock_write)(running_machine *machine, int level); |
| 27 | 27 | }; |
| 28 | 28 | |
| 29 | 29 | void serial_config(running_machine *machine, const cbm_serial_interface *intf); |
| r3894 | r3895 | |
| 36 | 36 | /* Serial bus for vic20, c64 & c16 with vc1541 and some printer */ |
| 37 | 37 | |
| 38 | 38 | /* To be passed directly to the drivers */ |
| 39 | | void cbm_serial_reset_write (int level); |
| 40 | | int cbm_serial_atn_read (void); |
| 41 | | void cbm_serial_atn_write (int level); |
| 42 | | int cbm_serial_data_read (void); |
| 43 | | void cbm_serial_data_write (int level); |
| 44 | | int cbm_serial_clock_read (void); |
| 45 | | void cbm_serial_clock_write (int level); |
| 46 | | int cbm_serial_request_read (void); |
| 47 | | void cbm_serial_request_write (int level); |
| 39 | void cbm_serial_reset_write (running_machine *machine, int level); |
| 40 | int cbm_serial_atn_read (running_machine *machine); |
| 41 | void cbm_serial_atn_write (running_machine *machine, int level); |
| 42 | int cbm_serial_data_read (running_machine *machine); |
| 43 | void cbm_serial_data_write (running_machine *machine, int level); |
| 44 | int cbm_serial_clock_read (running_machine *machine); |
| 45 | void cbm_serial_clock_write (running_machine *machine, int level); |
| 46 | int cbm_serial_request_read (running_machine *machine); |
| 47 | void cbm_serial_request_write (running_machine *machine, int level); |
| 48 | 48 | |
| 49 | 49 | |
| 50 | 50 | #endif /* CBMSERB_H_ */ |
src/mess/machine/cbmserb.c
| r3894 | r3895 | |
| 4 | 4 | #include <string.h> |
| 5 | 5 | #include "driver.h" |
| 6 | 6 | #include "image.h" |
| 7 | | #include "deprecat.h" |
| 8 | 7 | |
| 9 | 8 | #include "includes/cbmserb.h" |
| 10 | 9 | |
| r3894 | r3895 | |
| 20 | 19 | **************************************/ |
| 21 | 20 | |
| 22 | 21 | |
| 23 | | static void sim_drive_reset_write (int level) |
| 22 | static void sim_drive_reset_write (running_machine *machine, int level) |
| 24 | 23 | { |
| 25 | 24 | int i; |
| 26 | 25 | |
| r3894 | r3895 | |
| 29 | 28 | /* init bus signals */ |
| 30 | 29 | } |
| 31 | 30 | |
| 32 | | static int sim_drive_request_read (void) |
| 31 | static int sim_drive_request_read (running_machine *machine) |
| 33 | 32 | { |
| 34 | 33 | /* in c16 not connected */ |
| 35 | 34 | return 1; |
| 36 | 35 | } |
| 37 | 36 | |
| 38 | | static void sim_drive_request_write (int level) |
| 37 | static void sim_drive_request_write (running_machine *machine, int level) |
| 39 | 38 | { |
| 40 | 39 | } |
| 41 | 40 | |
| 42 | | static int sim_drive_atn_read (void) |
| 41 | static int sim_drive_atn_read (running_machine *machine) |
| 43 | 42 | { |
| 44 | 43 | int i; |
| 45 | 44 | |
| 46 | 45 | cbm_serial.atn[0] = cbm_serial.atn[1]; |
| 47 | 46 | for (i = 0; i < cbm_serial.count; i++) |
| 48 | 47 | cbm_serial.atn[0] &= cbm_serial.atn[i + 2] = |
| 49 | | vc1541_atn_read (Machine, cbm_serial.drives[i]); |
| 48 | vc1541_atn_read (machine, cbm_serial.drives[i]); |
| 50 | 49 | return cbm_serial.atn[0]; |
| 51 | 50 | } |
| 52 | 51 | |
| 53 | | static int sim_drive_data_read (void) |
| 52 | static int sim_drive_data_read (running_machine *machine) |
| 54 | 53 | { |
| 55 | 54 | int i; |
| 56 | 55 | |
| 57 | 56 | cbm_serial.data[0] = cbm_serial.data[1]; |
| 58 | 57 | for (i = 0; i < cbm_serial.count; i++) |
| 59 | 58 | cbm_serial.data[0] &= cbm_serial.data[i + 2] = |
| 60 | | vc1541_data_read (Machine, cbm_serial.drives[i]); |
| 59 | vc1541_data_read (machine, cbm_serial.drives[i]); |
| 61 | 60 | return cbm_serial.data[0]; |
| 62 | 61 | } |
| 63 | 62 | |
| 64 | | static int sim_drive_clock_read (void) |
| 63 | static int sim_drive_clock_read (running_machine *machine) |
| 65 | 64 | { |
| 66 | 65 | int i; |
| 67 | 66 | |
| 68 | 67 | cbm_serial.clock[0] = cbm_serial.clock[1]; |
| 69 | 68 | for (i = 0; i < cbm_serial.count; i++) |
| 70 | 69 | cbm_serial.clock[0] &= cbm_serial.clock[i + 2] = |
| 71 | | vc1541_clock_read (Machine, cbm_serial.drives[i]); |
| 70 | vc1541_clock_read (machine, cbm_serial.drives[i]); |
| 72 | 71 | return cbm_serial.clock[0]; |
| 73 | 72 | } |
| 74 | 73 | |
| 75 | | static void sim_drive_data_write (int level) |
| 74 | static void sim_drive_data_write (running_machine *machine, int level) |
| 76 | 75 | { |
| 77 | 76 | int i; |
| 78 | 77 | |
| r3894 | r3895 | |
| 83 | 82 | cbm_serial.data[0] &= cbm_serial.data[i + 2]; |
| 84 | 83 | /* inform drives */ |
| 85 | 84 | for (i = 0; i < cbm_serial.count; i++) |
| 86 | | vc1541_data_write (Machine, cbm_serial.drives[i], cbm_serial.data[0]); |
| 85 | vc1541_data_write (machine, cbm_serial.drives[i], cbm_serial.data[0]); |
| 87 | 86 | } |
| 88 | 87 | |
| 89 | | static void sim_drive_clock_write (int level) |
| 88 | static void sim_drive_clock_write (running_machine *machine, int level) |
| 90 | 89 | { |
| 91 | 90 | int i; |
| 92 | 91 | |
| r3894 | r3895 | |
| 97 | 96 | cbm_serial.clock[0] &= cbm_serial.clock[i + 2]; |
| 98 | 97 | /* inform drives */ |
| 99 | 98 | for (i = 0; i < cbm_serial.count; i++) |
| 100 | | vc1541_clock_write (Machine, cbm_serial.drives[i], cbm_serial.clock[0]); |
| 99 | vc1541_clock_write (machine, cbm_serial.drives[i], cbm_serial.clock[0]); |
| 101 | 100 | } |
| 102 | 101 | |
| 103 | | static void sim_drive_atn_write (int level) |
| 102 | static void sim_drive_atn_write (running_machine *machine, int level) |
| 104 | 103 | { |
| 105 | 104 | int i; |
| 106 | 105 | |
| r3894 | r3895 | |
| 111 | 110 | cbm_serial.atn[0] &= cbm_serial.atn[i + 2]; |
| 112 | 111 | /* inform drives */ |
| 113 | 112 | for (i = 0; i < cbm_serial.count; i++) |
| 114 | | vc1541_atn_write (Machine, cbm_serial.drives[i], cbm_serial.atn[0]); |
| 113 | vc1541_atn_write (machine, cbm_serial.drives[i], cbm_serial.atn[0]); |
| 115 | 114 | } |
| 116 | 115 | |
| 117 | 116 | |
| r3894 | r3895 | |
| 137 | 136 | **************************************/ |
| 138 | 137 | |
| 139 | 138 | |
| 140 | | static void emu_drive_reset_write( int level ) |
| 139 | static void emu_drive_reset_write( running_machine *machine, int level ) |
| 141 | 140 | { |
| 142 | 141 | vc1541_serial_reset_write(0, level); |
| 143 | 142 | } |
| 144 | 143 | |
| 145 | | static int emu_drive_request_read( void ) |
| 144 | static int emu_drive_request_read( running_machine *machine ) |
| 146 | 145 | { |
| 147 | 146 | return vc1541_serial_request_read(0); |
| 148 | 147 | } |
| 149 | 148 | |
| 150 | | static void emu_drive_request_write( int level ) |
| 149 | static void emu_drive_request_write( running_machine *machine, int level ) |
| 151 | 150 | { |
| 152 | 151 | vc1541_serial_request_write(0, level); |
| 153 | 152 | } |
| 154 | 153 | |
| 155 | | static int emu_drive_atn_read( void ) |
| 154 | static int emu_drive_atn_read( running_machine *machine ) |
| 156 | 155 | { |
| 157 | 156 | return vc1541_serial_atn_read(0); |
| 158 | 157 | } |
| 159 | 158 | |
| 160 | | static int emu_drive_data_read( void ) |
| 159 | static int emu_drive_data_read( running_machine *machine ) |
| 161 | 160 | { |
| 162 | 161 | return vc1541_serial_data_read(0); |
| 163 | 162 | } |
| 164 | 163 | |
| 165 | | static int emu_drive_clock_read( void ) |
| 164 | static int emu_drive_clock_read( running_machine *machine ) |
| 166 | 165 | { |
| 167 | 166 | return vc1541_serial_clock_read(0); |
| 168 | 167 | } |
| 169 | 168 | |
| 170 | | static void emu_drive_atn_write( int level ) |
| 169 | static void emu_drive_atn_write( running_machine *machine, int level ) |
| 171 | 170 | { |
| 172 | | vc1541_serial_atn_write(Machine, 0, level); |
| 171 | vc1541_serial_atn_write(machine, 0, level); |
| 173 | 172 | } |
| 174 | 173 | |
| 175 | | static void emu_drive_data_write( int level ) |
| 174 | static void emu_drive_data_write( running_machine *machine, int level ) |
| 176 | 175 | { |
| 177 | 176 | vc1541_serial_data_write(0, level); |
| 178 | 177 | } |
| 179 | 178 | |
| 180 | | static void emu_drive_clock_write( int level ) |
| 179 | static void emu_drive_clock_write( running_machine *machine, int level ) |
| 181 | 180 | { |
| 182 | 181 | vc1541_serial_clock_write(0, level); |
| 183 | 182 | } |
| r3894 | r3895 | |
| 206 | 205 | |
| 207 | 206 | /* In sx64, c16v & vic20v we use these while fixing handlers for real emulation */ |
| 208 | 207 | |
| 209 | | static void fake_drive_reset_write( int level ) |
| 208 | static void fake_drive_reset_write( running_machine *machine, int level ) |
| 210 | 209 | { |
| 211 | 210 | } |
| 212 | 211 | |
| 213 | | static int fake_drive_request_read( void ) |
| 212 | static int fake_drive_request_read( running_machine *machine ) |
| 214 | 213 | { |
| 215 | 214 | return 0; |
| 216 | 215 | } |
| 217 | 216 | |
| 218 | | static void fake_drive_request_write( int level ) |
| 217 | static void fake_drive_request_write( running_machine *machine, int level ) |
| 219 | 218 | { |
| 220 | 219 | } |
| 221 | 220 | |
| 222 | | static int fake_drive_atn_read( void ) |
| 221 | static int fake_drive_atn_read( running_machine *machine ) |
| 223 | 222 | { |
| 224 | 223 | return 0; |
| 225 | 224 | } |
| 226 | 225 | |
| 227 | | static int fake_drive_data_read( void ) |
| 226 | static int fake_drive_data_read( running_machine *machine ) |
| 228 | 227 | { |
| 229 | 228 | return 0; |
| 230 | 229 | } |
| 231 | 230 | |
| 232 | | static int fake_drive_clock_read( void ) |
| 231 | static int fake_drive_clock_read( running_machine *machine ) |
| 233 | 232 | { |
| 234 | 233 | return 0; |
| 235 | 234 | } |
| 236 | 235 | |
| 237 | | static void fake_drive_atn_write( int level ) |
| 236 | static void fake_drive_atn_write( running_machine *machine, int level ) |
| 238 | 237 | { |
| 239 | 238 | } |
| 240 | 239 | |
| 241 | | static void fake_drive_data_write( int level ) |
| 240 | static void fake_drive_data_write( running_machine *machine, int level ) |
| 242 | 241 | { |
| 243 | 242 | } |
| 244 | 243 | |
| 245 | | static void fake_drive_clock_write( int level ) |
| 244 | static void fake_drive_clock_write( running_machine *machine, int level ) |
| 246 | 245 | { |
| 247 | 246 | } |
| 248 | 247 | |
| r3894 | r3895 | |
| 298 | 297 | |
| 299 | 298 | |
| 300 | 299 | /* bus handling */ |
| 301 | | void cbm_serial_reset_write (int level) |
| 300 | void cbm_serial_reset_write (running_machine *machine, int level) |
| 302 | 301 | { |
| 303 | | serial_intf->serial_reset_write(level); |
| 302 | serial_intf->serial_reset_write(machine, level); |
| 304 | 303 | } |
| 305 | 304 | |
| 306 | | int cbm_serial_request_read (void) |
| 305 | int cbm_serial_request_read (running_machine *machine) |
| 307 | 306 | { |
| 308 | | return serial_intf->serial_request_read(); |
| 307 | return serial_intf->serial_request_read(machine); |
| 309 | 308 | } |
| 310 | 309 | |
| 311 | | void cbm_serial_request_write (int level) |
| 310 | void cbm_serial_request_write (running_machine *machine, int level) |
| 312 | 311 | { |
| 313 | | serial_intf->serial_request_write(level); |
| 312 | serial_intf->serial_request_write(machine, level); |
| 314 | 313 | } |
| 315 | 314 | |
| 316 | | int cbm_serial_atn_read (void) |
| 315 | int cbm_serial_atn_read (running_machine *machine) |
| 317 | 316 | { |
| 318 | | return serial_intf->serial_atn_read(); |
| 317 | return serial_intf->serial_atn_read(machine); |
| 319 | 318 | } |
| 320 | 319 | |
| 321 | | int cbm_serial_data_read (void) |
| 320 | int cbm_serial_data_read (running_machine *machine) |
| 322 | 321 | { |
| 323 | | return serial_intf->serial_data_read(); |
| 322 | return serial_intf->serial_data_read(machine); |
| 324 | 323 | } |
| 325 | 324 | |
| 326 | | int cbm_serial_clock_read (void) |
| 325 | int cbm_serial_clock_read (running_machine *machine) |
| 327 | 326 | { |
| 328 | | return serial_intf->serial_clock_read(); |
| 327 | return serial_intf->serial_clock_read(machine); |
| 329 | 328 | } |
| 330 | 329 | |
| 331 | | void cbm_serial_data_write (int level) |
| 330 | void cbm_serial_data_write (running_machine *machine, int level) |
| 332 | 331 | { |
| 333 | | serial_intf->serial_data_write(level); |
| 332 | serial_intf->serial_data_write(machine, level); |
| 334 | 333 | } |
| 335 | 334 | |
| 336 | | void cbm_serial_clock_write (int level) |
| 335 | void cbm_serial_clock_write (running_machine *machine, int level) |
| 337 | 336 | { |
| 338 | | serial_intf->serial_clock_write(level); |
| 337 | serial_intf->serial_clock_write(machine, level); |
| 339 | 338 | } |
| 340 | 339 | |
| 341 | | void cbm_serial_atn_write (int level) |
| 340 | void cbm_serial_atn_write (running_machine *machine, int level) |
| 342 | 341 | { |
| 343 | | serial_intf->serial_atn_write(level); |
| 342 | serial_intf->serial_atn_write(machine, level); |
| 344 | 343 | } |
src/mess/machine/vc20.c
| r3894 | r3895 | |
| 117 | 117 | /* should be reduced to about 1 or 2 microseconds */ |
| 118 | 118 | /* if ((input_port_read(space->machine, "CTRLSEL") & 0x20 ) && (input_port_read(space->machine, "JOY") & 0x40) ) // i.e. LIGHTPEN_BUTTON |
| 119 | 119 | value &= ~0x20; */ |
| 120 | | if (!serial_clock || !cbm_serial_clock_read ()) |
| 120 | if (!serial_clock || !cbm_serial_clock_read (device->machine)) |
| 121 | 121 | value &= ~0x01; |
| 122 | | if (!serial_data || !cbm_serial_data_read ()) |
| 122 | if (!serial_data || !cbm_serial_data_read (device->machine)) |
| 123 | 123 | value &= ~0x02; |
| 124 | 124 | |
| 125 | 125 | if ((cassette_get_state(device_list_find_by_tag( device->machine->config->devicelist, CASSETTE, "cassette" )) & CASSETTE_MASK_UISTATE) != CASSETTE_STOPPED) |
| r3894 | r3895 | |
| 133 | 133 | static WRITE8_DEVICE_HANDLER( vc20_via0_write_porta ) |
| 134 | 134 | { |
| 135 | 135 | running_machine *machine = device->machine; |
| 136 | | cbm_serial_atn_write (serial_atn = !(data & 0x80)); |
| 136 | cbm_serial_atn_write (machine, serial_atn = !(data & 0x80)); |
| 137 | 137 | DBG_LOG (1, "serial out", ("atn %s\n", serial_atn ? "high" : "low")); |
| 138 | 138 | } |
| 139 | 139 | |
| r3894 | r3895 | |
| 192 | 192 | |
| 193 | 193 | static WRITE8_DEVICE_HANDLER( vc20_via1_write_ca2 ) |
| 194 | 194 | { |
| 195 | | cbm_serial_clock_write (serial_clock = !data); |
| 195 | cbm_serial_clock_write (device->machine, serial_clock = !data); |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | static READ8_DEVICE_HANDLER( vc20_via1_read_portb ) |
| r3894 | r3895 | |
| 333 | 333 | { |
| 334 | 334 | running_machine *machine = device->machine; |
| 335 | 335 | DBG_LOG (1, "serial in", ("request read\n")); |
| 336 | | return cbm_serial_request_read (); |
| 336 | return cbm_serial_request_read (device->machine); |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | static WRITE8_DEVICE_HANDLER( vc20_via1_write_cb2 ) |
| 340 | 340 | { |
| 341 | | cbm_serial_data_write (serial_data = !data); |
| 341 | cbm_serial_data_write (device->machine, serial_data = !data); |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | /* ieee 6522 number 1 (via4) |
| r3894 | r3895 | |
| 623 | 623 | else |
| 624 | 624 | { |
| 625 | 625 | serial_config(machine, &sim_drive_interface); |
| 626 | | cbm_serial_reset_write (0); |
| 626 | cbm_serial_reset_write (machine, 0); |
| 627 | 627 | |
| 628 | 628 | if (ieee) |
| 629 | 629 | { |