Previous 15994 Revisions Next

r10105 Wednesday 19th January, 2011 at 13:36:51 UTC by Robbbert
[SOL20] Cassette works now. Format is identical to the sorcerer, and tapes are interchangeable.
[src/mess/drivers]ptcsol.c

src/mess/drivers/ptcsol.c
r10104r10105
3232#include "imagedev/cassette.h"
3333#include "machine/ay31015.h"
3434
35typedef 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;
3547
3648class sol20_state : public driver_device
3749{
r10104r10105
3951   sol20_state(running_machine &machine, const driver_device_config_base &config)
4052      : driver_device(machine, config),
4153   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"),
4456   m_uart_c(*this, "uart_c"),
4557   m_uart_s(*this, "uart_s"),
4658   m_terminal(*this, TERMINAL_TAG)
4759   { }
4860
4961   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;
5264   required_device<device_t> m_uart_c;
5365   required_device<device_t> m_uart_s;
5466   required_device<device_t> m_terminal;
5567   DECLARE_READ8_MEMBER( sol20_fa_r );
68   DECLARE_READ8_MEMBER( sol20_fb_r );
5669   DECLARE_READ8_MEMBER( sol20_fc_r );
70   DECLARE_WRITE8_MEMBER( sol20_fa_w );
71   DECLARE_WRITE8_MEMBER( sol20_fb_w );
5772   DECLARE_WRITE8_MEMBER( sol20_fe_w );
5873   DECLARE_WRITE8_MEMBER( sol20_kbd_put );
5974   UINT8 m_sol20_fa;
r10104r10105
6277   const UINT8 *FNT;
6378   const UINT8 *m_videoram;
6479   UINT8 m_framecnt;
80   emu_timer *m_cassette_timer;
81   cass_data_t m_cass_data;
6582};
6683
6784
85/* timer to read cassette waveforms */
6886
87
88static 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
99static 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
69189READ8_MEMBER( sol20_state::sol20_fa_r )
70190{
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);
72202}
73203
204READ8_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
74212READ8_MEMBER( sol20_state::sol20_fc_r )
75213{
76   m_sol20_fa = 0xff;
214   m_sol20_fa |= 1;
77215   return m_sol20_fc;
78216}
79217
218WRITE8_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
241WRITE8_MEMBER( sol20_state::sol20_fb_w )
242{
243   ay31015_set_transmit_data( m_uart_c, data );
244}
245
80246WRITE8_MEMBER( sol20_state::sol20_fe_w )
81247{
82248   m_sol20_fe = data;
r10104r10105
94260static ADDRESS_MAP_START( sol20_io , ADDRESS_SPACE_IO, 8, sol20_state)
95261   ADDRESS_MAP_UNMAP_HIGH
96262   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)
98265   AM_RANGE(0xfc, 0xfc) AM_READ(sol20_fc_r)
99266   AM_RANGE(0xfe, 0xfe) AM_WRITE(sol20_fe_w)
100267/*  AM_RANGE(0xf8, 0xf8) serial status in (bit 6=data av, bit 7=tmbe)
r10104r10105
137304   memory_set_bank(machine, "boot", 0);
138305}
139306
307static 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
140313static MACHINE_RESET( sol20 )
141314{
142315   sol20_state *state = machine->driver_data<sol20_state>();
143   state->m_sol20_fa=0xff;
144316   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
145327   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);
147329}
148330
149331static DRIVER_INIT( sol20 )
r10104r10105
228410   MCFG_CPU_PROGRAM_MAP(sol20_mem)
229411   MCFG_CPU_IO_MAP(sol20_io)
230412
413   MCFG_MACHINE_START(sol20)
231414   MCFG_MACHINE_RESET(sol20)
232415
233416   /* video hardware */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team