Previous 15994 Revisions Next

r7174 Monday 25th January, 2010 at 13:01:01 UTC by Curt Coder
[C2040] Fixed IEEE interface.
[src/mess/machine]c2040.c

src/mess/machine/c2040.c
r7173r7174
1212   TODO:
1313
1414   - find GCR rom region
15   - decode GCR
16   - write
15   - write to disk
1716
1817*/
1918
r7173r7174
5453#define TRACK_BUFFER_SIZE   8194      /* 2 bytes track length + maximum of 8192 bytes of GCR encoded data */
5554#define TRACK_DATA_START   2
5655
56#define SYNC   ((c2040->sr & SYNC_MARK) == SYNC_MARK)
57#define ERROR   (!c2040->ready & !BIT(c2040->gcr_data, 3))
58
5759/***************************************************************************
5860    TYPE DEFINITIONS
5961***************************************************************************/
r7173r7174
7577struct _c2040_t
7678{
7779   /* abstractions */
78   int address;                  /* serial bus address - 8 */
80   int address;                  /* bus address - 8 */
7981   int drive;                     /* selected drive */
8082   int side;                     /* selected side */
8183   c2040_unit_t unit[2];            /* drive unit */
8284
8385   /* track */
8486   int bit_count;                  /* current data byte bit counter */
85   UINT16 data;                  /* data shift register */
87   UINT16 sr;                     /* data shift register */
8688   int ds;                        /* density select */
8789   UINT8* gcr;                     /* GCR encoder/decoder ROM */
90   UINT8 gcr_data;                  /* GCR encoder/decoded ROM data */
8891   UINT8 pi;                     /* parallel data input */
8992
9093   /* IEEE-488 bus */
91   int nrfd_out;                  /* not ready for data */
92   int ndac_out;                  /* not data accepted */
94   int rfdo;                     /* not ready for data output */
95   int daco;                     /* not data accepted output */
9396   int atna;                     /* attention acknowledge */
9497
9598   /* signals */
r7173r7174
132135   return (c2040_config *)device->inline_config;
133136}
134137
138INLINE void update_ieee_signals(const device_config *device)
139{
140   c2040_t *c2040 = get_safe_token(device);
141
142   int atn = ieee488_atn_r(c2040->bus);
143   int atna = c2040->atna;
144   int rfdo = c2040->rfdo;
145   int daco = c2040->daco;
146
147   int nrfd = !(!(!(atn&atna)&rfdo)|!(atn|atna));
148   int ndac = !(daco|!(atn|atna));
149
150   ieee488_nrfd_w(c2040->bus, device, nrfd);
151   ieee488_ndac_w(c2040->bus, device, ndac);
152}
153
154INLINE void update_gcr_data(c2040_t *c2040)
155{
156   UINT16 gcr_addr;
157
158   if (c2040->rw)
159   {
160      /*
161
162         bit      description
163
164         I0      SR0
165         I1      SR1
166         I2      SR2
167         I3      SR3
168         I4      SR4
169         I5      SR5
170         I6      SR6
171         I7      SR7
172         I8      SR8
173         I9      SR9
174         I10      R/_W SEL
175
176      */
177
178      gcr_addr = (c2040->rw << 10) | (c2040->sr & 0x3ff);
179   }
180   else
181   {
182      /*
183
184         bit      description
185
186         I0      PI0
187         I1      PI1
188         I2      PI2
189         I3      PI3
190         I4      MODE SEL
191         I5      PI4
192         I6      PI5
193         I7      PI6
194         I8      PI7
195         I9      0
196         I10      R/_W SEL
197
198      */
199
200      gcr_addr = (c2040->rw << 10) | ((c2040->pi & 0xf0) << 1) | (c2040->mode << 4) | (c2040->pi & 0x0f);
201   }
202
203   //   c2040->gcr_data = c2040->gcr[gcr_addr];
204
205   via_cb1_w(c2040->via, ERROR);
206}
207
135208/***************************************************************************
136209    IMPLEMENTATION
137210***************************************************************************/
r7173r7174
147220   int ready = 1;
148221
149222   /* shift in data from the read head */
150   c2040->data <<= 1;
151   c2040->data |= BIT(c2040->unit[c2040->drive].track_buffer[c2040->unit[c2040->drive].buffer_pos], c2040->unit[c2040->drive].bit_pos);
223   c2040->sr <<= 1;
224   c2040->sr |= BIT(c2040->unit[c2040->drive].track_buffer[c2040->unit[c2040->drive].buffer_pos], c2040->unit[c2040->drive].bit_pos);
152225   c2040->unit[c2040->drive].bit_pos--;
153226   c2040->bit_count++;
154227
r7173r7174
164237      }
165238   }
166239
167   if ((c2040->data & SYNC_MARK) == SYNC_MARK)
240   if (SYNC)
168241   {
169242      /* SYNC detected */
170243      c2040->bit_count = 0;
r7173r7174
176249      c2040->bit_count = 0;
177250      ready = 0;
178251
179      if (!(c2040->data & 0xff))
252      if (!(c2040->sr & 0xff))
180253      {
181254         /* simulate weak bits with randomness */
182         c2040->data = (c2040->data & 0xff00) | (mame_rand(machine) & 0xff);
255         c2040->sr = (c2040->sr & 0xff00) | (mame_rand(machine) & 0xff);
183256      }
184257   }
185258
186259   if (c2040->ready != ready)
187260   {
261      /* set byte ready flag */
262      c2040->ready = ready;
188263      via_ca1_w(c2040->via, ready);
264   }
189265
190      c2040->ready = ready;
191   }
266   /* update GCR data */
267   update_gcr_data(c2040);
192268}
193269
194270/*-------------------------------------------------
r7173r7174
198274WRITE_LINE_DEVICE_HANDLER( c2040_ieee488_atn_w )
199275{
200276   c2040_t *c2040 = get_safe_token(device);
201   int nrfd = (state ^ c2040->atna) ? c2040->nrfd_out : 0;
202   int ndac = (state | c2040->atna) ? !c2040->ndac_out : 0;
203277
204   ieee488_nrfd_w(c2040->bus, device, nrfd);
205   ieee488_ndac_w(c2040->bus, device, ndac);
278   update_ieee_signals(device);
279
280   /* set RIOT PA7 */
281   riot6532_porta_in_set(c2040->riot1, !state << 7, 0x80);
206282}
207283
208284/*-------------------------------------------------
r7173r7174
223299
224300static ADDRESS_MAP_START( c2040_dos_map, ADDRESS_SPACE_PROGRAM, 8 )
225301   ADDRESS_MAP_GLOBAL_MASK(0x7fff)
226   AM_RANGE(0x0000, 0x007f) AM_MIRROR(0x0f00) AM_RAM // 6532 #1
227   AM_RANGE(0x0080, 0x00ff) AM_MIRROR(0x0f00) AM_RAM // 6532 #2
302   AM_RANGE(0x0000, 0x007f) AM_MIRROR(0x0100) AM_RAM // 6532 #1
303   AM_RANGE(0x0080, 0x00ff) AM_MIRROR(0x0100) AM_RAM // 6532 #2
228304   AM_RANGE(0x0200, 0x020f) AM_MIRROR(0x0d70) AM_DEVREADWRITE(M6532_0_TAG, riot6532_r, riot6532_w)
229305   AM_RANGE(0x0280, 0x028f) AM_MIRROR(0x0d70) AM_DEVREADWRITE(M6532_1_TAG, riot6532_r, riot6532_w)
230306   AM_RANGE(0x1000, 0x13ff) AM_MIRROR(0x0c00) AM_RAM AM_SHARE("share1")
r7173r7174
256332
257333static ADDRESS_MAP_START( c4040_dos_map, ADDRESS_SPACE_PROGRAM, 8 )
258334   ADDRESS_MAP_GLOBAL_MASK(0x7fff)
259   AM_RANGE(0x0000, 0x007f) AM_MIRROR(0x0f00) AM_RAM // 6532 #1
260   AM_RANGE(0x0080, 0x00ff) AM_MIRROR(0x0f00) AM_RAM // 6532 #2
261   AM_RANGE(0x0200, 0x020f) AM_MIRROR(0x0d70) AM_DEVREADWRITE(M6532_0_TAG, riot6532_r, riot6532_w)
262   AM_RANGE(0x0280, 0x028f) AM_MIRROR(0x0d70) AM_DEVREADWRITE(M6532_1_TAG, riot6532_r, riot6532_w)
263   AM_RANGE(0x1000, 0x13ff) AM_MIRROR(0x0c00) AM_RAM AM_SHARE("share1")
264   AM_RANGE(0x2000, 0x23ff) AM_MIRROR(0x0c00) AM_RAM AM_SHARE("share2")
265   AM_RANGE(0x3000, 0x33ff) AM_MIRROR(0x0c00) AM_RAM AM_SHARE("share3")
266   AM_RANGE(0x4000, 0x43ff) AM_MIRROR(0x0c00) AM_RAM AM_SHARE("share4")
335   AM_RANGE(0x0000, 0x007f) AM_MIRROR(0x0100) AM_RAM // 6532 #1
336   AM_RANGE(0x0080, 0x00ff) AM_MIRROR(0x0100) AM_RAM // 6532 #2
337   AM_RANGE(0x0200, 0x020f) /*AM_MIRROR(0x0d70)*/ AM_DEVREADWRITE(M6532_0_TAG, riot6532_r, riot6532_w)
338   AM_RANGE(0x0280, 0x028f) /*AM_MIRROR(0x0d70)*/ AM_DEVREADWRITE(M6532_1_TAG, riot6532_r, riot6532_w)
339   AM_RANGE(0x1000, 0x13ff) /*AM_MIRROR(0x0c00)*/ AM_RAM AM_SHARE("share1")
340   AM_RANGE(0x2000, 0x23ff) /*AM_MIRROR(0x0c00)*/ AM_RAM AM_SHARE("share2")
341   AM_RANGE(0x3000, 0x33ff) /*AM_MIRROR(0x0c00)*/ AM_RAM AM_SHARE("share3")
342   AM_RANGE(0x4000, 0x43ff) /*AM_MIRROR(0x0c00)*/ AM_RAM AM_SHARE("share4")
267343   AM_RANGE(0x5000, 0x7fff) AM_ROM AM_REGION("c4040", 0x0000)
268344ADDRESS_MAP_END
269345
r7173r7174
273349
274350static ADDRESS_MAP_START( c4040_fdc_map, ADDRESS_SPACE_PROGRAM, 8 )
275351   ADDRESS_MAP_GLOBAL_MASK(0x1fff)
276   AM_RANGE(0x0000, 0x003f) AM_MIRROR(0x0300) AM_RAM // 6530
277   AM_RANGE(0x0040, 0x004f) AM_MIRROR(0x0330) AM_DEVREADWRITE(M6522_TAG, via_r, via_w)
278   AM_RANGE(0x0080, 0x008f) AM_MIRROR(0x0330) AM_DEVREADWRITE(M6530_TAG, riot6532_r, riot6532_w)
352   AM_RANGE(0x0000, 0x003f) AM_MIRROR(0x0100) AM_RAM // 6530
353   AM_RANGE(0x0040, 0x004f) /*AM_MIRROR(0x0330)*/ AM_DEVREADWRITE(M6522_TAG, via_r, via_w)
354   AM_RANGE(0x0080, 0x008f) /*AM_MIRROR(0x0330)*/ AM_DEVREADWRITE(M6530_TAG, riot6532_r, riot6532_w)
279355   AM_RANGE(0x0400, 0x07ff) AM_RAM AM_SHARE("share1")
280356   AM_RANGE(0x0800, 0x0bff) AM_RAM AM_SHARE("share2")
281357   AM_RANGE(0x0c00, 0x0fff) AM_RAM AM_SHARE("share3")
r7173r7174
460536
461537   c2040_t *c2040 = get_safe_token(device->owner);
462538
463   int atn = ieee488_atn_r(c2040->bus);
464   int atna = BIT(data, 0);
465   int ndac = BIT(data, 1);
466   int nrfd = BIT(data, 2);
539   /* attention acknowledge */
540   c2040->atna = BIT(data, 0);
467541
542   /* data accepted output */
543   c2040->daco = BIT(data, 1);
544
545   /* not ready for data output */
546   c2040->rfdo = BIT(data, 2);
547
468548   /* end or identify */
469549   ieee488_eoi_w(c2040->bus, device->owner, BIT(data, 3));
470550
471551   /* data valid */
472552   ieee488_dav_w(c2040->bus, device->owner, BIT(data, 4));
473553
474   /* TODO attention acknowledge */
475   c2040->atna = atna;
476   c2040->nrfd_out = nrfd;
477   c2040->ndac_out = ndac;
478
479   nrfd = (atn ^ atna) ? nrfd : 0;
480   ndac = (atn | atna) ? !ndac : 0;
481
482   ieee488_nrfd_w(c2040->bus, device->owner, nrfd);
483   ieee488_ndac_w(c2040->bus, device->owner, ndac);
554   update_ieee_signals(device->owner);
484555}
485556
486557static READ8_DEVICE_HANDLER( c2040_riot1_pb_r )
r7173r7174
579650
580651   c2040_t *c2040 = get_safe_token(device->owner);
581652
582//   UINT16 gcr_addr = (c2040->rw << 10) | (c2040->data & 0x3ff);
583   UINT8 e = 0;//memory_region(device->machine, "c4040:c4040")[0x3400 + gcr_addr];
584   UINT16 i = c2040->data;
653   UINT16 i = c2040->sr;
654   UINT8 e = c2040->gcr_data;
585655
586656   return (BIT(e, 6) << 7) | (BIT(i, 7) << 6) | (e & 0x30) | (BIT(e, 2) << 3) | (i & 0x04) | (e & 0x03);
587657}
r7173r7174
661731   /* stepper motor 1 */
662732   int s1 = data & 0x03;
663733   step_motor(c2040, 1, s1);
734   logerror("S1 %u\n", s1);
664735
665736   /* stepper motor 0 */
666737   int s0 = (data >> 2) & 0x03;
667738   step_motor(c2040, 0, s0);
739   logerror("S0 %u\n", s1);
668740
669741   /* spindle motor 1 */
670742   int mtr1 = BIT(data, 4);
671743   floppy_mon_w(c2040->unit[1].image, !mtr1);
744   logerror("MTR1 %u\n", mtr1);
672745
673746   /* spindle motor 0 */
674747   int mtr0 = BIT(data, 5);
675748   floppy_mon_w(c2040->unit[0].image, !mtr0);
749   logerror("MTR0 %u\n", mtr0);
676750
677751   timer_enable(c2040->bit_timer, mtr1 | mtr0);
678752}
r7173r7174
699773   UINT8 data = 0;
700774
701775   /* SYNC detected */
702   data |= !((c2040->data & SYNC_MARK) == SYNC_MARK) << 7;
776   data |= !SYNC << 7;
703777
704778   return data;
705779}
r7173r7174
735809{
736810   c2040_t *c2040 = get_safe_token(device->owner);
737811
738   //UINT16 gcr_addr = (c2040->rw << 10) | (c2040->data & 0x3ff);
739   UINT8 e = 0;//memory_region(device->machine, "c4040:c4040")[0x3400 + gcr_addr];
740
741   return (!c2040->ready & !BIT(e, 3));
812   return ERROR;
742813}
743814
744815static WRITE_LINE_DEVICE_HANDLER( mode_sel_w )
r7173r7174
747818
748819   /* mode select */
749820   c2040->mode = state;
821
822   update_gcr_data(c2040);
750823}
751824
752825static WRITE_LINE_DEVICE_HANDLER( rw_sel_w )
r7173r7174
755828
756829   /* read/write select */
757830   c2040->rw = state;
831
832   update_gcr_data(c2040);
758833}
759834
760835static const via6522_interface c2040_via_intf =
r7173r7174
868943   data |= floppy_wpt_r(c2040->unit[c2040->drive].image) << 3;
869944
870945   /* SYNC detected */
871   data |= !((c2040->data & SYNC_MARK) == SYNC_MARK) << 6;
946   data |= !SYNC << 6;
872947
873948   return data;
874949}
r7173r7174
10911166   /* DOS */
10921167   MDRV_CPU_ADD(M6502_DOS_TAG, M6502, XTAL_16MHz/16)
10931168   MDRV_CPU_PROGRAM_MAP(c2040_dos_map)
1169   
10941170   MDRV_RIOT6532_ADD(M6532_0_TAG, XTAL_16MHz/16, c2040_riot0_intf)
10951171   MDRV_RIOT6532_ADD(M6532_1_TAG, XTAL_16MHz/16, c2040_riot1_intf)
10961172
10971173   /* controller */
10981174   MDRV_CPU_ADD(M6502_FDC_TAG, M6502, XTAL_16MHz/16)
10991175   MDRV_CPU_PROGRAM_MAP(c2040_fdc_map)
1176   
11001177   MDRV_VIA6522_ADD(M6522_TAG, XTAL_16MHz/16, c2040_via_intf)
11011178   MDRV_RIOT6532_ADD(M6530_TAG, XTAL_16MHz/16, c2040_riot2_intf)
11021179
r7173r7174
11111188   /* DOS */
11121189   MDRV_CPU_ADD(M6502_DOS_TAG, M6502, XTAL_16MHz/16)
11131190   MDRV_CPU_PROGRAM_MAP(c4040_dos_map)
1191
11141192   MDRV_RIOT6532_ADD(M6532_0_TAG, XTAL_16MHz/16, c2040_riot0_intf)
11151193   MDRV_RIOT6532_ADD(M6532_1_TAG, XTAL_16MHz/16, c2040_riot1_intf)
11161194
11171195   /* controller */
11181196   MDRV_CPU_ADD(M6502_FDC_TAG, M6502, XTAL_16MHz/16)
11191197   MDRV_CPU_PROGRAM_MAP(c4040_fdc_map)
1198
11201199   MDRV_VIA6522_ADD(M6522_TAG, XTAL_16MHz/16, c2040_via_intf)
11211200   MDRV_RIOT6532_ADD(M6530_TAG, XTAL_16MHz/16, c2040_riot2_intf)
11221201
r7173r7174
11311210   /* DOS */
11321211   MDRV_CPU_ADD(M6502_DOS_TAG, M6502, XTAL_12MHz/3)
11331212   MDRV_CPU_PROGRAM_MAP(c8050_dos_map)
1213   
11341214   MDRV_RIOT6532_ADD(M6532_0_TAG, XTAL_12MHz/3, c2040_riot0_intf)
11351215   MDRV_RIOT6532_ADD(M6532_1_TAG, XTAL_12MHz/3, c2040_riot1_intf)
11361216
11371217   /* controller */
11381218   MDRV_CPU_ADD(M6502_FDC_TAG, M6502, XTAL_12MHz/3)
11391219   MDRV_CPU_PROGRAM_MAP(c8050_fdc_map)
1220   
11401221   MDRV_VIA6522_ADD(M6522_TAG, XTAL_12MHz/3, c8050_via_intf)
11411222   MDRV_RIOT6532_ADD(M6530_TAG, XTAL_12MHz/3, c8050_riot2_intf)
11421223
r7173r7174
11511232   /* DOS */
11521233   MDRV_CPU_ADD(M6502_DOS_TAG, M6502, XTAL_12MHz/3)
11531234   MDRV_CPU_PROGRAM_MAP(c8050_dos_map)
1235   
11541236   MDRV_RIOT6532_ADD(M6532_0_TAG, XTAL_12MHz/3, c2040_riot0_intf)
11551237   MDRV_RIOT6532_ADD(M6532_1_TAG, XTAL_12MHz/3, c2040_riot1_intf)
11561238
11571239   /* controller */
11581240   MDRV_CPU_ADD(M6502_FDC_TAG, M6502, XTAL_12MHz/3)
11591241   MDRV_CPU_PROGRAM_MAP(c8050_fdc_map)
1242   
11601243   MDRV_VIA6522_ADD(M6522_TAG, XTAL_12MHz/3, c8050_via_intf)
11611244   MDRV_RIOT6532_ADD(M6530_TAG, XTAL_12MHz/3, c8050_riot2_intf)
11621245
r7173r7174
11711254   /* DOS */
11721255   MDRV_CPU_ADD(M6502_DOS_TAG, M6502, XTAL_12MHz/3)
11731256   MDRV_CPU_PROGRAM_MAP(sfd1001_dos_map)
1257   
11741258   MDRV_RIOT6532_ADD(M6532_0_TAG, XTAL_12MHz/3, c2040_riot0_intf)
11751259   MDRV_RIOT6532_ADD(M6532_1_TAG, XTAL_12MHz/3, c2040_riot1_intf)
11761260
11771261   /* controller */
11781262   MDRV_CPU_ADD(M6502_FDC_TAG, M6502, XTAL_12MHz/3)
11791263   MDRV_CPU_PROGRAM_MAP(sfd1001_fdc_map)
1264   
11801265   MDRV_VIA6522_ADD(M6522_TAG, XTAL_12MHz/3, c8050_via_intf)
11811266   MDRV_RIOT6532_ADD(M6530_TAG, XTAL_12MHz/3, c8050_riot2_intf)
11821267

Previous 15994 Revisions Next


© 1998-2018 The MESS Team