Previous 15994 Revisions Next

r2506 Wednesday 30th April, 2008 at 02:51:11 UTC by Barry Rodewald
[HD63450] Converted to new device system.
[docs]messnew.txt
[src/mess/drivers]x68k.c
[src/mess/machine]hd63450.c hd63450.h

src/mess/machine/hd63450.c
r2505r2506
77#include "machine/hd63450.h"
88
99
10static struct hd63450 dmac;
11
1210static TIMER_CALLBACK(dma_transfer_timer);
13static void dma_transfer_abort(int channel);
14static void dma_transfer_halt(int channel);
15static void dma_transfer_continue(int channel);
11static void dma_transfer_abort(const device_config* device, int channel);
12static void dma_transfer_halt(const device_config* device, int channel);
13static void dma_transfer_continue(const device_config* device, int channel);
1614
17void hd63450_init(const struct hd63450_interface* intf)
15DEVICE_START(hd63450)
1816{
17   hd63450_t* dmac = device->token;
1918   int x;
2019
21   memset(&dmac,0,sizeof(struct hd63450));
22   dmac.intf = intf;
20   assert(device->machine != NULL);
21   dmac->intf = device->static_config;
22
23   // Initialise timers and registers
2324   for(x=0;x<4;x++)
2425   {
25      dmac.timer[x] = timer_alloc(dma_transfer_timer, NULL);
26      dmac.reg[x].niv = 0x0f;  // defaults?
27      dmac.reg[x].eiv = 0x0f;
26      dmac->timer[x] = timer_alloc(dma_transfer_timer, (void*)device);
27      dmac->reg[x].niv = 0x0f;  // defaults?
28      dmac->reg[x].eiv = 0x0f;
2829   }
2930}
3031
31int hd63450_read(running_machine *machine, int offset, UINT16 mem_mask)
32int hd63450_read(const device_config* device, int offset, UINT16 mem_mask)
3233{
3334   int channel,reg;
35   hd63450_t* dmac = device->token;
3436
3537   channel = (offset & 0x60) >> 5;
3638   reg = offset & 0x1f;
r2505r2506
3840   switch(reg)
3941   {
4042   case 0x00:  // CSR / CER
41      return (dmac.reg[channel].csr << 8) | dmac.reg[channel].cer;
43      return (dmac->reg[channel].csr << 8) | dmac->reg[channel].cer;
4244   case 0x02:  // DCR / OCR
43      return (dmac.reg[channel].dcr << 8) | dmac.reg[channel].ocr;
45      return (dmac->reg[channel].dcr << 8) | dmac->reg[channel].ocr;
4446   case 0x03:  // SCR / CCR
45      return (dmac.reg[channel].scr << 8) | dmac.reg[channel].ccr;
47      return (dmac->reg[channel].scr << 8) | dmac->reg[channel].ccr;
4648   case 0x05:  // MTC
47      return dmac.reg[channel].mtc;
49      return dmac->reg[channel].mtc;
4850   case 0x06:  // MAR (high)
49      return (dmac.reg[channel].mar & 0xffff0000) >> 16;
51      return (dmac->reg[channel].mar & 0xffff0000) >> 16;
5052   case 0x07:  // MAR (low)
51      return (dmac.reg[channel].mar & 0x0000ffff);
53      return (dmac->reg[channel].mar & 0x0000ffff);
5254   case 0x0a:  // DAR (high)
53      return (dmac.reg[channel].dar & 0xffff0000) >> 16;
55      return (dmac->reg[channel].dar & 0xffff0000) >> 16;
5456   case 0x0b:  // DAR (low)
55      return (dmac.reg[channel].dar & 0x0000ffff);
57      return (dmac->reg[channel].dar & 0x0000ffff);
5658   case 0x0d:  // BTC
57      return dmac.reg[channel].btc;
59      return dmac->reg[channel].btc;
5860   case 0x0e:  // BAR (high)
59      return (dmac.reg[channel].bar & 0xffff0000) >> 16;
61      return (dmac->reg[channel].bar & 0xffff0000) >> 16;
6062   case 0x0f:  // BAR (low)
61      return (dmac.reg[channel].bar & 0x0000ffff);
63      return (dmac->reg[channel].bar & 0x0000ffff);
6264   case 0x12:  // NIV
63      return dmac.reg[channel].niv;
65      return dmac->reg[channel].niv;
6466   case 0x13:  // EIV
65      return dmac.reg[channel].eiv;
67      return dmac->reg[channel].eiv;
6668   case 0x14:  // MFC
67      return dmac.reg[channel].mfc;
69      return dmac->reg[channel].mfc;
6870   case 0x16:  // CPR
69      return dmac.reg[channel].cpr;
71      return dmac->reg[channel].cpr;
7072   case 0x18:  // DFC
71      return dmac.reg[channel].dfc;
73      return dmac->reg[channel].dfc;
7274   case 0x1c:  // BFC
73      return dmac.reg[channel].bfc;
75      return dmac->reg[channel].bfc;
7476   case 0x1f:  // GCR
75      return dmac.reg[channel].gcr;
77      return dmac->reg[channel].gcr;
7678   }
7779   return 0xff;
7880}
7981
80void hd63450_write(running_machine *machine, int offset, int data, UINT16 mem_mask)
82void hd63450_write(const device_config* device, int offset, int data, UINT16 mem_mask)
8183{
8284   int channel,reg;
8385
86   hd63450_t* dmac = device->token;
87
8488   channel = (offset & 0x60) >> 5;
8589   reg = offset & 0x1f;
8690   switch(reg)
r2505r2506
8892   case 0x00:  // CSR / CER
8993      if(ACCESSING_BITS_8_15)
9094      {
91//         dmac.reg[channel].csr = (data & 0xff00) >> 8;
95//         dmac->reg[channel].csr = (data & 0xff00) >> 8;
9296//         logerror("DMA#%i: Channel status write : %02x\n",channel,dmac.reg[channel].csr);
9397      }
9498      // CER is read-only, so no action needed there.
r2505r2506
96100   case 0x02:  // DCR / OCR
97101      if(ACCESSING_BITS_8_15)
98102      {
99         dmac.reg[channel].dcr = (data & 0xff00) >> 8;
100         logerror("DMA#%i: Device Control write : %02x\n",channel,dmac.reg[channel].dcr);
103         dmac->reg[channel].dcr = (data & 0xff00) >> 8;
104         logerror("DMA#%i: Device Control write : %02x\n",channel,dmac->reg[channel].dcr);
101105      }
102106      if(ACCESSING_BITS_0_7)
103107      {
104         dmac.reg[channel].ocr = data & 0x00ff;
105         logerror("DMA#%i: Operation Control write : %02x\n",channel,dmac.reg[channel].ocr);
108         dmac->reg[channel].ocr = data & 0x00ff;
109         logerror("DMA#%i: Operation Control write : %02x\n",channel,dmac->reg[channel].ocr);
106110      }
107111      break;
108112   case 0x03:  // SCR / CCR
109113      if(ACCESSING_BITS_8_15)
110114      {
111         dmac.reg[channel].scr = (data & 0xff00) >> 8;
112         logerror("DMA#%i: Sequence Control write : %02x\n",channel,dmac.reg[channel].scr);
115         dmac->reg[channel].scr = (data & 0xff00) >> 8;
116         logerror("DMA#%i: Sequence Control write : %02x\n",channel,dmac->reg[channel].scr);
113117      }
114118      if(ACCESSING_BITS_0_7)
115119      {
116         dmac.reg[channel].ccr = data & 0x00ff;
117         if((data & 0x0080))// && !dmac.intf->dma_read[channel] && !dmac.intf->dma_write[channel])
118            dma_transfer_start(machine, channel,0);
120         dmac->reg[channel].ccr = data & 0x00ff;
121         if((data & 0x0080))// && !dmac->intf->dma_read[channel] && !dmac->intf->dma_write[channel])
122            dma_transfer_start(device, channel,0);
119123         if(data & 0x0010)  // software abort
120            dma_transfer_abort(channel);
124            dma_transfer_abort(device,channel);
121125         if(data & 0x0020)  // halt operation
122            dma_transfer_halt(channel);
126            dma_transfer_halt(device,channel);
123127         if(data & 0x0040)  // continure operation
124            dma_transfer_continue(channel);
125         logerror("DMA#%i: Channel Control write : %02x\n",channel,dmac.reg[channel].ccr);
128            dma_transfer_continue(device,channel);
129         logerror("DMA#%i: Channel Control write : %02x\n",channel,dmac->reg[channel].ccr);
126130      }
127131      break;
128132   case 0x05:  // MTC
129      dmac.reg[channel].mtc = data;
130      logerror("DMA#%i:  Memory Transfer Counter write : %04x\n",channel,dmac.reg[channel].mtc);
133      dmac->reg[channel].mtc = data;
134      logerror("DMA#%i:  Memory Transfer Counter write : %04x\n",channel,dmac->reg[channel].mtc);
131135      break;
132136   case 0x06:  // MAR (high)
133      dmac.reg[channel].mar = (dmac.reg[channel].mar & 0x0000ffff) | (data << 16);
134      logerror("DMA#%i:  Memory Address write : %08lx\n",channel,dmac.reg[channel].mar);
137      dmac->reg[channel].mar = (dmac->reg[channel].mar & 0x0000ffff) | (data << 16);
138      logerror("DMA#%i:  Memory Address write : %08lx\n",channel,dmac->reg[channel].mar);
135139      break;
136140   case 0x07:  // MAR (low)
137      dmac.reg[channel].mar = (dmac.reg[channel].mar & 0xffff0000) | (data & 0x0000ffff);
138      logerror("DMA#%i:  Memory Address write : %08lx\n",channel,dmac.reg[channel].mar);
141      dmac->reg[channel].mar = (dmac->reg[channel].mar & 0xffff0000) | (data & 0x0000ffff);
142      logerror("DMA#%i:  Memory Address write : %08lx\n",channel,dmac->reg[channel].mar);
139143      break;
140144   case 0x0a:  // DAR (high)
141      dmac.reg[channel].dar = (dmac.reg[channel].dar & 0x0000ffff) | (data << 16);
142      logerror("DMA#%i:  Device Address write : %08lx\n",channel,dmac.reg[channel].dar);
145      dmac->reg[channel].dar = (dmac->reg[channel].dar & 0x0000ffff) | (data << 16);
146      logerror("DMA#%i:  Device Address write : %08lx\n",channel,dmac->reg[channel].dar);
143147      break;
144148   case 0x0b:  // DAR (low)
145      dmac.reg[channel].dar = (dmac.reg[channel].dar & 0xffff0000) | (data & 0x0000ffff);
146      logerror("DMA#%i:  Device Address write : %08lx\n",channel,dmac.reg[channel].dar);
149      dmac->reg[channel].dar = (dmac->reg[channel].dar & 0xffff0000) | (data & 0x0000ffff);
150      logerror("DMA#%i:  Device Address write : %08lx\n",channel,dmac->reg[channel].dar);
147151      break;
148152   case 0x0d:  // BTC
149      dmac.reg[channel].btc = data;
150      logerror("DMA#%i:  Base Transfer Counter write : %04x\n",channel,dmac.reg[channel].btc);
153      dmac->reg[channel].btc = data;
154      logerror("DMA#%i:  Base Transfer Counter write : %04x\n",channel,dmac->reg[channel].btc);
151155      break;
152156   case 0x0e:  // BAR (high)
153      dmac.reg[channel].bar = (dmac.reg[channel].bar & 0x0000ffff) | (data << 16);
154      logerror("DMA#%i:  Base Address write : %08lx\n",channel,dmac.reg[channel].bar);
157      dmac->reg[channel].bar = (dmac->reg[channel].bar & 0x0000ffff) | (data << 16);
158      logerror("DMA#%i:  Base Address write : %08lx\n",channel,dmac->reg[channel].bar);
155159      break;
156160   case 0x0f:  // BAR (low)
157      dmac.reg[channel].bar = (dmac.reg[channel].bar & 0xffff0000) | (data & 0x0000ffff);
158      logerror("DMA#%i:  Base Address write : %08lx\n",channel,dmac.reg[channel].bar);
161      dmac->reg[channel].bar = (dmac->reg[channel].bar & 0xffff0000) | (data & 0x0000ffff);
162      logerror("DMA#%i:  Base Address write : %08lx\n",channel,dmac->reg[channel].bar);
159163      break;
160164   case 0x12:  // NIV
161      dmac.reg[channel].niv = data & 0xff;
162      logerror("DMA#%i:  Normal IRQ Vector write : %02x\n",channel,dmac.reg[channel].niv);
165      dmac->reg[channel].niv = data & 0xff;
166      logerror("DMA#%i:  Normal IRQ Vector write : %02x\n",channel,dmac->reg[channel].niv);
163167      break;
164168   case 0x13:  // EIV
165      dmac.reg[channel].eiv = data & 0xff;
166      logerror("DMA#%i:  Error IRQ Vector write : %02x\n",channel,dmac.reg[channel].eiv);
169      dmac->reg[channel].eiv = data & 0xff;
170      logerror("DMA#%i:  Error IRQ Vector write : %02x\n",channel,dmac->reg[channel].eiv);
167171      break;
168172   case 0x14:  // MFC
169      dmac.reg[channel].mfc = data & 0xff;
170      logerror("DMA#%i:  Memory Function Code write : %02x\n",channel,dmac.reg[channel].mfc);
173      dmac->reg[channel].mfc = data & 0xff;
174      logerror("DMA#%i:  Memory Function Code write : %02x\n",channel,dmac->reg[channel].mfc);
171175      break;
172176   case 0x16:  // CPR
173      dmac.reg[channel].cpr = data & 0xff;
174      logerror("DMA#%i:  Channel Priority write : %02x\n",channel,dmac.reg[channel].cpr);
177      dmac->reg[channel].cpr = data & 0xff;
178      logerror("DMA#%i:  Channel Priority write : %02x\n",channel,dmac->reg[channel].cpr);
175179      break;
176180   case 0x18:  // DFC
177      dmac.reg[channel].dfc = data & 0xff;
178      logerror("DMA#%i:  Device Function Code write : %02x\n",channel,dmac.reg[channel].dfc);
181      dmac->reg[channel].dfc = data & 0xff;
182      logerror("DMA#%i:  Device Function Code write : %02x\n",channel,dmac->reg[channel].dfc);
179183      break;
180184   case 0x1c:  // BFC
181      dmac.reg[channel].bfc = data & 0xff;
182      logerror("DMA#%i:  Base Function Code write : %02x\n",channel,dmac.reg[channel].bfc);
185      dmac->reg[channel].bfc = data & 0xff;
186      logerror("DMA#%i:  Base Function Code write : %02x\n",channel,dmac->reg[channel].bfc);
183187      break;
184188   case 0x1f:
185      dmac.reg[channel].gcr = data & 0xff;
186      logerror("DMA#%i:  General Control write : %02x\n",channel,dmac.reg[channel].gcr);
189      dmac->reg[channel].gcr = data & 0xff;
190      logerror("DMA#%i:  General Control write : %02x\n",channel,dmac->reg[channel].gcr);
187191      break;
188192   }
189193}
190194
191void dma_transfer_start(running_machine *machine, int channel, int dir)
195void dma_transfer_start(const device_config* device, int channel, int dir)
192196{
193   dmac.in_progress[channel] = 1;
194   dmac.reg[channel].csr &= ~0xe0;
195   dmac.reg[channel].csr |= 0x08;  // Channel active
196   dmac.reg[channel].csr &= ~0x30;  // Reset Error and Normal termination bits
197   if(dmac.reg[channel].btc > 0)
197   hd63450_t* dmac = device->token;
198   dmac->in_progress[channel] = 1;
199   dmac->reg[channel].csr &= ~0xe0;
200   dmac->reg[channel].csr |= 0x08;  // Channel active
201   dmac->reg[channel].csr &= ~0x30;  // Reset Error and Normal termination bits
202   if(dmac->reg[channel].btc > 0)
198203   {
199      dmac.reg[channel].mar = program_read_word(dmac.reg[channel].bar) << 8;
200      dmac.reg[channel].mar |= program_read_word(dmac.reg[channel].bar+2);
201      dmac.reg[channel].mtc = program_read_word(dmac.reg[channel].bar+4);
202      dmac.reg[channel].btc--;
204      dmac->reg[channel].mar = program_read_word(dmac->reg[channel].bar) << 8;
205      dmac->reg[channel].mar |= program_read_word(dmac->reg[channel].bar+2);
206      dmac->reg[channel].mtc = program_read_word(dmac->reg[channel].bar+4);
207      dmac->reg[channel].btc--;
203208   }
204209
205210   // Burst transfers will halt the CPU until the transfer is complete
206   if((dmac.reg[channel].dcr & 0xc0) == 0x00)  // Burst transfer
211   if((dmac->reg[channel].dcr & 0xc0) == 0x00)  // Burst transfer
207212   {
208      cpunum_set_input_line(machine, dmac.intf->cpu,INPUT_LINE_HALT,ASSERT_LINE);
209      timer_adjust_periodic(dmac.timer[channel], attotime_zero, channel, dmac.intf->burst_clock[channel]);
213      cpunum_set_input_line(device->machine, dmac->intf->cpu,INPUT_LINE_HALT,ASSERT_LINE);
214      timer_adjust_periodic(dmac->timer[channel], attotime_zero, channel, dmac->intf->burst_clock[channel]);
210215   }
211216   else
212      timer_adjust_periodic(dmac.timer[channel], ATTOTIME_IN_USEC(500), channel, dmac.intf->clock[channel]);
217      timer_adjust_periodic(dmac->timer[channel], ATTOTIME_IN_USEC(500), channel, dmac->intf->clock[channel]);
213218
214219
215   dmac.transfer_size[channel] = dmac.reg[channel].mtc;
220   dmac->transfer_size[channel] = dmac->reg[channel].mtc;
216221
217   logerror("DMA: Transfer begins: size=0x%08x\n",dmac.transfer_size[channel]);
222   logerror("DMA: Transfer begins: size=0x%08x\n",dmac->transfer_size[channel]);
218223}
219224
220225static TIMER_CALLBACK(dma_transfer_timer)
221226{
222   hd63450_single_transfer(machine, param);
227   hd63450_single_transfer(ptr, param);
223228}
224229
225static void dma_transfer_abort(int channel)
230static void dma_transfer_abort(const device_config* device, int channel)
226231{
232   hd63450_t* dmac = device->token;
233
227234   logerror("DMA#%i: Transfer aborted\n",channel);
228   timer_adjust_oneshot(dmac.timer[channel], attotime_zero, 0);
229   dmac.in_progress[channel] = 0;
230   dmac.reg[channel].mtc = dmac.transfer_size[channel];
231   dmac.reg[channel].csr |= 0xe0;  // channel operation complete, block transfer complete
232   dmac.reg[channel].csr &= ~0x08;  // channel no longer active
235   timer_adjust_oneshot(dmac->timer[channel], attotime_zero, 0);
236   dmac->in_progress[channel] = 0;
237   dmac->reg[channel].mtc = dmac->transfer_size[channel];
238   dmac->reg[channel].csr |= 0xe0;  // channel operation complete, block transfer complete
239   dmac->reg[channel].csr &= ~0x08;  // channel no longer active
233240}
234241
235static void dma_transfer_halt(int channel)
242static void dma_transfer_halt(const device_config* device, int channel)
236243{
237   dmac.halted[channel] = 1;
238   timer_adjust_oneshot(dmac.timer[channel], attotime_zero, 0);
244   hd63450_t* dmac = device->token;
245
246   dmac->halted[channel] = 1;
247   timer_adjust_oneshot(dmac->timer[channel], attotime_zero, 0);
239248}
240249
241static void dma_transfer_continue(int channel)
250static void dma_transfer_continue(const device_config* device, int channel)
242251{
243   if(dmac.halted[channel] != 0)
252   hd63450_t* dmac = device->token;
253
254   if(dmac->halted[channel] != 0)
244255   {
245      dmac.halted[channel] = 0;
246      timer_adjust_periodic(dmac.timer[channel], attotime_zero, channel, dmac.intf->clock[channel]);
256      dmac->halted[channel] = 0;
257      timer_adjust_periodic(dmac->timer[channel], attotime_zero, channel, dmac->intf->clock[channel]);
247258   }
248259}
249260
250void hd63450_single_transfer(running_machine *machine, int x)
261void hd63450_single_transfer(const device_config* device, int x)
251262{
252263   int data;
253264   int datasize = 1;
265   hd63450_t* dmac = device->token;
254266
255      if(dmac.in_progress[x] != 0)  // DMA in progress in channel x
267      if(dmac->in_progress[x] != 0)  // DMA in progress in channel x
256268      {
257         if(dmac.reg[x].ocr & 0x80)  // direction: 1 = device -> memory
269         if(dmac->reg[x].ocr & 0x80)  // direction: 1 = device -> memory
258270         {
259            if(dmac.intf->dma_read[x])
271            if(dmac->intf->dma_read[x])
260272            {
261               data = dmac.intf->dma_read[x](dmac.reg[x].mar);
273               data = dmac->intf->dma_read[x](dmac->reg[x].mar);
262274               if(data == -1)
263275                  return;  // not ready to recieve data
264               program_write_byte(dmac.reg[x].mar,data);
276               program_write_byte(dmac->reg[x].mar,data);
265277               datasize = 1;
266278            }
267279            else
268280            {
269               switch(dmac.reg[x].ocr & 0x30)  // operation size
281               switch(dmac->reg[x].ocr & 0x30)  // operation size
270282               {
271283               case 0x00:  // 8 bit
272                  data = program_read_byte(dmac.reg[x].dar);  // read from device address
273                  program_write_byte(dmac.reg[x].mar, data);  // write to memory address
284                  data = program_read_byte(dmac->reg[x].dar);  // read from device address
285                  program_write_byte(dmac->reg[x].mar, data);  // write to memory address
274286                  datasize = 1;
275287                  break;
276288               case 0x10:  // 16 bit
277                  data = program_read_word(dmac.reg[x].dar);  // read from device address
278                  program_write_word(dmac.reg[x].mar, data);  // write to memory address
289                  data = program_read_word(dmac->reg[x].dar);  // read from device address
290                  program_write_word(dmac->reg[x].mar, data);  // write to memory address
279291                  datasize = 2;
280292                  break;
281293               case 0x20:  // 32 bit
282                  data = program_read_word(dmac.reg[x].dar) << 16;  // read from device address
283                  data |= program_read_word(dmac.reg[x].dar+2);
284                  program_write_word(dmac.reg[x].mar, (data & 0xffff0000) >> 16);  // write to memory address
285                  program_write_word(dmac.reg[x].mar+2, data & 0x0000ffff);
294                  data = program_read_word(dmac->reg[x].dar) << 16;  // read from device address
295                  data |= program_read_word(dmac->reg[x].dar+2);
296                  program_write_word(dmac->reg[x].mar, (data & 0xffff0000) >> 16);  // write to memory address
297                  program_write_word(dmac->reg[x].mar+2, data & 0x0000ffff);
286298                  datasize = 4;
287299                  break;
288300               case 0x30:  // 8 bit packed (?)
289                  data = program_read_byte(dmac.reg[x].dar);  // read from device address
290                  program_write_byte(dmac.reg[x].mar, data);  // write to memory address
301                  data = program_read_byte(dmac->reg[x].dar);  // read from device address
302                  program_write_byte(dmac->reg[x].mar, data);  // write to memory address
291303                  datasize = 1;
292304                  break;
293305               }
r2505r2506
296308         }
297309         else  // memory -> device
298310         {
299            if(dmac.intf->dma_write[x])
311            if(dmac->intf->dma_write[x])
300312            {
301               data = program_read_byte(dmac.reg[x].mar);
302               dmac.intf->dma_write[x](dmac.reg[x].mar,data);
313               data = program_read_byte(dmac->reg[x].mar);
314               dmac->intf->dma_write[x](dmac->reg[x].mar,data);
303315               datasize = 1;
304316            }
305317            else
306318            {
307               switch(dmac.reg[x].ocr & 0x30)  // operation size
319               switch(dmac->reg[x].ocr & 0x30)  // operation size
308320               {
309321               case 0x00:  // 8 bit
310                  data = program_read_byte(dmac.reg[x].mar);  // read from memory address
311                  program_write_byte(dmac.reg[x].dar, data);  // write to device address
322                  data = program_read_byte(dmac->reg[x].mar);  // read from memory address
323                  program_write_byte(dmac->reg[x].dar, data);  // write to device address
312324                  datasize = 1;
313325                  break;
314326               case 0x10:  // 16 bit
315                  data = program_read_word(dmac.reg[x].mar);  // read from memory address
316                  program_write_word(dmac.reg[x].dar, data);  // write to device address
327                  data = program_read_word(dmac->reg[x].mar);  // read from memory address
328                  program_write_word(dmac->reg[x].dar, data);  // write to device address
317329                  datasize = 2;
318330                  break;
319331               case 0x20:  // 32 bit
320                  data = program_read_word(dmac.reg[x].mar) << 16;  // read from memory address
321                  data |= program_read_word(dmac.reg[x].mar+2);  // read from memory address
322                  program_write_word(dmac.reg[x].dar, (data & 0xffff0000) >> 16);  // write to device address
323                  program_write_word(dmac.reg[x].dar+2, data & 0x0000ffff);  // write to device address
332                  data = program_read_word(dmac->reg[x].mar) << 16;  // read from memory address
333                  data |= program_read_word(dmac->reg[x].mar+2);  // read from memory address
334                  program_write_word(dmac->reg[x].dar, (data & 0xffff0000) >> 16);  // write to device address
335                  program_write_word(dmac->reg[x].dar+2, data & 0x0000ffff);  // write to device address
324336                  datasize = 4;
325337                  break;
326338               case 0x30:  // 8 bit packed (?)
327                  data = program_read_byte(dmac.reg[x].mar);  // read from memory address
328                  //program_write_byte(dmac.reg[x].dar, data);  // write to device address  -- disabled for now
339                  data = program_read_byte(dmac->reg[x].mar);  // read from memory address
340                  //program_write_byte(dmac->reg[x].dar, data);  // write to device address  -- disabled for now
329341                  datasize = 1;
330342                  break;
331343               }
332344            }
333//            logerror("DMA#%i: byte transfer %08lx -> %08lx\n",x,dmac.reg[x].mar,dmac.reg[x].dar);
345//            logerror("DMA#%i: byte transfer %08lx -> %08lx\n",x,dmac->reg[x].mar,dmac->reg[x].dar);
334346         }
335347
336348
337349         // decrease memory transfer counter
338         if(dmac.reg[x].mtc > 0)
339            dmac.reg[x].mtc--;
350         if(dmac->reg[x].mtc > 0)
351            dmac->reg[x].mtc--;
340352
341353         // handle change of memory and device addresses
342         if((dmac.reg[x].scr & 0x03) == 0x01)
343            dmac.reg[x].dar+=datasize;
344         else if((dmac.reg[x].scr & 0x03) == 0x02)
345            dmac.reg[x].dar-=datasize;
354         if((dmac->reg[x].scr & 0x03) == 0x01)
355            dmac->reg[x].dar+=datasize;
356         else if((dmac->reg[x].scr & 0x03) == 0x02)
357            dmac->reg[x].dar-=datasize;
346358
347         if((dmac.reg[x].scr & 0x0c) == 0x04)
348            dmac.reg[x].mar+=datasize;
349         else if((dmac.reg[x].scr & 0x0c) == 0x08)
350            dmac.reg[x].mar-=datasize;
359         if((dmac->reg[x].scr & 0x0c) == 0x04)
360            dmac->reg[x].mar+=datasize;
361         else if((dmac->reg[x].scr & 0x0c) == 0x08)
362            dmac->reg[x].mar-=datasize;
351363
352         if(dmac.reg[x].mtc <= 0)
364         if(dmac->reg[x].mtc <= 0)
353365         {
354366            // End of transfer
355367            logerror("DMA#%i: End of transfer\n",x);
356            if(dmac.reg[x].btc > 0)
368            if(dmac->reg[x].btc > 0)
357369            {
358               dmac.reg[x].btc--;
359               dmac.reg[x].bar+=6;
360               dmac.reg[x].mar = program_read_word(dmac.reg[x].bar) << 8;
361               dmac.reg[x].mar |= program_read_word(dmac.reg[x].bar+2);
362               dmac.reg[x].mtc = program_read_word(dmac.reg[x].bar+4);
370               dmac->reg[x].btc--;
371               dmac->reg[x].bar+=6;
372               dmac->reg[x].mar = program_read_word(dmac->reg[x].bar) << 8;
373               dmac->reg[x].mar |= program_read_word(dmac->reg[x].bar+2);
374               dmac->reg[x].mtc = program_read_word(dmac->reg[x].bar+4);
363375               return;
364376            }
365            timer_adjust_oneshot(dmac.timer[x], attotime_zero, 0);
366            dmac.in_progress[x] = 0;
367            dmac.reg[x].mtc = dmac.transfer_size[x];
368            dmac.reg[x].csr |= 0xe0;  // channel operation complete, block transfer complete
369            dmac.reg[x].csr &= ~0x08;  // channel no longer active
370            if((dmac.reg[x].dcr & 0xc0) == 0x00)  // Burst transfer
371               cpunum_set_input_line(machine, dmac.intf->cpu,INPUT_LINE_HALT,CLEAR_LINE);
377            timer_adjust_oneshot(dmac->timer[x], attotime_zero, 0);
378            dmac->in_progress[x] = 0;
379            dmac->reg[x].mtc = dmac->transfer_size[x];
380            dmac->reg[x].csr |= 0xe0;  // channel operation complete, block transfer complete
381            dmac->reg[x].csr &= ~0x08;  // channel no longer active
382            if((dmac->reg[x].dcr & 0xc0) == 0x00)  // Burst transfer
383               cpunum_set_input_line(device->machine, dmac->intf->cpu,INPUT_LINE_HALT,CLEAR_LINE);
372384
373            if(dmac.intf->dma_end)
374               dmac.intf->dma_end(x,dmac.reg[x].ccr & 0x08);
385            if(dmac->intf->dma_end)
386               dmac->intf->dma_end(x,dmac->reg[x].ccr & 0x08);
375387         }
376388      }
377389}
378390
379int hd63450_get_vector(int channel)
391int hd63450_get_vector(const device_config* device, int channel)
380392{
381   return dmac.reg[channel].niv;
393   hd63450_t* dmac = device->token;
394   return dmac->reg[channel].niv;
382395}
383396
384int hd63450_get_error_vector(int channel)
397int hd63450_get_error_vector(const device_config* device, int channel)
385398{
386   return dmac.reg[channel].eiv;
399   hd63450_t* dmac = device->token;
400   return dmac->reg[channel].eiv;
387401}
388402
403static DEVICE_SET_INFO( hd63450 )
404{
405   switch (state)
406   {
407      /* no parameters to set */
408   }
409}
389410
390READ16_HANDLER(hd63450_r) { return hd63450_read(machine,offset,mem_mask); }
391WRITE16_HANDLER(hd63450_w) { hd63450_write(machine,offset,data,mem_mask); }
411DEVICE_GET_INFO(hd63450)
412{
413   switch (state)
414   {
415      /* --- the following bits of info are returned as 64-bit signed integers --- */
416      case DEVINFO_INT_CLASS:                     info->i = DEVICE_CLASS_OTHER;            break;
417      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(hd63450_t);            break;
392418
419      /* --- the following bits of info are returned as pointers to data or functions --- */
420      case DEVINFO_FCT_SET_INFO:                  info->set_info = DEVICE_SET_INFO_NAME(hd63450); break;
421      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(hd63450);   break;
422      case DEVINFO_FCT_STOP:                     /* Nothing */                        break;
423      case DEVINFO_FCT_RESET:                     /*info->reset = DEVICE_RESET_NAME(hd63450);*/   break;
424
425      /* --- the following bits of info are returned as NULL-terminated strings --- */
426      case DEVINFO_STR_NAME:                     info->s = "Hitachi HD63450";            break;
427      case DEVINFO_STR_FAMILY:                  info->s = "DMA Controller";               break;
428      case DEVINFO_STR_VERSION:                  info->s = "1.0";                     break;
429      case DEVINFO_STR_SOURCE_FILE:               info->s = __FILE__;                     break;
430      case DEVINFO_STR_CREDITS:                  info->s = "Copyright the MESS Team";       break;
431   }
432}
433
434READ16_DEVICE_HANDLER(hd63450_r) { return hd63450_read(device,offset,mem_mask); }
435WRITE16_DEVICE_HANDLER(hd63450_w) { hd63450_write(device,offset,data,mem_mask); }
436
src/mess/machine/hd63450.h
r2505r2506
44
55#include "driver.h"
66
7struct hd63450_interface
7typedef struct _hd63450_interface hd63450_intf;
8struct _hd63450_interface
89{
910   int cpu;
1011   attotime clock[4];
r2505r2506
1516   void (*dma_write[4])(int addr,int data);
1617};
1718
18struct hd63450
19typedef struct _hd63450_regs hd63450_regs;
20struct _hd63450_regs
21{  // offsets in bytes
22   unsigned char csr;  // [00] Channel status register (R/W)
23   unsigned char cer;  // [01] Channel error register (R)
24   unsigned char dcr;  // [04] Device control register (R/W)
25   unsigned char ocr;  // [05] Operation control register (R/W)
26   unsigned char scr;  // [06] Sequence control register (R/W)
27   unsigned char ccr;  // [07] Channel control register (R/W)
28   unsigned short mtc;  // [0a,0b]  Memory Transfer Counter (R/W)
29   unsigned long mar;  // [0c-0f]  Memory Address Register (R/W)
30   unsigned long dar;  // [14-17]  Device Address Register (R/W)
31   unsigned short btc;  // [1a,1b]  Base Transfer Counter (R/W)
32   unsigned long bar;  // [1c-1f]  Base Address Register (R/W)
33   unsigned char niv;  // [25]  Normal Interrupt Vector (R/W)
34   unsigned char eiv;  // [27]  Error Interrupt Vector (R/W)
35   unsigned char mfc;  // [29]  Memory Function Code (R/W)
36   unsigned char cpr;  // [2d]  Channel Priority Register (R/W)
37   unsigned char dfc;  // [31]  Device Function Code (R/W)
38   unsigned char bfc;  // [39]  Base Function Code (R/W)
39   unsigned char gcr;  // [3f]  General Control Register (R/W)
40};
41
42typedef struct _hd63450_t hd63450_t;
43struct _hd63450_t
1944{
20   struct
21   {  // offsets in bytes
22      unsigned char csr;  // [00] Channel status register (R/W)
23      unsigned char cer;  // [01] Channel error register (R)
24      unsigned char dcr;  // [04] Device control register (R/W)
25      unsigned char ocr;  // [05] Operation control register (R/W)
26      unsigned char scr;  // [06] Sequence control register (R/W)
27      unsigned char ccr;  // [07] Channel control register (R/W)
28      unsigned short mtc;  // [0a,0b]  Memory Transfer Counter (R/W)
29      unsigned long mar;  // [0c-0f]  Memory Address Register (R/W)
30      unsigned long dar;  // [14-17]  Device Address Register (R/W)
31      unsigned short btc;  // [1a,1b]  Base Transfer Counter (R/W)
32      unsigned long bar;  // [1c-1f]  Base Address Register (R/W)
33      unsigned char niv;  // [25]  Normal Interrupt Vector (R/W)
34      unsigned char eiv;  // [27]  Error Interrupt Vector (R/W)
35      unsigned char mfc;  // [29]  Memory Function Code (R/W)
36      unsigned char cpr;  // [2d]  Channel Priority Register (R/W)
37      unsigned char dfc;  // [31]  Device Function Code (R/W)
38      unsigned char bfc;  // [39]  Base Function Code (R/W)
39      unsigned char gcr;  // [3f]  General Control Register (R/W)
40   } reg[4];
45    hd63450_regs reg[4];
4146   emu_timer* timer[4];  // for timing data reading/writing each channel
4247   int in_progress[4];  // if a channel is in use
4348   int transfer_size[4];
4449   int halted[4];  // non-zero if a channel has been halted, and can be continued later.
45   const struct hd63450_interface* intf;
50   const hd63450_intf* intf;
4651};
4752
48void hd63450_init(const struct hd63450_interface* intf);
49int hd63450_read(running_machine *machine, int offset, UINT16 mem_mask);
50void hd63450_write(running_machine *machine,int offset, int data, UINT16 mem_mask);
51void hd63450_single_transfer(running_machine *machine, int x);
53DEVICE_START( hd63450 );
54DEVICE_GET_INFO( hd63450 );
5255
53void dma_transfer_start(running_machine *machine, int channel, int dir);
56int hd63450_read(const device_config* device, int offset, UINT16 mem_mask);
57void hd63450_write(const device_config* device,int offset, int data, UINT16 mem_mask);
58void hd63450_single_transfer(const device_config* device, int x);
5459
55int hd63450_get_vector(int channel);
56int hd63450_get_error_vector(int channel);
60void dma_transfer_start(const device_config* device, int channel, int dir);
5761
58READ16_HANDLER( hd63450_r );
59WRITE16_HANDLER( hd63450_w );
62int hd63450_get_vector(const device_config* device, int channel);
63int hd63450_get_error_vector(const device_config* device, int channel);
64
65#define HD63450 DEVICE_GET_INFO_NAME(hd63450)
66
67READ16_DEVICE_HANDLER( hd63450_r );
68WRITE16_DEVICE_HANDLER( hd63450_w );
src/mess/drivers/x68k.c
r2505r2506
344344// 4 channel DMA controller (Hitachi HD63450)
345345static WRITE16_HANDLER( x68k_dmac_w )
346346{
347   hd63450_w(machine, offset, data, mem_mask);
347   const device_config* device = device_list_find_by_tag(machine->config->devicelist,HD63450,"hd63450");
348   hd63450_w(device, offset, data, mem_mask);
348349}
349350
350351static READ16_HANDLER( x68k_dmac_r )
351352{
352   return hd63450_r(machine, offset, mem_mask);
353   const device_config* device = device_list_find_by_tag(machine->config->devicelist,HD63450,"hd63450");
354   return hd63450_r(device, offset, mem_mask);
353355}
354356
355357static void x68k_keyboard_ctrl_w(int data)
r2505r2506
13831385
13841386static void x68k_dma_irq(running_machine *machine, int channel)
13851387{
1386   current_vector[3] = hd63450_get_vector(channel);
1388   const device_config *device = device_list_find_by_tag(machine->config->devicelist, HD63450, "hd63450");
1389   current_vector[3] = hd63450_get_vector(device, channel);
13871390   current_irq_line = 3;
13881391   logerror("DMA#%i: DMA End (vector 0x%02x)\n",channel,current_vector[3]);
13891392   cpunum_set_input_line_and_vector(machine, 0,3,ASSERT_LINE,current_vector[3]);
r2505r2506
13991402
14001403static void x68k_dma_error(int channel, int irq)
14011404{
1405   const device_config *device = device_list_find_by_tag(Machine->config->devicelist, HD63450, "hd63450");
14021406   if(irq != 0)
14031407   {
1404      current_vector[3] = hd63450_get_error_vector(channel);
1408      current_vector[3] = hd63450_get_error_vector(device,channel);
14051409      current_irq_line = 3;
14061410      cpunum_set_input_line_and_vector(Machine, 0,3,ASSERT_LINE,current_vector[3]);
14071411   }
r2505r2506
15621566   ppi_port_c_w
15631567};
15641568
1565static const struct hd63450_interface dmac_interface =
1569static const hd63450_intf dmac_interface =
15661570{
15671571   0,  // CPU - 68000
15681572   {STATIC_ATTOTIME_IN_USEC(32),STATIC_ATTOTIME_IN_USEC(32),STATIC_ATTOTIME_IN_USEC(4),STATIC_ATTOTIME_IN_USEC(32)},  // Cycle steal mode timing (guesstimate)
r2505r2506
19841988
19851989   memset(&sys,0,sizeof(sys));
19861990
1987   hd63450_init(&dmac_interface);
19881991   mfp_init();
19891992   scc_init(&scc_interface);
19901993   rp5c15_init(machine, &rtc_intf);
r2505r2506
20192022   MDRV_DEVICE_ADD( "ppi8255", PPI8255 )
20202023   MDRV_DEVICE_CONFIG( ppi_interface )
20212024
2025   MDRV_DEVICE_ADD( "hd63450", HD63450 )
2026   MDRV_DEVICE_CONFIG( dmac_interface )
2027
20222028    /* video hardware */
20232029   MDRV_SCREEN_ADD("main", RASTER)
20242030   MDRV_SCREEN_REFRESH_RATE(55.45)
docs/messnew.txt
r2505r2506
112112- Fixed a regression in natural keyboard support that could cause certain keys
113113  to not be recognized.  (bug #1564)  [Nate Woods]
114114
115- Converted HD63450 DMA controller to the new device system.  [Barry Rodewald]
115116
116117
118
1171190.124a
118120
119121New System Drivers Supported (in no particular order):

Previous 15994 Revisions Next


© 1998-2018 The MESS Team