Previous 15994 Revisions Next

r6642 Tuesday 15th December, 2009 at 12:35:07 UTC by Curt Coder
[C1581] Added serial interface.
[src/emu/machine]6526cia.c 6526cia.h
[src/mess/machine]c1541.c c1551.c c1581.c

src/emu/machine/6526cia.c
r6641r6642
8383   UINT8         icr;
8484   UINT8         ics;
8585   UINT8         irq;
86   int            flag;
8687
8788   /* Serial */
8889   UINT8         loaded;
r6641r6642
192193   state_save_register_device_item(device, 0, cia->icr);
193194   state_save_register_device_item(device, 0, cia->ics);
194195   state_save_register_device_item(device, 0, cia->irq);
196   state_save_register_device_item(device, 0, cia->flag);
195197   state_save_register_device_item(device, 0, cia->loaded);
196198   state_save_register_device_item(device, 0, cia->sdr);
197199   state_save_register_device_item(device, 0, cia->sp);
r6641r6642
640642   cia->cnt = data ? 1 : 0;
641643}
642644
645WRITE_LINE_DEVICE_HANDLER( mos6526_tod_w )
646{
647   if (state) cia_clock_tod(device);
648}
643649
650WRITE_LINE_DEVICE_HANDLER( mos6526_cnt_w )
651{
652   cia_set_input_cnt(device, state);
653}
654
655WRITE_LINE_DEVICE_HANDLER( mos6526_sp_w )
656{
657   cia_set_input_sp(device, state);
658}
659
660WRITE_LINE_DEVICE_HANDLER( mos6526_flag_w )
661{
662   cia_state *cia = get_token(device);
663
664   if (cia->flag && !state)
665   {
666      cia->flag = state;
667      cia_issue_index(device);
668   }
669}
670
644671/*-------------------------------------------------
645672    cia_r
646673-------------------------------------------------*/
src/emu/machine/6526cia.h
r6641r6642
7070void cia_set_input_cnt(const device_config *device, int data);
7171void cia_set_input_sp(const device_config *device, int data);
7272
73WRITE_LINE_DEVICE_HANDLER( mos6526_tod_w );
74WRITE_LINE_DEVICE_HANDLER( mos6526_cnt_w );
75WRITE_LINE_DEVICE_HANDLER( mos6526_sp_w );
76WRITE_LINE_DEVICE_HANDLER( mos6526_flag_w );
77
7378/* accessors */
7479UINT8 cia_get_output_a(const device_config *device);
7580UINT8 cia_get_output_b(const device_config *device);
src/mess/machine/c1581.c
r6641r6642
77
88**********************************************************************/
99
10/*
11
12   TODO:
13   
14   - floppy access
15   - WD1770 DDEN = 0
16   - fast serial
17   - power LED
18   - activity LED
19
20*/
21
1022#include "driver.h"
1123#include "c1581.h"
1224#include "cpu/m6502/m6502.h"
1325#include "devices/flopdrv.h"
14#include "formats/g64_dsk.h"
26#include "formats/basicdsk.h"
1527#include "machine/6526cia.h"
1628#include "machine/cbmserial.h"
1729#include "machine/wd17xx.h"
r6641r6642
3345typedef struct _c1581_t c1581_t;
3446struct _c1581_t
3547{
48   int address;
49
50   int data_out;
51   int atn_ack;
52
3653   /* devices */
3754   const device_config *cpu;
3855   const device_config *cia;
r6641r6642
6582***************************************************************************/
6683
6784/*-------------------------------------------------
85    c1581_atn_w - serial bus attention
86-------------------------------------------------*/
87
88static CBMSERIAL_ATN( c1581 )
89{
90   c1581_t *c1581 = get_safe_token(device);
91   int data_out = !c1581->data_out && !(c1581->atn_ack && !state);
92
93   mos6526_flag_w(c1581->cia, state);
94
95   cbmserial_data_w(c1581->serial_bus, device, data_out);
96}
97
98/*-------------------------------------------------
99    c1581_reset_w - serial bus reset
100-------------------------------------------------*/
101
102static CBMSERIAL_RESET( c1581 )
103{
104   if (!state)
105   {
106      device_reset(device);
107   }
108}
109
110/*-------------------------------------------------
68111    ADDRESS_MAP( c1581_map )
69112-------------------------------------------------*/
70113
r6641r6642
79122    cia6526_interface c1581_cia_intf
80123-------------------------------------------------*/
81124
125static READ8_DEVICE_HANDLER( c1581_cia_pa_r )
126{
127   /*
128
129      bit      description
130
131      PA0      SIDE0
132      PA1      /RDY
133      PA2      /MOTOR
134      PA3      SW1
135      PA4      SW1
136      PA5      POWER LED
137      PA6      ACT LED
138      PA7      /DISK CHANGE
139
140   */
141
142   c1581_t *c1581 = get_safe_token(device);
143   UINT8 data = 0;
144
145   /* ready */
146   data |= !(floppy_drive_get_flag_state(c1581->image, FLOPPY_DRIVE_READY) == FLOPPY_DRIVE_READY) << 1;
147
148   /* serial address */
149   data |= c1581->address << 3;
150
151   return data;
152}
153
154static WRITE8_DEVICE_HANDLER( c1581_cia_pa_w )
155{
156   /*
157
158      bit      description
159
160      PA0      SIDE0
161      PA1      /RDY
162      PA2      /MOTOR
163      PA3      SW1
164      PA4      SW1
165      PA5      POWER LED
166      PA6      ACT LED
167      PA7      /DISK CHANGE
168
169   */
170
171   c1581_t *c1581 = get_safe_token(device);
172   int motor = BIT(data, 2);
173
174   /* side 0 */
175   wd17xx_set_side(c1581->wd1770, !BIT(data, 0));
176
177   /* motor */
178   floppy_drive_set_motor_state(c1581->image, motor ? 0 : FLOPPY_DRIVE_MOTOR_ON);
179   floppy_drive_set_ready_state(c1581->image, motor, 1);
180
181   /* power led */
182
183   /* active led */
184}
185
186static READ8_DEVICE_HANDLER( c1581_cia_pb_r )
187{
188   /*
189
190      bit      description
191
192      PB0      DATA IN
193      PB1      DATA OUT
194      PB2      CLK IN
195      PB3      CLK OUT
196      PB4      ATN ACK
197      PB5      FAST SER DIR
198      PB6      /WPRT
199      PB7      ATN IN
200
201   */
202
203   c1581_t *c1581 = get_safe_token(device);
204   UINT8 data = 0;
205
206   /* data in */
207   data = !cbmserial_data_r(c1581->serial_bus);
208
209   /* clock in */
210   data |= !cbmserial_clk_r(c1581->serial_bus) << 2;
211
212   /* write protect */
213   data |= !floppy_wpt_r(c1581->image) << 6;
214
215   /* attention in */
216   data |= !cbmserial_atn_r(c1581->serial_bus) << 7;
217
218   return data;
219}
220
221static WRITE8_DEVICE_HANDLER( c1581_cia_pb_w )
222{
223   /*
224
225      bit      description
226
227      PB0      DATA IN
228      PB1      DATA OUT
229      PB2      CLK IN
230      PB3      CLK OUT
231      PB4      ATN ACK
232      PB5      FAST SER DIR
233      PB6      /WPRT
234      PB7      ATN IN
235
236   */
237
238   c1581_t *c1581 = get_safe_token(device);
239
240   int data_out = BIT(data, 1);
241   int clk_out = BIT(data, 3);
242   int atn_ack = BIT(data, 4);
243
244   /* data out */
245   int serial_data = !data_out && !(atn_ack && !cbmserial_atn_r(c1581->serial_bus));
246   cbmserial_data_w(c1581->serial_bus, device->owner, serial_data);
247   c1581->data_out = data_out;
248
249   /* clock out */
250   cbmserial_clk_w(c1581->serial_bus, device->owner, !clk_out);
251
252   /* attention acknowledge */
253   c1581->atn_ack = BIT(data, 4);
254}
255
82256static const cia6526_interface c1581_cia_intf =
83257{
258   DEVCB_CPU_INPUT_LINE(M6502_TAG, INPUT_LINE_IRQ0),
84259   DEVCB_NULL,
85   DEVCB_NULL,
86260   10, /* 1/10 second */
87261   {
88      { DEVCB_NULL, DEVCB_NULL },
89      { DEVCB_NULL, DEVCB_NULL }
262      { DEVCB_HANDLER(c1581_cia_pa_r), DEVCB_HANDLER(c1581_cia_pa_w) },
263      { DEVCB_HANDLER(c1581_cia_pb_r), DEVCB_HANDLER(c1581_cia_pb_w) }
90264   }
91265};
92266
r6641r6642
106280-------------------------------------------------*/
107281
108282static FLOPPY_OPTIONS_START( c1581 )
109//   FLOPPY_OPTION( c1581, "d81", "Commodore 1581 Disk Image", d64_dsk_identify, d64_dsk_construct, NULL )
283   FLOPPY_OPTION( c1581, "d81", "Commodore 1581 Disk Image", basicdsk_identify_default, basicdsk_construct_default,
284      HEADS([2])
285      TRACKS([80])
286      SECTORS([20])
287      SECTOR_LENGTH([256])
288      FIRST_SECTOR_ID([0]))
110289FLOPPY_OPTIONS_END
111290
112291/*-------------------------------------------------
r6641r6642
130309-------------------------------------------------*/
131310
132311static MACHINE_DRIVER_START( c1581 )
133   MDRV_CPU_ADD(M6502_TAG, M6502, XTAL_16MHz/16)
312   MDRV_CPU_ADD(M6502_TAG, M6502, XTAL_16MHz/8)
134313   MDRV_CPU_PROGRAM_MAP(c1581_map)
135314
136   MDRV_CIA8520_ADD(M8520_TAG, XTAL_16MHz/16, c1581_cia_intf)
137   MDRV_WD1770_ADD(WD1770_TAG, c1581_wd1770_intf)
315   MDRV_CIA8520_ADD(M8520_TAG, XTAL_16MHz/8, c1581_cia_intf)
316   MDRV_WD1770_ADD(WD1770_TAG, /*XTAL_16MHz/2,*/ c1581_wd1770_intf)
138317
139318   MDRV_FLOPPY_DRIVE_ADD(FLOPPY_0, c1581_floppy_config)
140319MACHINE_DRIVER_END
r6641r6642
165344
166345static DEVICE_START( c1581 )
167346{
347   c1581_t *c1581 = get_safe_token(device);
348   const c1581_config *config = get_safe_config(device);
349
350   /* set serial address */
351   assert((config->address > 7) && (config->address < 12));
352   c1581->address = config->address - 8;
353
354   /* find our CPU */
355   c1581->cpu = device_find_child_by_tag(device, M6502_TAG);
356
357   /* find devices */
358   c1581->cia = device_find_child_by_tag(device, M8520_TAG);
359   c1581->wd1770 = device_find_child_by_tag(device, WD1770_TAG);
360   c1581->serial_bus = devtag_get_device(device->machine, config->serial_bus_tag);
361   c1581->image = device_find_child_by_tag(device, FLOPPY_0);
362
363   /* register for state saving */
168364}
169365
170366/*-------------------------------------------------
r6641r6642
173369
174370static DEVICE_RESET( c1581 )
175371{
372   c1581_t *c1581 = get_safe_token(device);
373
374   device_reset(c1581->cpu);
375   device_reset(c1581->cia);
376   device_reset(c1581->wd1770);
176377}
177378
178379/*-------------------------------------------------
r6641r6642
196397      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(c1581);                  break;
197398      case DEVINFO_FCT_STOP:                     /* Nothing */                                    break;
198399      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(c1581);                  break;
400      case DEVINFO_FCT_CBM_SERIAL_ATN:            info->f = (genf *)CBMSERIAL_ATN_NAME(c1581);            break;
401      case DEVINFO_FCT_CBM_SERIAL_RESET:            info->f = (genf *)CBMSERIAL_RESET_NAME(c1581);            break;
199402
200403      /* --- the following bits of info are returned as NULL-terminated strings --- */
201404      case DEVINFO_STR_NAME:                     strcpy(info->s, "Commodore 1581");                     break;
src/mess/machine/c1541.c
r6641r6642
296296static CBMSERIAL_ATN( c1541 )
297297{
298298   c1541_t *c1541 = get_safe_token(device);
299   int serial_data = !c1541->data_out && !(c1541->atna ^ !state);
299   int data_out = !c1541->data_out && !(c1541->atna ^ !state);
300300
301301   via_ca1_w(c1541->via0, 0, !state);
302302
303   cbmserial_data_w(c1541->serial_bus, device, serial_data);
303   cbmserial_data_w(c1541->serial_bus, device, data_out);
304304}
305305
306306/*-------------------------------------------------
r6641r6642
501501
502502   c1541_t *c1541 = get_safe_token(device->owner);
503503
504   return !(floppy_drive_get_flag_state(c1541->image, FLOPPY_DRIVE_HEAD_AT_TRACK_0) == FLOPPY_DRIVE_HEAD_AT_TRACK_0);
504   return (floppy_drive_get_flag_state(c1541->image, FLOPPY_DRIVE_HEAD_AT_TRACK_0) == FLOPPY_DRIVE_HEAD_AT_TRACK_0);
505505}
506506
507507static const via6522_interface c1541c_via0_intf =
src/mess/machine/c1551.c
r6641r6642
2323
2424#define M6510T_TAG      "u2"
2525#define M6525_TAG      "u3"
26#define M6523_TAG      "ci_u2"
2627
2728#define FLOPPY_TAG      "c1551_floppy"
2829
r6641r6642
5556    IMPLEMENTATION
5657***************************************************************************/
5758
59static READ8_HANDLER( c1551_port_r )
60{
61   /*
62
63      bit      description
64
65      P0      STEP0
66      P1      STEP1
67      P2      MOTOR ON
68      P3      ACT
69      P4      WPRT
70      P5      DS0
71      P6      DS1
72      P7      ATN
73
74   */
75
76   return 0;
77}
78
79static WRITE8_HANDLER( c1551_port_w )
80{
81   /*
82
83      bit      description
84
85      P0      STEP0
86      P1      STEP1
87      P2      MOTOR ON
88      P3      ACT
89      P4      WPRT
90      P5      DS0
91      P6      DS1
92      P7      ATN
93
94   */
95}
96
97
5898/*-------------------------------------------------
5999    ADDRESS_MAP( c1551_map )
60100-------------------------------------------------*/
61101
62102static ADDRESS_MAP_START( c1551_map, ADDRESS_SPACE_PROGRAM, 8 )
63//   AM_RANGE(0x0000, 0x0001) AM_READWRITE(c1551_port_r, c1551_port_w)
103   AM_RANGE(0x0000, 0x0001) AM_READWRITE(c1551_port_r, c1551_port_w)
64104   AM_RANGE(0x0002, 0x07ff) AM_RAM
65105   AM_RANGE(0x4000, 0x4007) AM_DEVREADWRITE(M6525_TAG, tpi6525_r, tpi6525_w)
66106   AM_RANGE(0xc000, 0xffff) AM_ROM AM_REGION("c1551", 0)
r6641r6642
70110    tpi6525_interface c1551_tpi_intf
71111-------------------------------------------------*/
72112
113static READ8_DEVICE_HANDLER( c1551_tpi_pa_r )
114{
115   /*
116
117      bit      description
118
119      PA0      6523 P0
120      PA1      6523 P1
121      PA2      6523 P2
122      PA3      6523 P3
123      PA4      6523 P4
124      PA5      6523 P5
125      PA6      6523 P6
126      PA7      6523 P7
127
128   */
129
130   return 0;
131}
132
133static WRITE8_DEVICE_HANDLER( c1551_tpi_pa_w )
134{
135   /*
136
137      bit      description
138
139      PA0      6523 P0
140      PA1      6523 P1
141      PA2      6523 P2
142      PA3      6523 P3
143      PA4      6523 P4
144      PA5      6523 P5
145      PA6      6523 P6
146      PA7      6523 P7
147
148   */
149}
150
151static READ8_DEVICE_HANDLER( c1551_tpi_pb_r )
152{
153   /*
154
155      bit      description
156
157      PB0      YB0
158      PB1      YB1
159      PB2      YB2
160      PB3      YB3
161      PB4      YB4
162      PB5      YB5
163      PB6      YB6
164      PB7      YB7
165
166   */
167
168   return 0;
169}
170
171static WRITE8_DEVICE_HANDLER( c1551_tpi_pb_w )
172{
173   /*
174
175      bit      description
176
177      PB0      YB0
178      PB1      YB1
179      PB2      YB2
180      PB3      YB3
181      PB4      YB4
182      PB5      YB5
183      PB6      YB6
184      PB7      YB7
185
186   */
187}
188
189static READ8_DEVICE_HANDLER( c1551_tpi_pc_r )
190{
191   /*
192
193      bit      description
194
195      PC0      6523 _IRQ
196      PC1      6523 _RES
197      PC2      interface J1
198      PC3      6523 pin 20
199      PC4      SOE
200      PC5      JP1
201      PC6      _SYNC
202      PC7      6523 phi2
203
204   */
205
206   return 0;
207}
208
209static WRITE8_DEVICE_HANDLER( c1551_tpi_pc_w )
210{
211   /*
212
213      bit      description
214
215      PC0      6523 _IRQ
216      PC1      6523 _RES
217      PC2      interface J1
218      PC3      6523 pin 20
219      PC4      SOE
220      PC5      JP1
221      PC6      _SYNC
222      PC7      6523 phi2
223
224   */
225}
226
73227static const tpi6525_interface c1551_tpi_intf =
74228{
229   c1551_tpi_pa_r,
230   c1551_tpi_pb_r,
231   c1551_tpi_pc_r,
232   c1551_tpi_pa_w,
233   c1551_tpi_pb_w,
234   c1551_tpi_pc_w,
75235   NULL,
76236   NULL,
77   NULL,
78   NULL,
79   NULL,
80   NULL,
81   NULL,
82   NULL,
83237   NULL
84238};
85239
r6641r6642
89243
90244static FLOPPY_OPTIONS_START( c1551 )
91245//   FLOPPY_OPTION( c1551, "d64", "Commodore 1541 Disk Image", d64_dsk_identify, d64_dsk_construct, NULL )
92   FLOPPY_OPTION( c1551, "g64", "Commodore 1551 GCR Disk Image", g64_dsk_identify, g64_dsk_construct, NULL )
246   FLOPPY_OPTION( c1551, "g64", "Commodore 1541 GCR Disk Image", g64_dsk_identify, g64_dsk_construct, NULL )
93247FLOPPY_OPTIONS_END
94248
95249/*-------------------------------------------------
r6641r6642
117271   MDRV_CPU_PROGRAM_MAP(c1551_map)
118272
119273   MDRV_TPI6525_ADD(M6525_TAG, c1551_tpi_intf)
274//   MDRV_MOS6523_ADD(M6523_TAG, 2000000, c1551_mos6523_intf)
120275
121276   MDRV_FLOPPY_DRIVE_ADD(FLOPPY_TAG, c1551_floppy_config)
122277MACHINE_DRIVER_END

Previous 15994 Revisions Next


© 1998-2018 The MESS Team