Previous 15994 Revisions Next

r5971 Monday 5th October, 2009 at 09:55:22 UTC by Barry Rodewald
Created (very) basic uPD71071 DMA implementation, and plugged it into the FM Towns driver.
[src/mess]mess.mak
[src/mess/drivers]fmtowns.c
[src/mess/machine]upd71071.c* upd71071.h*

src/mess/machine/upd71071.c
r0r5971
1
2/*
3
4   NEC uPD71071 DMA Controller
5   Used on the Fujitsu FM-Towns
6
7   Register description:
8   
9   0x00:   Initialise (Write-only)
10         - bit 0: Reset
11         - bit 1: 16-bit data bus
12
13   0x01:   Channel Register
14         On read:
15         - bits 0-3: Selected channel
16         - bit 4: Only base registers may be read or written
17         On write:
18         - bits 0-1: Select channel for programming count, address, and mode registers
19         - bit 2: Only base registers can be read or written to
20         
21   0x02:   
22   0x03:   Count Register (16-bit)
23         DMA Transfer counter
24         
25   0x04:
26   0x05:
27   0x06:   Address Register (24-bit)
28         Self-explanatory, I hope. :)
29         
30   0x08:   
31   0x09:   Device Control register (16-bit)
32         bit 0: Enable memory-to-memory (MTM) transfers
33         bit 1: Enable fixed address for channel 0 only (MTM only)
34         bit 2: Disable DMA operation (stops HLDRQ signal to the CPU)
35         bit 3: Use compressed timing
36         bit 4: Rotational Priority
37         bit 5: Extended Writing
38         bit 6: DMARQ active level (1=active low)
39         bit 7: DMAAK active level (1=active high)
40         bit 8: Bus mode (0=bus release, 1=bus hold)
41         bit 9: Wait Enable during Verify
42         
43   0x0a:   Mode Control register
44         bit 0: Transfer size (1=16-bit, 0=8-bit,  16-bit data bus size only)
45         bit 2-3: Transfer direction (ignored for MTM transfers)
46                  00 = Verify
47                  01 = I/O to memory
48                  10 = memory to I/O
49                  11 = invalid
50         bit 4: Enable auto-initialise
51         bit 5: Address direction (0=increment, 1=decrement, affects only current Address reg)
52         bit 6-7: Transfer mode (ignored for MTM transfers)
53                  00 = Demand
54                  01 = Single
55                  10 = Block
56                  11 = Cascade
57         
58   0x0b:   Status register
59         bit 0-3: Terminal count (per channel)
60         bit 4-7: DMA request present (external hardware DMA only)
61         
62   0x0c:   
63   0x0d:   Temporary register (16-bit, read-only)
64         Stores the last data transferred in an MTM transfer
65         
66   0x0e:   Request register
67         bit 0-3: Software DMA request (1=set)
68         bit 0 only in MTM transfers
69   
70   0x0f:   Mask register
71         bit 0-3: DMARQ mask
72         bits 1 and 0 only in MTM transfers
73   
74         
75*/
76
77#include "driver.h"
78#include "machine/upd71071.h"
79
80struct upd71071_reg
81{
82   UINT8 initialise;
83   UINT8 channel;
84   UINT16 count_current[4];
85   UINT16 count_base[4];
86   UINT32 address_current[4];
87   UINT32 address_base[4];
88   UINT16 device_control;
89   UINT8 mode_control[4];
90   UINT8 status;
91   UINT8 temp_l;
92   UINT8 temp_h;
93   UINT8 request;
94   UINT8 mask;
95};
96
97typedef struct _upd71071_t upd71071_t;
98struct _upd71071_t
99{
100   struct upd71071_reg reg;
101   int selected_channel;
102   int buswidth;
103   int dmarq[4];
104   emu_timer* timer[4];
105   int in_progress[4];
106   int transfer_size[4];
107   int base[4];
108   const upd71071_intf* intf;
109};
110
111static TIMER_CALLBACK(dma_transfer_timer)
112{
113   // single byte or word transfer
114   const device_config* device = ptr;
115   upd71071_t* dmac = device->token;
116   const address_space* space = cputag_get_address_space(device->machine,dmac->intf->cputag,ADDRESS_SPACE_PROGRAM);
117   int channel = param;
118   UINT16 data = 0;  // data to transfer
119   
120   switch(dmac->reg.mode_control[channel] & 0x0c)
121   {
122      case 0x00:  // Verify
123         break;
124      case 0x04:  // I/O -> memory
125         if(dmac->intf->dma_read[channel])
126            data = dmac->intf->dma_read[channel](device->machine);
127         memory_write_byte(space,dmac->reg.address_current[channel],data & 0xff);
128         dmac->reg.count_current[channel]--;
129         if(dmac->reg.mode_control[channel] & 0x20)  // Address direction
130            dmac->reg.address_current[channel]--;
131         else
132            dmac->reg.address_current[channel]++;
133         break;
134      case 0x08:  // memory -> I/O
135         data = memory_read_byte(space,dmac->reg.address_current[channel]);
136         if(dmac->intf->dma_read[channel])
137            dmac->intf->dma_write[channel](device->machine,data);
138         dmac->reg.count_current[channel]--;
139         if(dmac->reg.mode_control[channel] & 0x20)  // Address direction
140            dmac->reg.address_current[channel]--;
141         else
142            dmac->reg.address_current[channel]++;
143         break;
144      case 0x0c:  // Invalid
145         break;
146   }
147}
148
149void upd71071_dmarq(const device_config* device, int state,int channel)
150{
151   upd71071_t* dmac = device->token;
152
153   if(state != 0)
154   {
155      // start transfer
156      if(dmac->reg.mask & (1 << channel))  // is channel masked?
157         return;
158     
159      dmac->dmarq[channel] = 1;  // DMARQ line is set
160     
161      switch(dmac->reg.mode_control[channel] & 0xc0)
162      {
163         case 0x00:  // Demand
164            // TODO
165            break;
166         case 0x40:  // Single
167            timer_adjust_oneshot(dmac->timer[channel],ATTOTIME_IN_HZ(dmac->intf->clock),channel);
168            break;
169         case 0x80:  // Block
170            // TODO
171            break;
172         case 0xc0:  // Cascade
173            // TODO
174            break;
175         
176      }
177   }
178   else
179   {
180      dmac->dmarq[channel] = 0;  // clear DMARQ line
181   }
182}
183
184static DEVICE_START(upd71071)
185{
186   upd71071_t* dmac = device->token;
187   int x;
188
189   dmac->intf = device->static_config;
190   for(x=0;x<4;x++)
191   {
192      dmac->timer[x] = timer_alloc(device->machine,dma_transfer_timer,(void*)device);
193   }
194   dmac->selected_channel = 0;
195}
196
197READ8_DEVICE_HANDLER(upd71071_read)
198{
199   upd71071_t* dmac = device->token;
200   UINT8 ret = 0;
201   
202   logerror("DMA: read from register %02x\n",offset);
203   switch(offset)
204   {
205      case 0x01:  // Channel
206         ret = (1 << dmac->selected_channel);
207         if(dmac->base[dmac->selected_channel] != 0)
208            ret |= 0x10;
209         break;
210      case 0x02:  // Count (low)
211         if(dmac->base[dmac->selected_channel] != 0)
212            ret = dmac->reg.count_base[dmac->selected_channel] & 0xff;
213         else
214            ret = dmac->reg.count_current[dmac->selected_channel] & 0xff;
215         break;
216      case 0x03:  // Count (high)
217         if(dmac->base[dmac->selected_channel] != 0)
218            ret = (dmac->reg.count_base[dmac->selected_channel] >> 8) & 0xff;
219         else
220            ret = (dmac->reg.count_current[dmac->selected_channel] >> 8) & 0xff;
221         break;
222      case 0x04:  // Address (low)
223         if(dmac->base[dmac->selected_channel] != 0)
224            ret = dmac->reg.address_base[dmac->selected_channel] & 0xff;
225         else
226            ret = dmac->reg.address_current[dmac->selected_channel] & 0xff;
227         break;
228      case 0x05:  // Address (mid)
229         if(dmac->base[dmac->selected_channel] != 0)
230            ret = (dmac->reg.address_base[dmac->selected_channel] >> 8) & 0xff;
231         else
232            ret = (dmac->reg.address_current[dmac->selected_channel] >> 8) & 0xff;
233         break;
234      case 0x06:  // Address (high)
235         if(dmac->base[dmac->selected_channel] != 0)
236            ret = (dmac->reg.address_base[dmac->selected_channel] >> 16) & 0xff;
237         else
238            ret = (dmac->reg.address_current[dmac->selected_channel] >> 16) & 0xff;
239         break;
240      case 0x08:  // Device control (low)
241         ret = dmac->reg.device_control & 0xff;
242         break;
243      case 0x09:  // Device control (high)
244         ret = (dmac->reg.device_control >> 8) & 0xff;
245         break;
246      case 0x0a:  // Mode control
247         ret = dmac->reg.mode_control[dmac->selected_channel];
248         break;
249      case 0x0b:  // Status
250         ret = dmac->reg.status;
251         break;
252      case 0x0c:  // Temporary (low)
253         ret = dmac->reg.temp_h;
254         break;
255      case 0x0d:  // Temporary (high)
256         ret = dmac->reg.temp_l;
257         break;
258      case 0x0e:  // Request
259         ret = dmac->reg.request;
260         break;
261      case 0x0f:  // Mask
262         ret = dmac->reg.mask;
263         break;
264   }
265   return ret;
266}
267
268WRITE8_DEVICE_HANDLER(upd71071_write)
269{
270   upd71071_t* dmac = device->token;
271
272   switch(offset)
273   {
274      case 0x00:  // Initialise
275         // TODO: reset (bit 0)
276         dmac->buswidth = data & 0x02;
277         logerror("DMA: Initialise [%02x]\n",data);
278         break;
279      case 0x01:  // Channel
280         dmac->selected_channel = data & 0x03;
281         dmac->base[dmac->selected_channel] = data & 0x04;
282         logerror("DMA: Channel selected [%02x]\n",data);
283         break;
284      case 0x02:  // Count (low)
285         dmac->reg.count_base[dmac->selected_channel] =
286            (dmac->reg.count_base[dmac->selected_channel] & 0xff00) | data;
287         dmac->reg.count_current[dmac->selected_channel] =
288            (dmac->reg.count_current[dmac->selected_channel] & 0xff00) | data;
289         logerror("DMA: Channel %i Counter set [%04x]\n",dmac->selected_channel,dmac->reg.count_base[dmac->selected_channel]);
290         break;
291      case 0x03:  // Count (high)
292         dmac->reg.count_base[dmac->selected_channel] =
293            (dmac->reg.count_base[dmac->selected_channel] & 0x00ff) | (data << 8);
294         dmac->reg.count_current[dmac->selected_channel] =
295            (dmac->reg.count_current[dmac->selected_channel] & 0x00ff) | (data << 8);
296         logerror("DMA: Channel %i Counter set [%04x]\n",dmac->selected_channel,dmac->reg.count_base[dmac->selected_channel]);
297         break;
298      case 0x04:  // Address (low)
299         dmac->reg.address_base[dmac->selected_channel] =
300            (dmac->reg.address_base[dmac->selected_channel] & 0x00ffff00) | data;
301         dmac->reg.address_current[dmac->selected_channel] =
302            (dmac->reg.address_current[dmac->selected_channel] & 0x00ffff00) | data;
303         logerror("DMA: Channel %i Address set [%06x]\n",dmac->selected_channel,dmac->reg.address_base[dmac->selected_channel]);
304         break;
305      case 0x05:  // Address (mid)
306         dmac->reg.address_base[dmac->selected_channel] =
307            (dmac->reg.address_base[dmac->selected_channel] & 0x00ff00ff) | (data << 8);
308         dmac->reg.address_current[dmac->selected_channel] =
309            (dmac->reg.address_current[dmac->selected_channel] & 0x00ff00ff) | (data << 8);
310         logerror("DMA: Channel %i Address set [%06x]\n",dmac->selected_channel,dmac->reg.address_base[dmac->selected_channel]);
311         break;
312      case 0x06:  // Address (high)
313         dmac->reg.address_base[dmac->selected_channel] =
314            (dmac->reg.address_base[dmac->selected_channel] & 0x0000ffff) | (data << 16);
315         dmac->reg.address_current[dmac->selected_channel] =
316            (dmac->reg.address_current[dmac->selected_channel] & 0x0000ffff) | (data << 16);
317         logerror("DMA: Channel %i Address set [%06x]\n",dmac->selected_channel,dmac->reg.address_base[dmac->selected_channel]);
318         break;
319      case 0x08:  // Device control (low)
320         dmac->reg.device_control = (dmac->reg.device_control & 0xff00) | data;
321         logerror("DMA: Device control set [%04x]\n",dmac->reg.device_control);
322         break;
323      case 0x09:  // Device control (high)
324         dmac->reg.device_control = (dmac->reg.device_control & 0x00ff) | (data << 8);
325         logerror("DMA: Device control set [%04x]\n",dmac->reg.device_control);
326         break;
327      case 0x0a:  // Mode control
328         dmac->reg.mode_control[dmac->selected_channel] = data;
329         logerror("DMA: Channel %i Mode control set [%02x]\n",dmac->selected_channel,dmac->reg.mode_control[dmac->selected_channel]);
330         break;
331      case 0x0e:  // Request
332         dmac->reg.request = data;
333         logerror("DMA: Request set [%02x]\n",data);
334         break;
335      case 0x0f:  // Mask
336         dmac->reg.mask = data;
337         logerror("DMA: Mask set [%02x]\n",data);
338         break;
339   }
340}
341
342DEVICE_GET_INFO(upd71071)
343{
344   switch (state)
345   {
346      /* --- the following bits of info are returned as 64-bit signed integers --- */
347      case DEVINFO_INT_CLASS:                     info->i = DEVICE_CLASS_OTHER;            break;
348      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(upd71071_t);            break;
349
350      /* --- the following bits of info are returned as pointers to data or functions --- */
351      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(upd71071);   break;
352      case DEVINFO_FCT_STOP:                     /* Nothing */                        break;
353      case DEVINFO_FCT_RESET:                     /* Nothing */                        break;
354
355      /* --- the following bits of info are returned as NULL-terminated strings --- */
356      case DEVINFO_STR_NAME:                     strcpy(info->s, "NEC uPD71071");         break;
357      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "DMA Controller");         break;
358      case DEVINFO_STR_VERSION:                  strcpy(info->s, "1.0");                  break;
359      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);               break;
360      case DEVINFO_STR_CREDITS:                  strcpy(info->s, "Copyright the MESS Team");   break;
361   }
362}
363
364READ8_DEVICE_HANDLER(upd71071_r) { return upd71071_read(device,offset); }
365WRITE8_DEVICE_HANDLER(upd71071_w) { upd71071_write(device,offset,data); }
366
src/mess/machine/upd71071.h
r0r5971
1#ifndef UPD71071_H_
2#define UPD71071_H_
3
4#include "driver.h"
5
6typedef struct _upd71071_interface upd71071_intf;
7struct _upd71071_interface
8{
9   const char* cputag;
10   int clock;
11   UINT16 (*dma_read[4])(running_machine* machine);
12   void (*dma_write[4])(running_machine* machine, UINT16 data);
13};
14
15void upd71071_dmarq(const device_config* device,int state,int channel);
16
17DEVICE_GET_INFO(upd71071);
18
19#define UPD71071 DEVICE_GET_INFO_NAME(upd71071)
20
21#define MDRV_UPD71071_ADD(_tag, _config) \
22   MDRV_DEVICE_ADD(_tag, UPD71071, 0) \
23   MDRV_DEVICE_CONFIG(_config)
24
25READ8_DEVICE_HANDLER(upd71071_r);
26WRITE8_DEVICE_HANDLER(upd71071_w);
27
28#endif /*UPD71071_H_*/
src/mess/mess.mak
r5970r5971
851851
852852$(MESSOBJ)/fujitsu.a:         \
853853   $(MESS_DRIVERS)/fmtowns.o   \
854   $(MESS_MACHINE)/upd71071.o   \
854855   $(MESS_DRIVERS)/fm7.o      \
855856   $(MESS_VIDEO)/fm7.o         \
856857   $(MESS_FORMATS)/fm7_cas.o   \
src/mess/drivers/fmtowns.c
r5970r5971
7878#include "sound/rf5c68.h"
7979#include "machine/pit8253.h"
8080#include "machine/pic8259.h"
81#include "formats/basicdsk.h"
8182#include "machine/wd17xx.h"
8283#include "devices/flopdrv.h"
84#include "machine/upd71071.h"
8385
8486static UINT8 ftimer;
8587static UINT8 nmi_mask;
r5970r5971
174176
175177static READ8_HANDLER(towns_dma1_r)
176178{
179   const device_config* dev = devtag_get_device(space->machine,"dma_1");
180
177181   logerror("DMA#1: read register %i\n",offset);
178   return 0x00;
182   return upd71071_r(dev,offset);
179183}
180184
181185static WRITE8_HANDLER(towns_dma1_w)
182186{
187   const device_config* dev = devtag_get_device(space->machine,"dma_1");
188
183189   logerror("DMA#1: wrote 0x%02x to register %i\n",data,offset);
190   upd71071_w(dev,offset,data);
184191}
185192
186193static READ8_HANDLER(towns_dma2_r)
187194{
195   const device_config* dev = devtag_get_device(space->machine,"dma_2");
196
188197   logerror("DMA#2: read register %i\n",offset);
189   return 0x00;
198   return upd71071_r(dev,offset);
190199}
191200
192201static WRITE8_HANDLER(towns_dma2_w)
193202{
203   const device_config* dev = devtag_get_device(space->machine,"dma_2");
204
194205   logerror("DMA#2: wrote 0x%02x to register %i\n",data,offset);
206   upd71071_w(dev,offset,data);
195207}
196208
197209/*
198210 *  Floppy Disc Controller (MB8877A)
199211 */
212 
213static WD17XX_CALLBACK(towns_fdc_irq)
214{
215   const device_config* dev = devtag_get_device(device->machine,"dma_1");
216   
217   switch(state)
218   {
219      case WD17XX_IRQ_CLR:
220         break;
221      case WD17XX_IRQ_SET:
222         break;
223      case WD17XX_DRQ_CLR:
224         upd71071_dmarq(dev,0,0);
225         break;
226      case WD17XX_DRQ_SET:
227         upd71071_dmarq(dev,1,0);
228         break;
229   }
230}
231 
200232static READ8_HANDLER(towns_floppy_r)
201233{
202234   const device_config* fdc = devtag_get_device(space->machine,"fdc");
r5970r5971
233265   switch(offset)
234266   {
235267      case 0x00:
268         // Commands 0xd0 and 0xfe (Write Track) are apparently ignored?
269         if(data == 0xd0)
270            return;
271         if(data == 0xfe)
272            return;
236273         wd17xx_command_w(fdc,offset/2,data);
237274         break;
238275      case 0x02:
r5970r5971
285322   }
286323}
287324
325UINT16 towns_fdc_dma_r(running_machine* machine)
326{
327   const device_config* fdc = devtag_get_device(machine,"fdc");
328   return wd17xx_data_r(fdc,0);
329}
330
331void towns_fdc_dma_w(running_machine* machine, UINT16 data)
332{
333   const device_config* fdc = devtag_get_device(machine,"fdc");
334   wd17xx_data_w(fdc,0,data);   
335}
336
288337static READ8_HANDLER(towns_video_440_r)
289338{
290339   logerror("VID: read port %04x\n",offset+0x440);
r5970r5971
679728   logerror("VGA: VRAM wplane select (I/O) = 0x%02x\n",towns_vram_wplane);
680729}
681730
731/*
732 *  I/O ports 0x4c0-0x4cf
733 *  CD-ROM driver (SCSI?)
734 */
735static READ8_HANDLER(towns_cdrom_r)
736{
737   switch(offset)
738   {
739      case 0x00:
740         return 0x01;
741      default:
742         logerror("CD: read port %02x\n",offset*2);
743         return 0x00;
744   }
745}
746
747static WRITE8_HANDLER(towns_cdrom_w)
748{
749   switch(offset)
750   {
751      default:
752         logerror("CD: read port %02x\n",offset*2);
753   }
754}
755
682756static ADDRESS_MAP_START(towns_mem, ADDRESS_SPACE_PROGRAM, 32)
683757  // memory map based on FM-Towns/Bochs (Bochs modified to emulate the FM-Towns)
684758  // may not be (and probably is not) correct
r5970r5971
718792  AM_RANGE(0x0040,0x0047) AM_DEVREADWRITE8("pit",pit8253_r, pit8253_w, 0x00ff00ff)
719793  AM_RANGE(0x0060,0x0063) AM_READWRITE8(towns_port60_r, towns_port60_w, 0x000000ff)
720794  AM_RANGE(0x006c,0x006f) AM_READWRITE8(towns_sys6c_r,towns_sys6c_w, 0x000000ff)
721  // DMA controllers (uPD71071?)
795  // DMA controllers (uPD71071)
722796  AM_RANGE(0x00a0,0x00af) AM_READWRITE8(towns_dma1_r, towns_dma1_w, 0xffffffff)
723797  AM_RANGE(0x00b0,0x00bf) AM_READWRITE8(towns_dma2_r, towns_dma2_w, 0xffffffff)
724798  // Floppy controller
r5970r5971
728802  AM_RANGE(0x0404,0x0407) AM_READWRITE(towns_video_404_r, towns_video_404_w)  // R/W (0x404)
729803  AM_RANGE(0x0440,0x045f) AM_READWRITE8(towns_video_440_r, towns_video_440_w, 0xffffffff)
730804  // System port
731  AM_RANGE(0x0480,0x0483) AM_READWRITE8(towns_sys480_r,towns_sys480_w,0xff000000)  // R/W (0x480)
805  AM_RANGE(0x0480,0x0483) AM_READWRITE8(towns_sys480_r,towns_sys480_w,0x000000ff)  // R/W (0x480)
732806  // CD-ROM
733  AM_RANGE(0x04c0,0x04cf) AM_NOP
807  AM_RANGE(0x04c0,0x04cf) AM_READWRITE8(towns_cdrom_r,towns_cdrom_w,0x00ff00ff)
734808  // Joystick / Mouse ports(?)
735809  AM_RANGE(0x04d0,0x04d3) AM_READ(towns_padport_r)
736810  // Sound (YM3438 [FM], RF5c68 [PCM])
r5970r5971
845919
846920static const wd17xx_interface towns_mb8877a_interface =
847921{
922   towns_fdc_irq,
848923   NULL,
849   NULL,
850924   {FLOPPY_0,FLOPPY_1,FLOPPY_2,FLOPPY_3}
851925};
852926
927FLOPPY_OPTIONS_START( towns )
928   FLOPPY_OPTION( fmt_bin, "bin", "BIN disk image", basicdsk_identify_default, basicdsk_construct_default,
929      HEADS([2])
930      TRACKS([77])
931      SECTORS([8])
932      SECTOR_LENGTH([1024])
933      FIRST_SECTOR_ID([1]))
934FLOPPY_OPTIONS_END
935
853936static const floppy_config towns_floppy_config =
854937{
855938   FLOPPY_DRIVE_DS_80,
856   FLOPPY_OPTIONS_NAME(default),
939   FLOPPY_OPTIONS_NAME(towns),
857940   DO_NOT_KEEP_GEOMETRY
858941};
859942
943static const upd71071_intf towns_dma_config =
944{
945   "maincpu",
946   1000000,
947   { towns_fdc_dma_r, 0, 0, 0 },
948   { towns_fdc_dma_w, 0, 0, 0 }
949};
950
860951// for debugging
861952static const gfx_layout x1_chars_16x16 =
862953{
r5970r5971
9131004   MDRV_MB8877_ADD("fdc",towns_mb8877a_interface)
9141005   MDRV_FLOPPY_2_DRIVES_ADD(towns_floppy_config)
9151006
1007   MDRV_UPD71071_ADD("dma_1",towns_dma_config)
1008   MDRV_UPD71071_ADD("dma_2",towns_dma_config)
1009
9161010    MDRV_VIDEO_START(towns)
9171011    MDRV_VIDEO_UPDATE(towns)
9181012MACHINE_DRIVER_END

Previous 15994 Revisions Next


© 1998-2018 The MESS Team