src/mess/drivers/ptcsol.c
| r10104 | r10105 | |
| 32 | 32 | #include "imagedev/cassette.h" |
| 33 | 33 | #include "machine/ay31015.h" |
| 34 | 34 | |
| 35 | typedef struct { |
| 36 | struct { |
| 37 | int length; /* time cassette level is at input.level */ |
| 38 | int level; /* cassette level */ |
| 39 | int bit; /* bit being read */ |
| 40 | } input; |
| 41 | struct { |
| 42 | int length; /* time cassette level is at output.level */ |
| 43 | int level; /* cassette level */ |
| 44 | int bit; /* bit to to output */ |
| 45 | } output; |
| 46 | } cass_data_t; |
| 35 | 47 | |
| 36 | 48 | class sol20_state : public driver_device |
| 37 | 49 | { |
| r10104 | r10105 | |
| 39 | 51 | sol20_state(running_machine &machine, const driver_device_config_base &config) |
| 40 | 52 | : driver_device(machine, config), |
| 41 | 53 | m_maincpu(*this, "maincpu"), |
| 42 | | m_cass_1(*this, "cassette1"), |
| 43 | | m_cass_2(*this, "cassette2"), |
| 54 | m_cass1(*this, "cassette1"), |
| 55 | m_cass2(*this, "cassette2"), |
| 44 | 56 | m_uart_c(*this, "uart_c"), |
| 45 | 57 | m_uart_s(*this, "uart_s"), |
| 46 | 58 | m_terminal(*this, TERMINAL_TAG) |
| 47 | 59 | { } |
| 48 | 60 | |
| 49 | 61 | required_device<cpu_device> m_maincpu; |
| 50 | | required_device<device_t> m_cass_1; |
| 51 | | required_device<device_t> m_cass_2; |
| 62 | required_device<device_t> m_cass1; |
| 63 | required_device<device_t> m_cass2; |
| 52 | 64 | required_device<device_t> m_uart_c; |
| 53 | 65 | required_device<device_t> m_uart_s; |
| 54 | 66 | required_device<device_t> m_terminal; |
| 55 | 67 | DECLARE_READ8_MEMBER( sol20_fa_r ); |
| 68 | DECLARE_READ8_MEMBER( sol20_fb_r ); |
| 56 | 69 | DECLARE_READ8_MEMBER( sol20_fc_r ); |
| 70 | DECLARE_WRITE8_MEMBER( sol20_fa_w ); |
| 71 | DECLARE_WRITE8_MEMBER( sol20_fb_w ); |
| 57 | 72 | DECLARE_WRITE8_MEMBER( sol20_fe_w ); |
| 58 | 73 | DECLARE_WRITE8_MEMBER( sol20_kbd_put ); |
| 59 | 74 | UINT8 m_sol20_fa; |
| r10104 | r10105 | |
| 62 | 77 | const UINT8 *FNT; |
| 63 | 78 | const UINT8 *m_videoram; |
| 64 | 79 | UINT8 m_framecnt; |
| 80 | emu_timer *m_cassette_timer; |
| 81 | cass_data_t m_cass_data; |
| 65 | 82 | }; |
| 66 | 83 | |
| 67 | 84 | |
| 85 | /* timer to read cassette waveforms */ |
| 68 | 86 | |
| 87 | |
| 88 | static device_t *cassette_device_image(running_machine *machine) |
| 89 | { |
| 90 | sol20_state *state = machine->driver_data<sol20_state>(); |
| 91 | if (state->m_sol20_fa & 0x40) |
| 92 | return machine->device("cassette2"); |
| 93 | else |
| 94 | return machine->device("cassette1"); |
| 95 | } |
| 96 | |
| 97 | |
| 98 | // identical to sorcerer |
| 99 | static TIMER_CALLBACK(sol20_cassette_tc) |
| 100 | { |
| 101 | sol20_state *state = machine->driver_data<sol20_state>(); |
| 102 | UINT8 cass_ws = 0; |
| 103 | switch (state->m_sol20_fa & 0x20) |
| 104 | { |
| 105 | case 0x20: /* Cassette 300 baud */ |
| 106 | |
| 107 | /* loading a tape - this is basically the same as the super80. |
| 108 | We convert the 1200/2400 Hz signal to a 0 or 1, and send it to the uart. */ |
| 109 | |
| 110 | state->m_cass_data.input.length++; |
| 111 | |
| 112 | cass_ws = (cassette_input(cassette_device_image(machine)) > +0.02) ? 1 : 0; |
| 113 | |
| 114 | if (cass_ws != state->m_cass_data.input.level) |
| 115 | { |
| 116 | state->m_cass_data.input.level = cass_ws; |
| 117 | state->m_cass_data.input.bit = ((state->m_cass_data.input.length < 0x6) || (state->m_cass_data.input.length > 0x20)) ? 1 : 0; |
| 118 | state->m_cass_data.input.length = 0; |
| 119 | ay31015_set_input_pin( state->m_uart_c, AY31015_SI, state->m_cass_data.input.bit ); |
| 120 | } |
| 121 | |
| 122 | /* saving a tape - convert the serial stream from the uart, into 1200 and 2400 Hz frequencies. |
| 123 | Synchronisation of the frequency pulses to the uart is extremely important. */ |
| 124 | |
| 125 | state->m_cass_data.output.length++; |
| 126 | if (!(state->m_cass_data.output.length & 0x1f)) |
| 127 | { |
| 128 | cass_ws = ay31015_get_output_pin( state->m_uart_c, AY31015_SO ); |
| 129 | if (cass_ws != state->m_cass_data.output.bit) |
| 130 | { |
| 131 | state->m_cass_data.output.bit = cass_ws; |
| 132 | state->m_cass_data.output.length = 0; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | if (!(state->m_cass_data.output.length & 3)) |
| 137 | { |
| 138 | if (!((state->m_cass_data.output.bit == 0) && (state->m_cass_data.output.length & 4))) |
| 139 | { |
| 140 | state->m_cass_data.output.level ^= 1; // toggle output state, except on 2nd half of low bit |
| 141 | cassette_output(cassette_device_image(machine), state->m_cass_data.output.level ? -1.0 : +1.0); |
| 142 | } |
| 143 | } |
| 144 | return; |
| 145 | |
| 146 | case 0x00: /* Cassette 1200 baud */ |
| 147 | /* loading a tape */ |
| 148 | state->m_cass_data.input.length++; |
| 149 | |
| 150 | cass_ws = (cassette_input(cassette_device_image(machine)) > +0.02) ? 1 : 0; |
| 151 | |
| 152 | if (cass_ws != state->m_cass_data.input.level || state->m_cass_data.input.length == 10) |
| 153 | { |
| 154 | state->m_cass_data.input.bit = ((state->m_cass_data.input.length < 10) || (state->m_cass_data.input.length > 0x20)) ? 1 : 0; |
| 155 | if ( cass_ws != state->m_cass_data.input.level ) |
| 156 | { |
| 157 | state->m_cass_data.input.length = 0; |
| 158 | state->m_cass_data.input.level = cass_ws; |
| 159 | } |
| 160 | ay31015_set_input_pin( state->m_uart_c, AY31015_SI, state->m_cass_data.input.bit ); |
| 161 | } |
| 162 | |
| 163 | /* saving a tape - convert the serial stream from the uart, into 600 and 1200 Hz frequencies. */ |
| 164 | |
| 165 | state->m_cass_data.output.length++; |
| 166 | if (!(state->m_cass_data.output.length & 7)) |
| 167 | { |
| 168 | cass_ws = ay31015_get_output_pin( state->m_uart_c, AY31015_SO ); |
| 169 | if (cass_ws != state->m_cass_data.output.bit) |
| 170 | { |
| 171 | state->m_cass_data.output.bit = cass_ws; |
| 172 | state->m_cass_data.output.length = 0; |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | if (!(state->m_cass_data.output.length & 7)) |
| 177 | { |
| 178 | if (!((state->m_cass_data.output.bit == 0) && (state->m_cass_data.output.length & 8))) |
| 179 | { |
| 180 | state->m_cass_data.output.level ^= 1; // toggle output state, except on 2nd half of low bit |
| 181 | cassette_output(cassette_device_image(machine), state->m_cass_data.output.level ? -1.0 : +1.0); |
| 182 | } |
| 183 | } |
| 184 | return; |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | |
| 69 | 189 | READ8_MEMBER( sol20_state::sol20_fa_r ) |
| 70 | 190 | { |
| 71 | | return m_sol20_fa; |
| 191 | /* set unused bits high */ |
| 192 | UINT8 data = 0x26; |
| 193 | |
| 194 | ay31015_set_input_pin( m_uart_c, AY31015_SWE, 0 ); |
| 195 | data |= ay31015_get_output_pin( m_uart_c, AY31015_TBMT ) ? 0x80 : 0; |
| 196 | data |= ay31015_get_output_pin( m_uart_c, AY31015_DAV ) ? 0x40 : 0; |
| 197 | data |= ay31015_get_output_pin( m_uart_c, AY31015_OR ) ? 0x10 : 0; |
| 198 | data |= ay31015_get_output_pin( m_uart_c, AY31015_FE ) ? 0x08 : 0; |
| 199 | ay31015_set_input_pin( m_uart_c, AY31015_SWE, 1 ); |
| 200 | |
| 201 | return data | (m_sol20_fa & 1); |
| 72 | 202 | } |
| 73 | 203 | |
| 204 | READ8_MEMBER( sol20_state::sol20_fb_r) |
| 205 | { |
| 206 | UINT8 data = ay31015_get_received_data( m_uart_c ); |
| 207 | ay31015_set_input_pin( m_uart_c, AY31015_RDAV, 0 ); |
| 208 | ay31015_set_input_pin( m_uart_c, AY31015_RDAV, 1 ); |
| 209 | return data; |
| 210 | } |
| 211 | |
| 74 | 212 | READ8_MEMBER( sol20_state::sol20_fc_r ) |
| 75 | 213 | { |
| 76 | | m_sol20_fa = 0xff; |
| 214 | m_sol20_fa |= 1; |
| 77 | 215 | return m_sol20_fc; |
| 78 | 216 | } |
| 79 | 217 | |
| 218 | WRITE8_MEMBER( sol20_state::sol20_fa_w ) |
| 219 | { |
| 220 | m_sol20_fa &= 1; |
| 221 | m_sol20_fa |= (data & 0xf0); |
| 222 | |
| 223 | /* cassette 1 motor */ |
| 224 | cassette_change_state(m_cass1, |
| 225 | (BIT(data, 7)) ? CASSETTE_MOTOR_ENABLED : CASSETTE_MOTOR_DISABLED, CASSETTE_MASK_MOTOR); |
| 226 | |
| 227 | /* cassette 2 motor */ |
| 228 | cassette_change_state(m_cass2, |
| 229 | (BIT(data, 6)) ? CASSETTE_MOTOR_ENABLED : CASSETTE_MOTOR_DISABLED, CASSETTE_MASK_MOTOR); |
| 230 | |
| 231 | if (data & 0xc0) |
| 232 | timer_adjust_periodic(m_cassette_timer, attotime_zero, 0, ATTOTIME_IN_HZ(19200)); |
| 233 | else |
| 234 | timer_adjust_oneshot(m_cassette_timer, attotime_zero, 0); |
| 235 | |
| 236 | // bit 5 baud rate */ |
| 237 | ay31015_set_receiver_clock( m_uart_c, (BIT(data, 5)) ? 4800.0 : 19200.0); |
| 238 | ay31015_set_transmitter_clock( m_uart_c, (BIT(data, 5)) ? 4800.0 : 19200.0); |
| 239 | } |
| 240 | |
| 241 | WRITE8_MEMBER( sol20_state::sol20_fb_w ) |
| 242 | { |
| 243 | ay31015_set_transmit_data( m_uart_c, data ); |
| 244 | } |
| 245 | |
| 80 | 246 | WRITE8_MEMBER( sol20_state::sol20_fe_w ) |
| 81 | 247 | { |
| 82 | 248 | m_sol20_fe = data; |
| r10104 | r10105 | |
| 94 | 260 | static ADDRESS_MAP_START( sol20_io , ADDRESS_SPACE_IO, 8, sol20_state) |
| 95 | 261 | ADDRESS_MAP_UNMAP_HIGH |
| 96 | 262 | ADDRESS_MAP_GLOBAL_MASK(0xff) |
| 97 | | AM_RANGE(0xfa, 0xfa) AM_READ(sol20_fa_r) |
| 263 | AM_RANGE(0xfa, 0xfa) AM_READWRITE(sol20_fa_r,sol20_fa_w) |
| 264 | AM_RANGE(0xfb, 0xfb) AM_READWRITE(sol20_fb_r,sol20_fb_w) |
| 98 | 265 | AM_RANGE(0xfc, 0xfc) AM_READ(sol20_fc_r) |
| 99 | 266 | AM_RANGE(0xfe, 0xfe) AM_WRITE(sol20_fe_w) |
| 100 | 267 | /* AM_RANGE(0xf8, 0xf8) serial status in (bit 6=data av, bit 7=tmbe) |
| r10104 | r10105 | |
| 137 | 304 | memory_set_bank(machine, "boot", 0); |
| 138 | 305 | } |
| 139 | 306 | |
| 307 | static MACHINE_START( sol20 ) |
| 308 | { |
| 309 | sol20_state *state = machine->driver_data<sol20_state>(); |
| 310 | state->m_cassette_timer = timer_alloc(machine, sol20_cassette_tc, NULL); |
| 311 | } |
| 312 | |
| 140 | 313 | static MACHINE_RESET( sol20 ) |
| 141 | 314 | { |
| 142 | 315 | sol20_state *state = machine->driver_data<sol20_state>(); |
| 143 | | state->m_sol20_fa=0xff; |
| 144 | 316 | state->m_sol20_fe=0; |
| 317 | state->m_sol20_fa=1; |
| 318 | // set hard-wired uart pins |
| 319 | ay31015_set_input_pin( state->m_uart_c, AY31015_CS, 0 ); |
| 320 | ay31015_set_input_pin( state->m_uart_c, AY31015_NB1, 1); |
| 321 | ay31015_set_input_pin( state->m_uart_c, AY31015_NB2, 1); |
| 322 | ay31015_set_input_pin( state->m_uart_c, AY31015_TSB, 1); |
| 323 | ay31015_set_input_pin( state->m_uart_c, AY31015_EPS, 1); |
| 324 | ay31015_set_input_pin( state->m_uart_c, AY31015_NP, 1); |
| 325 | ay31015_set_input_pin( state->m_uart_c, AY31015_CS, 1 ); |
| 326 | // boot-bank |
| 145 | 327 | memory_set_bank(machine, "boot", 1); |
| 146 | | timer_set(machine, ATTOTIME_IN_USEC(10), NULL, 0, sol20_boot); |
| 328 | timer_set(machine, ATTOTIME_IN_USEC(9), NULL, 0, sol20_boot); |
| 147 | 329 | } |
| 148 | 330 | |
| 149 | 331 | static DRIVER_INIT( sol20 ) |
| r10104 | r10105 | |
| 228 | 410 | MCFG_CPU_PROGRAM_MAP(sol20_mem) |
| 229 | 411 | MCFG_CPU_IO_MAP(sol20_io) |
| 230 | 412 | |
| 413 | MCFG_MACHINE_START(sol20) |
| 231 | 414 | MCFG_MACHINE_RESET(sol20) |
| 232 | 415 | |
| 233 | 416 | /* video hardware */ |