src/mess/machine/hd63450.c
| r2505 | r2506 | |
| 7 | 7 | #include "machine/hd63450.h" |
| 8 | 8 | |
| 9 | 9 | |
| 10 | | static struct hd63450 dmac; |
| 11 | | |
| 12 | 10 | static TIMER_CALLBACK(dma_transfer_timer); |
| 13 | | static void dma_transfer_abort(int channel); |
| 14 | | static void dma_transfer_halt(int channel); |
| 15 | | static void dma_transfer_continue(int channel); |
| 11 | static void dma_transfer_abort(const device_config* device, int channel); |
| 12 | static void dma_transfer_halt(const device_config* device, int channel); |
| 13 | static void dma_transfer_continue(const device_config* device, int channel); |
| 16 | 14 | |
| 17 | | void hd63450_init(const struct hd63450_interface* intf) |
| 15 | DEVICE_START(hd63450) |
| 18 | 16 | { |
| 17 | hd63450_t* dmac = device->token; |
| 19 | 18 | int x; |
| 20 | 19 | |
| 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 |
| 23 | 24 | for(x=0;x<4;x++) |
| 24 | 25 | { |
| 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; |
| 28 | 29 | } |
| 29 | 30 | } |
| 30 | 31 | |
| 31 | | int hd63450_read(running_machine *machine, int offset, UINT16 mem_mask) |
| 32 | int hd63450_read(const device_config* device, int offset, UINT16 mem_mask) |
| 32 | 33 | { |
| 33 | 34 | int channel,reg; |
| 35 | hd63450_t* dmac = device->token; |
| 34 | 36 | |
| 35 | 37 | channel = (offset & 0x60) >> 5; |
| 36 | 38 | reg = offset & 0x1f; |
| r2505 | r2506 | |
| 38 | 40 | switch(reg) |
| 39 | 41 | { |
| 40 | 42 | 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; |
| 42 | 44 | 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; |
| 44 | 46 | 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; |
| 46 | 48 | case 0x05: // MTC |
| 47 | | return dmac.reg[channel].mtc; |
| 49 | return dmac->reg[channel].mtc; |
| 48 | 50 | case 0x06: // MAR (high) |
| 49 | | return (dmac.reg[channel].mar & 0xffff0000) >> 16; |
| 51 | return (dmac->reg[channel].mar & 0xffff0000) >> 16; |
| 50 | 52 | case 0x07: // MAR (low) |
| 51 | | return (dmac.reg[channel].mar & 0x0000ffff); |
| 53 | return (dmac->reg[channel].mar & 0x0000ffff); |
| 52 | 54 | case 0x0a: // DAR (high) |
| 53 | | return (dmac.reg[channel].dar & 0xffff0000) >> 16; |
| 55 | return (dmac->reg[channel].dar & 0xffff0000) >> 16; |
| 54 | 56 | case 0x0b: // DAR (low) |
| 55 | | return (dmac.reg[channel].dar & 0x0000ffff); |
| 57 | return (dmac->reg[channel].dar & 0x0000ffff); |
| 56 | 58 | case 0x0d: // BTC |
| 57 | | return dmac.reg[channel].btc; |
| 59 | return dmac->reg[channel].btc; |
| 58 | 60 | case 0x0e: // BAR (high) |
| 59 | | return (dmac.reg[channel].bar & 0xffff0000) >> 16; |
| 61 | return (dmac->reg[channel].bar & 0xffff0000) >> 16; |
| 60 | 62 | case 0x0f: // BAR (low) |
| 61 | | return (dmac.reg[channel].bar & 0x0000ffff); |
| 63 | return (dmac->reg[channel].bar & 0x0000ffff); |
| 62 | 64 | case 0x12: // NIV |
| 63 | | return dmac.reg[channel].niv; |
| 65 | return dmac->reg[channel].niv; |
| 64 | 66 | case 0x13: // EIV |
| 65 | | return dmac.reg[channel].eiv; |
| 67 | return dmac->reg[channel].eiv; |
| 66 | 68 | case 0x14: // MFC |
| 67 | | return dmac.reg[channel].mfc; |
| 69 | return dmac->reg[channel].mfc; |
| 68 | 70 | case 0x16: // CPR |
| 69 | | return dmac.reg[channel].cpr; |
| 71 | return dmac->reg[channel].cpr; |
| 70 | 72 | case 0x18: // DFC |
| 71 | | return dmac.reg[channel].dfc; |
| 73 | return dmac->reg[channel].dfc; |
| 72 | 74 | case 0x1c: // BFC |
| 73 | | return dmac.reg[channel].bfc; |
| 75 | return dmac->reg[channel].bfc; |
| 74 | 76 | case 0x1f: // GCR |
| 75 | | return dmac.reg[channel].gcr; |
| 77 | return dmac->reg[channel].gcr; |
| 76 | 78 | } |
| 77 | 79 | return 0xff; |
| 78 | 80 | } |
| 79 | 81 | |
| 80 | | void hd63450_write(running_machine *machine, int offset, int data, UINT16 mem_mask) |
| 82 | void hd63450_write(const device_config* device, int offset, int data, UINT16 mem_mask) |
| 81 | 83 | { |
| 82 | 84 | int channel,reg; |
| 83 | 85 | |
| 86 | hd63450_t* dmac = device->token; |
| 87 | |
| 84 | 88 | channel = (offset & 0x60) >> 5; |
| 85 | 89 | reg = offset & 0x1f; |
| 86 | 90 | switch(reg) |
| r2505 | r2506 | |
| 88 | 92 | case 0x00: // CSR / CER |
| 89 | 93 | if(ACCESSING_BITS_8_15) |
| 90 | 94 | { |
| 91 | | // dmac.reg[channel].csr = (data & 0xff00) >> 8; |
| 95 | // dmac->reg[channel].csr = (data & 0xff00) >> 8; |
| 92 | 96 | // logerror("DMA#%i: Channel status write : %02x\n",channel,dmac.reg[channel].csr); |
| 93 | 97 | } |
| 94 | 98 | // CER is read-only, so no action needed there. |
| r2505 | r2506 | |
| 96 | 100 | case 0x02: // DCR / OCR |
| 97 | 101 | if(ACCESSING_BITS_8_15) |
| 98 | 102 | { |
| 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); |
| 101 | 105 | } |
| 102 | 106 | if(ACCESSING_BITS_0_7) |
| 103 | 107 | { |
| 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); |
| 106 | 110 | } |
| 107 | 111 | break; |
| 108 | 112 | case 0x03: // SCR / CCR |
| 109 | 113 | if(ACCESSING_BITS_8_15) |
| 110 | 114 | { |
| 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); |
| 113 | 117 | } |
| 114 | 118 | if(ACCESSING_BITS_0_7) |
| 115 | 119 | { |
| 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); |
| 119 | 123 | if(data & 0x0010) // software abort |
| 120 | | dma_transfer_abort(channel); |
| 124 | dma_transfer_abort(device,channel); |
| 121 | 125 | if(data & 0x0020) // halt operation |
| 122 | | dma_transfer_halt(channel); |
| 126 | dma_transfer_halt(device,channel); |
| 123 | 127 | 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); |
| 126 | 130 | } |
| 127 | 131 | break; |
| 128 | 132 | 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); |
| 131 | 135 | break; |
| 132 | 136 | 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); |
| 135 | 139 | break; |
| 136 | 140 | 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); |
| 139 | 143 | break; |
| 140 | 144 | 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); |
| 143 | 147 | break; |
| 144 | 148 | 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); |
| 147 | 151 | break; |
| 148 | 152 | 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); |
| 151 | 155 | break; |
| 152 | 156 | 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); |
| 155 | 159 | break; |
| 156 | 160 | 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); |
| 159 | 163 | break; |
| 160 | 164 | 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); |
| 163 | 167 | break; |
| 164 | 168 | 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); |
| 167 | 171 | break; |
| 168 | 172 | 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); |
| 171 | 175 | break; |
| 172 | 176 | 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); |
| 175 | 179 | break; |
| 176 | 180 | 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); |
| 179 | 183 | break; |
| 180 | 184 | 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); |
| 183 | 187 | break; |
| 184 | 188 | 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); |
| 187 | 191 | break; |
| 188 | 192 | } |
| 189 | 193 | } |
| 190 | 194 | |
| 191 | | void dma_transfer_start(running_machine *machine, int channel, int dir) |
| 195 | void dma_transfer_start(const device_config* device, int channel, int dir) |
| 192 | 196 | { |
| 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) |
| 198 | 203 | { |
| 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--; |
| 203 | 208 | } |
| 204 | 209 | |
| 205 | 210 | // 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 |
| 207 | 212 | { |
| 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]); |
| 210 | 215 | } |
| 211 | 216 | 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]); |
| 213 | 218 | |
| 214 | 219 | |
| 215 | | dmac.transfer_size[channel] = dmac.reg[channel].mtc; |
| 220 | dmac->transfer_size[channel] = dmac->reg[channel].mtc; |
| 216 | 221 | |
| 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]); |
| 218 | 223 | } |
| 219 | 224 | |
| 220 | 225 | static TIMER_CALLBACK(dma_transfer_timer) |
| 221 | 226 | { |
| 222 | | hd63450_single_transfer(machine, param); |
| 227 | hd63450_single_transfer(ptr, param); |
| 223 | 228 | } |
| 224 | 229 | |
| 225 | | static void dma_transfer_abort(int channel) |
| 230 | static void dma_transfer_abort(const device_config* device, int channel) |
| 226 | 231 | { |
| 232 | hd63450_t* dmac = device->token; |
| 233 | |
| 227 | 234 | 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 |
| 233 | 240 | } |
| 234 | 241 | |
| 235 | | static void dma_transfer_halt(int channel) |
| 242 | static void dma_transfer_halt(const device_config* device, int channel) |
| 236 | 243 | { |
| 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); |
| 239 | 248 | } |
| 240 | 249 | |
| 241 | | static void dma_transfer_continue(int channel) |
| 250 | static void dma_transfer_continue(const device_config* device, int channel) |
| 242 | 251 | { |
| 243 | | if(dmac.halted[channel] != 0) |
| 252 | hd63450_t* dmac = device->token; |
| 253 | |
| 254 | if(dmac->halted[channel] != 0) |
| 244 | 255 | { |
| 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]); |
| 247 | 258 | } |
| 248 | 259 | } |
| 249 | 260 | |
| 250 | | void hd63450_single_transfer(running_machine *machine, int x) |
| 261 | void hd63450_single_transfer(const device_config* device, int x) |
| 251 | 262 | { |
| 252 | 263 | int data; |
| 253 | 264 | int datasize = 1; |
| 265 | hd63450_t* dmac = device->token; |
| 254 | 266 | |
| 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 |
| 256 | 268 | { |
| 257 | | if(dmac.reg[x].ocr & 0x80) // direction: 1 = device -> memory |
| 269 | if(dmac->reg[x].ocr & 0x80) // direction: 1 = device -> memory |
| 258 | 270 | { |
| 259 | | if(dmac.intf->dma_read[x]) |
| 271 | if(dmac->intf->dma_read[x]) |
| 260 | 272 | { |
| 261 | | data = dmac.intf->dma_read[x](dmac.reg[x].mar); |
| 273 | data = dmac->intf->dma_read[x](dmac->reg[x].mar); |
| 262 | 274 | if(data == -1) |
| 263 | 275 | return; // not ready to recieve data |
| 264 | | program_write_byte(dmac.reg[x].mar,data); |
| 276 | program_write_byte(dmac->reg[x].mar,data); |
| 265 | 277 | datasize = 1; |
| 266 | 278 | } |
| 267 | 279 | else |
| 268 | 280 | { |
| 269 | | switch(dmac.reg[x].ocr & 0x30) // operation size |
| 281 | switch(dmac->reg[x].ocr & 0x30) // operation size |
| 270 | 282 | { |
| 271 | 283 | 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 |
| 274 | 286 | datasize = 1; |
| 275 | 287 | break; |
| 276 | 288 | 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 |
| 279 | 291 | datasize = 2; |
| 280 | 292 | break; |
| 281 | 293 | 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); |
| 286 | 298 | datasize = 4; |
| 287 | 299 | break; |
| 288 | 300 | 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 |
| 291 | 303 | datasize = 1; |
| 292 | 304 | break; |
| 293 | 305 | } |
| r2505 | r2506 | |
| 296 | 308 | } |
| 297 | 309 | else // memory -> device |
| 298 | 310 | { |
| 299 | | if(dmac.intf->dma_write[x]) |
| 311 | if(dmac->intf->dma_write[x]) |
| 300 | 312 | { |
| 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); |
| 303 | 315 | datasize = 1; |
| 304 | 316 | } |
| 305 | 317 | else |
| 306 | 318 | { |
| 307 | | switch(dmac.reg[x].ocr & 0x30) // operation size |
| 319 | switch(dmac->reg[x].ocr & 0x30) // operation size |
| 308 | 320 | { |
| 309 | 321 | 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 |
| 312 | 324 | datasize = 1; |
| 313 | 325 | break; |
| 314 | 326 | 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 |
| 317 | 329 | datasize = 2; |
| 318 | 330 | break; |
| 319 | 331 | 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 |
| 324 | 336 | datasize = 4; |
| 325 | 337 | break; |
| 326 | 338 | 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 |
| 329 | 341 | datasize = 1; |
| 330 | 342 | break; |
| 331 | 343 | } |
| 332 | 344 | } |
| 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); |
| 334 | 346 | } |
| 335 | 347 | |
| 336 | 348 | |
| 337 | 349 | // 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--; |
| 340 | 352 | |
| 341 | 353 | // 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; |
| 346 | 358 | |
| 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; |
| 351 | 363 | |
| 352 | | if(dmac.reg[x].mtc <= 0) |
| 364 | if(dmac->reg[x].mtc <= 0) |
| 353 | 365 | { |
| 354 | 366 | // End of transfer |
| 355 | 367 | logerror("DMA#%i: End of transfer\n",x); |
| 356 | | if(dmac.reg[x].btc > 0) |
| 368 | if(dmac->reg[x].btc > 0) |
| 357 | 369 | { |
| 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); |
| 363 | 375 | return; |
| 364 | 376 | } |
| 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); |
| 372 | 384 | |
| 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); |
| 375 | 387 | } |
| 376 | 388 | } |
| 377 | 389 | } |
| 378 | 390 | |
| 379 | | int hd63450_get_vector(int channel) |
| 391 | int hd63450_get_vector(const device_config* device, int channel) |
| 380 | 392 | { |
| 381 | | return dmac.reg[channel].niv; |
| 393 | hd63450_t* dmac = device->token; |
| 394 | return dmac->reg[channel].niv; |
| 382 | 395 | } |
| 383 | 396 | |
| 384 | | int hd63450_get_error_vector(int channel) |
| 397 | int hd63450_get_error_vector(const device_config* device, int channel) |
| 385 | 398 | { |
| 386 | | return dmac.reg[channel].eiv; |
| 399 | hd63450_t* dmac = device->token; |
| 400 | return dmac->reg[channel].eiv; |
| 387 | 401 | } |
| 388 | 402 | |
| 403 | static DEVICE_SET_INFO( hd63450 ) |
| 404 | { |
| 405 | switch (state) |
| 406 | { |
| 407 | /* no parameters to set */ |
| 408 | } |
| 409 | } |
| 389 | 410 | |
| 390 | | READ16_HANDLER(hd63450_r) { return hd63450_read(machine,offset,mem_mask); } |
| 391 | | WRITE16_HANDLER(hd63450_w) { hd63450_write(machine,offset,data,mem_mask); } |
| 411 | DEVICE_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; |
| 392 | 418 | |
| 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 | |
| 434 | READ16_DEVICE_HANDLER(hd63450_r) { return hd63450_read(device,offset,mem_mask); } |
| 435 | WRITE16_DEVICE_HANDLER(hd63450_w) { hd63450_write(device,offset,data,mem_mask); } |
| 436 | |