src/mess/machine/x68k_hdc.c
| r14698 | r14699 | |
| 19 | 19 | #include "imagedev/harddriv.h" |
| 20 | 20 | #include "image.h" |
| 21 | 21 | |
| 22 | | static TIMER_CALLBACK( req_delay ) |
| 23 | | { |
| 24 | | sasi_ctrl_t* sasi = (sasi_ctrl_t*)ptr; |
| 25 | | sasi->req = 1; |
| 26 | | sasi->status_port |= 0x01; |
| 27 | | } |
| 22 | const device_type X68KHDC = &device_creator<x68k_hdc_image_device>; |
| 28 | 23 | |
| 29 | | static unsigned char SASIReadByte(device_t* device) |
| 24 | x68k_hdc_image_device::x68k_hdc_image_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 25 | : device_t(mconfig, X68KHDC, "SASI Hard Disk", tag, owner, clock), |
| 26 | device_image_interface(mconfig, *this) |
| 30 | 27 | { |
| 31 | | device_image_interface *image = dynamic_cast<device_image_interface *>(device); |
| 32 | | //int ret; |
| 33 | | unsigned char val; |
| 34 | | |
| 35 | | /*ret = */image->fread(&val,1); |
| 36 | | |
| 37 | | return val; |
| 38 | 28 | } |
| 39 | 29 | |
| 40 | | static void SASIWriteByte(device_t* device, unsigned char val) |
| 41 | | { |
| 42 | | device_image_interface *image = dynamic_cast<device_image_interface *>(device); |
| 43 | | image->fwrite(&val,1); |
| 30 | void x68k_hdc_image_device::device_config_complete() |
| 31 | { |
| 32 | update_names(X68KHDC, "sasihd", "sasi"); |
| 44 | 33 | } |
| 45 | 34 | |
| 46 | | INLINE sasi_ctrl_t *get_safe_token(device_t *device) |
| 47 | | { |
| 48 | | assert(device != NULL); |
| 49 | | assert(device->type() == X68KHDC); |
| 50 | | |
| 51 | | return (sasi_ctrl_t *)downcast<legacy_device_base *>(device)->token(); |
| 35 | void x68k_hdc_image_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 36 | { |
| 37 | m_req = 1; |
| 38 | m_status_port |= 0x01; |
| 52 | 39 | } |
| 53 | 40 | |
| 54 | | DEVICE_START( x68k_hdc ) |
| 41 | void x68k_hdc_image_device::device_start() |
| 55 | 42 | { |
| 56 | | sasi_ctrl_t* sasi = get_safe_token(device); |
| 57 | | |
| 58 | | sasi->status = 0x00; |
| 59 | | sasi->status_port = 0x00; |
| 60 | | sasi->phase = SASI_PHASE_BUSFREE; |
| 43 | m_status = 0x00; |
| 44 | m_status_port = 0x00; |
| 45 | m_phase = SASI_PHASE_BUSFREE; |
| 61 | 46 | } |
| 62 | 47 | |
| 63 | | DEVICE_IMAGE_CREATE( sasihd ) |
| 48 | bool x68k_hdc_image_device::call_create(int format_type, option_resolution *format_options) |
| 64 | 49 | { |
| 65 | 50 | // create 20MB HD |
| 66 | 51 | int x; |
| r14698 | r14699 | |
| 70 | 55 | memset(sectordata,0,sizeof(sectordata)); |
| 71 | 56 | for(x=0;x<0x013c98;x++) // 0x13c98 = number of blocks on a 20MB HD |
| 72 | 57 | { |
| 73 | | ret = image.fwrite(sectordata,256); |
| 58 | ret = fwrite(sectordata,256); |
| 74 | 59 | if(ret < 256) |
| 75 | 60 | return IMAGE_INIT_FAIL; |
| 76 | 61 | } |
| r14698 | r14699 | |
| 78 | 63 | return IMAGE_INIT_PASS; |
| 79 | 64 | } |
| 80 | 65 | |
| 81 | | WRITE16_DEVICE_HANDLER( x68k_hdc_w ) |
| 66 | WRITE16_MEMBER( x68k_hdc_image_device::hdc_w ) |
| 82 | 67 | { |
| 83 | | sasi_ctrl_t* sasi = get_safe_token(device); |
| 84 | 68 | unsigned int lba = 0; |
| 85 | 69 | char* blk; |
| 86 | | device_image_interface *image = dynamic_cast<device_image_interface *>(device); |
| 87 | 70 | switch(offset) |
| 88 | 71 | { |
| 89 | 72 | case 0x00: // data I/O |
| 90 | | if(sasi->phase == SASI_PHASE_WRITE) |
| 73 | if(m_phase == SASI_PHASE_WRITE) |
| 91 | 74 | { |
| 92 | | if(sasi->transfer_byte_count == 0) |
| 75 | if(m_transfer_byte_count == 0) |
| 93 | 76 | { |
| 94 | | switch(sasi->command[0]) |
| 77 | switch(m_command[0]) |
| 95 | 78 | { |
| 96 | 79 | case SASI_CMD_SPECIFY: |
| 97 | | sasi->transfer_byte_total = 10; |
| 80 | m_transfer_byte_total = 10; |
| 98 | 81 | break; |
| 99 | 82 | case SASI_CMD_WRITE: |
| 100 | | sasi->transfer_byte_total = (0x100 * sasi->command[4]); |
| 83 | m_transfer_byte_total = (0x100 * m_command[4]); |
| 101 | 84 | break; |
| 102 | 85 | default: |
| 103 | | sasi->transfer_byte_total = 0x100; |
| 86 | m_transfer_byte_total = 0x100; |
| 104 | 87 | } |
| 105 | 88 | } |
| 106 | 89 | |
| 107 | | if(sasi->command[0] == SASI_CMD_SPECIFY) |
| 90 | if(m_command[0] == SASI_CMD_SPECIFY) |
| 108 | 91 | { |
| 109 | 92 | logerror("SPECIFY: wrote 0x%02x\n",data); |
| 110 | 93 | } |
| 111 | 94 | |
| 112 | | if(sasi->command[0] == SASI_CMD_WRITE) |
| 95 | if(m_command[0] == SASI_CMD_WRITE) |
| 113 | 96 | { |
| 114 | | if(!image->exists()) |
| 97 | if(!exists()) |
| 115 | 98 | { |
| 116 | | sasi->phase = SASI_PHASE_STATUS; |
| 117 | | sasi->io = 1; // Output |
| 118 | | sasi->status_port |= 0x04; // C/D remains the same |
| 119 | | sasi->status = 0x02; |
| 99 | m_phase = SASI_PHASE_STATUS; |
| 100 | m_io = 1; // Output |
| 101 | m_status_port |= 0x04; // C/D remains the same |
| 102 | m_status = 0x02; |
| 120 | 103 | logerror("SASI: No HD connected.\n"); |
| 121 | 104 | } |
| 122 | 105 | else |
| 123 | 106 | { |
| 124 | | SASIWriteByte(device,data); |
| 107 | fwrite(&data,1); |
| 125 | 108 | } |
| 126 | 109 | } |
| 127 | 110 | |
| 128 | | sasi->req = 0; |
| 129 | | sasi->status_port &= ~0x01; |
| 130 | | device->machine().scheduler().timer_set(attotime::from_nsec(450), FUNC(req_delay), 0, sasi); |
| 131 | | sasi->transfer_byte_count++; |
| 132 | | if(sasi->transfer_byte_count >= sasi->transfer_byte_total) |
| 111 | m_req = 0; |
| 112 | m_status_port &= ~0x01; |
| 113 | timer_set(attotime::from_nsec(450)); |
| 114 | m_transfer_byte_count++; |
| 115 | if(m_transfer_byte_count >= m_transfer_byte_total) |
| 133 | 116 | { |
| 134 | 117 | // End of transfer |
| 135 | | sasi->phase = SASI_PHASE_STATUS; |
| 136 | | sasi->io = 1; |
| 137 | | sasi->status_port |= 0x04; |
| 138 | | sasi->cd = 1; |
| 139 | | sasi->status_port |= 0x08; |
| 118 | m_phase = SASI_PHASE_STATUS; |
| 119 | m_io = 1; |
| 120 | m_status_port |= 0x04; |
| 121 | m_cd = 1; |
| 122 | m_status_port |= 0x08; |
| 140 | 123 | logerror("SASI: Write transfer complete\n"); |
| 141 | 124 | } |
| 142 | 125 | } |
| 143 | | if(sasi->phase == SASI_PHASE_COMMAND) |
| 126 | if(m_phase == SASI_PHASE_COMMAND) |
| 144 | 127 | { |
| 145 | | if(sasi->command_byte_count == 0) |
| 128 | if(m_command_byte_count == 0) |
| 146 | 129 | { |
| 147 | 130 | // first command byte |
| 148 | | sasi->current_command = data; |
| 131 | m_current_command = data; |
| 149 | 132 | switch(data >> 5) // high 3 bits determine command class, and therefore, length |
| 150 | 133 | { |
| 151 | 134 | case 0: |
| 152 | | sasi->command_byte_total = 6; |
| 135 | m_command_byte_total = 6; |
| 153 | 136 | break; |
| 154 | 137 | case 1: |
| 155 | | sasi->command_byte_total = 10; |
| 138 | m_command_byte_total = 10; |
| 156 | 139 | break; |
| 157 | 140 | case 2: |
| 158 | | sasi->command_byte_total = 8; |
| 141 | m_command_byte_total = 8; |
| 159 | 142 | break; |
| 160 | 143 | default: |
| 161 | | sasi->command_byte_total = 6; |
| 144 | m_command_byte_total = 6; |
| 162 | 145 | } |
| 163 | 146 | } |
| 164 | | sasi->command[sasi->command_byte_count] = data; |
| 147 | m_command[m_command_byte_count] = data; |
| 165 | 148 | // reset REQ temporarily |
| 166 | | sasi->req = 0; |
| 167 | | sasi->status_port &= ~0x01; |
| 168 | | device->machine().scheduler().timer_set(attotime::from_nsec(450), FUNC(req_delay), 0, sasi); |
| 149 | m_req = 0; |
| 150 | m_status_port &= ~0x01; |
| 151 | timer_set(attotime::from_nsec(450)); |
| 169 | 152 | |
| 170 | | sasi->command_byte_count++; |
| 171 | | if(sasi->command_byte_count >= sasi->command_byte_total) |
| 153 | m_command_byte_count++; |
| 154 | if(m_command_byte_count >= m_command_byte_total) |
| 172 | 155 | { |
| 173 | 156 | // End of command |
| 174 | 157 | |
| 175 | | switch(sasi->command[0]) |
| 158 | switch(m_command[0]) |
| 176 | 159 | { |
| 177 | 160 | case SASI_CMD_REZERO_UNIT: |
| 178 | | sasi->phase = SASI_PHASE_STATUS; |
| 179 | | sasi->io = 1; // Output |
| 180 | | sasi->status_port |= 0x04; // C/D remains the same |
| 161 | m_phase = SASI_PHASE_STATUS; |
| 162 | m_io = 1; // Output |
| 163 | m_status_port |= 0x04; // C/D remains the same |
| 181 | 164 | logerror("SASI: REZERO UNIT\n"); |
| 182 | 165 | break; |
| 183 | 166 | case SASI_CMD_REQUEST_SENSE: |
| 184 | | sasi->phase = SASI_PHASE_READ; |
| 185 | | sasi->io = 1; |
| 186 | | sasi->status_port |= 0x04; |
| 187 | | sasi->cd = 0; |
| 188 | | sasi->status_port &= ~0x08; |
| 189 | | sasi->transfer_byte_count = 0; |
| 190 | | sasi->transfer_byte_total = 0; |
| 167 | m_phase = SASI_PHASE_READ; |
| 168 | m_io = 1; |
| 169 | m_status_port |= 0x04; |
| 170 | m_cd = 0; |
| 171 | m_status_port &= ~0x08; |
| 172 | m_transfer_byte_count = 0; |
| 173 | m_transfer_byte_total = 0; |
| 191 | 174 | logerror("SASI: REQUEST SENSE\n"); |
| 192 | 175 | break; |
| 193 | 176 | case SASI_CMD_SPECIFY: |
| 194 | | sasi->phase = SASI_PHASE_WRITE; |
| 195 | | sasi->io = 0; |
| 196 | | sasi->status_port &= ~0x04; |
| 197 | | sasi->cd = 0; // Data |
| 198 | | sasi->status_port &= ~0x08; |
| 199 | | sasi->transfer_byte_count = 0; |
| 200 | | sasi->transfer_byte_total = 0; |
| 177 | m_phase = SASI_PHASE_WRITE; |
| 178 | m_io = 0; |
| 179 | m_status_port &= ~0x04; |
| 180 | m_cd = 0; // Data |
| 181 | m_status_port &= ~0x08; |
| 182 | m_transfer_byte_count = 0; |
| 183 | m_transfer_byte_total = 0; |
| 201 | 184 | logerror("SASI: SPECIFY\n"); |
| 202 | 185 | break; |
| 203 | 186 | case SASI_CMD_READ: |
| 204 | | if(!image->exists()) |
| 187 | if(!exists()) |
| 205 | 188 | { |
| 206 | | sasi->phase = SASI_PHASE_STATUS; |
| 207 | | sasi->io = 1; // Output |
| 208 | | sasi->status_port |= 0x04; // C/D remains the same |
| 209 | | sasi->cd = 1; |
| 210 | | sasi->status_port |= 0x08; |
| 211 | | sasi->status = 0x02; |
| 189 | m_phase = SASI_PHASE_STATUS; |
| 190 | m_io = 1; // Output |
| 191 | m_status_port |= 0x04; // C/D remains the same |
| 192 | m_cd = 1; |
| 193 | m_status_port |= 0x08; |
| 194 | m_status = 0x02; |
| 212 | 195 | logerror("SASI: No HD connected\n"); |
| 213 | 196 | } |
| 214 | 197 | else |
| 215 | 198 | { |
| 216 | | sasi->phase = SASI_PHASE_READ; |
| 217 | | sasi->io = 1; |
| 218 | | sasi->status_port |= 0x04; |
| 219 | | sasi->cd = 0; |
| 220 | | sasi->status_port &= ~0x08; |
| 221 | | sasi->transfer_byte_count = 0; |
| 222 | | sasi->transfer_byte_total = 0; |
| 223 | | lba = sasi->command[3]; |
| 224 | | lba |= sasi->command[2] << 8; |
| 225 | | lba |= (sasi->command[1] & 0x1f) << 16; |
| 226 | | image->fseek(lba * 256,SEEK_SET); |
| 227 | | logerror("SASI: READ (LBA 0x%06x, blocks = %i)\n",lba,sasi->command[4]); |
| 199 | m_phase = SASI_PHASE_READ; |
| 200 | m_io = 1; |
| 201 | m_status_port |= 0x04; |
| 202 | m_cd = 0; |
| 203 | m_status_port &= ~0x08; |
| 204 | m_transfer_byte_count = 0; |
| 205 | m_transfer_byte_total = 0; |
| 206 | lba = m_command[3]; |
| 207 | lba |= m_command[2] << 8; |
| 208 | lba |= (m_command[1] & 0x1f) << 16; |
| 209 | fseek(lba * 256,SEEK_SET); |
| 210 | logerror("SASI: READ (LBA 0x%06x, blocks = %i)\n",lba,m_command[4]); |
| 228 | 211 | } |
| 229 | 212 | break; |
| 230 | 213 | case SASI_CMD_WRITE: |
| 231 | | if(!image->exists()) |
| 214 | if(!exists()) |
| 232 | 215 | { |
| 233 | | sasi->phase = SASI_PHASE_STATUS; |
| 234 | | sasi->io = 1; // Output |
| 235 | | sasi->status_port |= 0x04; // C/D remains the same |
| 236 | | sasi->cd = 1; |
| 237 | | sasi->status_port |= 0x08; |
| 238 | | sasi->status = 0x02; |
| 216 | m_phase = SASI_PHASE_STATUS; |
| 217 | m_io = 1; // Output |
| 218 | m_status_port |= 0x04; // C/D remains the same |
| 219 | m_cd = 1; |
| 220 | m_status_port |= 0x08; |
| 221 | m_status = 0x02; |
| 239 | 222 | logerror("SASI: No HD connected\n"); |
| 240 | 223 | } |
| 241 | 224 | else |
| 242 | 225 | { |
| 243 | | sasi->phase = SASI_PHASE_WRITE; |
| 244 | | sasi->io = 0; |
| 245 | | sasi->status_port &= ~0x04; |
| 246 | | sasi->cd = 0; |
| 247 | | sasi->status_port &= ~0x08; |
| 248 | | sasi->transfer_byte_count = 0; |
| 249 | | sasi->transfer_byte_total = 0; |
| 250 | | lba = sasi->command[3]; |
| 251 | | lba |= sasi->command[2] << 8; |
| 252 | | lba |= (sasi->command[1] & 0x1f) << 16; |
| 253 | | image->fseek(lba * 256,SEEK_SET); |
| 254 | | logerror("SASI: WRITE (LBA 0x%06x, blocks = %i)\n",lba,sasi->command[4]); |
| 226 | m_phase = SASI_PHASE_WRITE; |
| 227 | m_io = 0; |
| 228 | m_status_port &= ~0x04; |
| 229 | m_cd = 0; |
| 230 | m_status_port &= ~0x08; |
| 231 | m_transfer_byte_count = 0; |
| 232 | m_transfer_byte_total = 0; |
| 233 | lba = m_command[3]; |
| 234 | lba |= m_command[2] << 8; |
| 235 | lba |= (m_command[1] & 0x1f) << 16; |
| 236 | fseek(lba * 256,SEEK_SET); |
| 237 | logerror("SASI: WRITE (LBA 0x%06x, blocks = %i)\n",lba,m_command[4]); |
| 255 | 238 | } |
| 256 | 239 | break; |
| 257 | 240 | case SASI_CMD_SEEK: |
| 258 | | sasi->phase = SASI_PHASE_STATUS; |
| 259 | | sasi->io = 1; // Output |
| 260 | | sasi->status_port |= 0x04; // C/D remains the same |
| 261 | | sasi->cd = 1; |
| 262 | | sasi->status_port |= 0x08; |
| 241 | m_phase = SASI_PHASE_STATUS; |
| 242 | m_io = 1; // Output |
| 243 | m_status_port |= 0x04; // C/D remains the same |
| 244 | m_cd = 1; |
| 245 | m_status_port |= 0x08; |
| 263 | 246 | logerror("SASI: SEEK (LBA 0x%06x)\n",lba); |
| 264 | 247 | break; |
| 265 | 248 | case SASI_CMD_FORMAT_UNIT: |
| r14698 | r14699 | |
| 273 | 256 | 4 | ?? (usually 0x01) |
| 274 | 257 | 5 | ?? |
| 275 | 258 | */ |
| 276 | | sasi->phase = SASI_PHASE_STATUS; |
| 277 | | sasi->io = 1; // Output |
| 278 | | sasi->status_port |= 0x04; // C/D remains the same |
| 279 | | sasi->cd = 1; |
| 280 | | sasi->status_port |= 0x08; |
| 281 | | lba = sasi->command[3]; |
| 282 | | lba |= sasi->command[2] << 8; |
| 283 | | lba |= (sasi->command[1] & 0x1f) << 16; |
| 284 | | image->fseek(lba * 256,SEEK_SET); |
| 259 | m_phase = SASI_PHASE_STATUS; |
| 260 | m_io = 1; // Output |
| 261 | m_status_port |= 0x04; // C/D remains the same |
| 262 | m_cd = 1; |
| 263 | m_status_port |= 0x08; |
| 264 | lba = m_command[3]; |
| 265 | lba |= m_command[2] << 8; |
| 266 | lba |= (m_command[1] & 0x1f) << 16; |
| 267 | fseek(lba * 256,SEEK_SET); |
| 285 | 268 | blk = (char*)malloc(256*33); |
| 286 | 269 | memset(blk,0,256*33); |
| 287 | 270 | // formats 33 256-byte blocks |
| 288 | | image->fwrite(blk,256*33); |
| 271 | fwrite(blk,256*33); |
| 289 | 272 | free(blk); |
| 290 | 273 | logerror("SASI: FORMAT UNIT (LBA 0x%06x)\n",lba); |
| 291 | 274 | break; |
| 292 | 275 | default: |
| 293 | | sasi->phase = SASI_PHASE_STATUS; |
| 294 | | sasi->io = 1; // Output |
| 295 | | sasi->status_port |= 0x04; // C/D remains the same |
| 296 | | sasi->status = 0x02; |
| 297 | | logerror("SASI: Invalid or unimplemented SASI command (0x%02x) received.\n",sasi->command[0]); |
| 276 | m_phase = SASI_PHASE_STATUS; |
| 277 | m_io = 1; // Output |
| 278 | m_status_port |= 0x04; // C/D remains the same |
| 279 | m_status = 0x02; |
| 280 | logerror("SASI: Invalid or unimplemented SASI command (0x%02x) received.\n",m_command[0]); |
| 298 | 281 | } |
| 299 | 282 | } |
| 300 | 283 | } |
| r14698 | r14699 | |
| 302 | 285 | case 0x01: |
| 303 | 286 | if(data == 0) |
| 304 | 287 | { |
| 305 | | if(sasi->phase == SASI_PHASE_SELECTION) |
| 288 | if(m_phase == SASI_PHASE_SELECTION) |
| 306 | 289 | { |
| 307 | 290 | // Go to Command phase |
| 308 | | sasi->phase = SASI_PHASE_COMMAND; |
| 309 | | sasi->cd = 1; // data port expects a command or status |
| 310 | | sasi->status_port |= 0x08; |
| 311 | | sasi->command_byte_count = 0; |
| 312 | | sasi->command_byte_total = 0; |
| 313 | | device->machine().scheduler().timer_set(attotime::from_nsec(45), FUNC(req_delay), 0, sasi); |
| 291 | m_phase = SASI_PHASE_COMMAND; |
| 292 | m_cd = 1; // data port expects a command or status |
| 293 | m_status_port |= 0x08; |
| 294 | m_command_byte_count = 0; |
| 295 | m_command_byte_total = 0; |
| 296 | timer_set(attotime::from_nsec(45)); |
| 314 | 297 | } |
| 315 | 298 | } |
| 316 | 299 | break; |
| r14698 | r14699 | |
| 319 | 302 | case 0x03: |
| 320 | 303 | if(data != 0) |
| 321 | 304 | { |
| 322 | | if(sasi->phase == SASI_PHASE_BUSFREE) |
| 305 | if(m_phase == SASI_PHASE_BUSFREE) |
| 323 | 306 | { |
| 324 | 307 | // Go to Selection phase |
| 325 | | sasi->phase = SASI_PHASE_SELECTION; |
| 326 | | sasi->bsy = 1; // HDC is now busy |
| 327 | | sasi->status_port |= 0x02; |
| 308 | m_phase = SASI_PHASE_SELECTION; |
| 309 | m_bsy = 1; // HDC is now busy |
| 310 | m_status_port |= 0x02; |
| 328 | 311 | } |
| 329 | 312 | } |
| 330 | 313 | break; |
| r14698 | r14699 | |
| 333 | 316 | // logerror("SASI: write to HDC, offset %04x, data %04x\n",offset,data); |
| 334 | 317 | } |
| 335 | 318 | |
| 336 | | READ16_DEVICE_HANDLER( x68k_hdc_r ) |
| 337 | | { |
| 338 | | sasi_ctrl_t* sasi = get_safe_token(device); |
| 339 | | device_image_interface *image = dynamic_cast<device_image_interface *>(device); |
| 319 | READ16_MEMBER( x68k_hdc_image_device::hdc_r ) |
| 320 | { |
| 340 | 321 | int retval = 0xff; |
| 341 | 322 | |
| 342 | 323 | switch(offset) |
| 343 | 324 | { |
| 344 | 325 | case 0x00: |
| 345 | | if(sasi->phase == SASI_PHASE_MESSAGE) |
| 326 | if(m_phase == SASI_PHASE_MESSAGE) |
| 346 | 327 | { |
| 347 | | sasi->phase = SASI_PHASE_BUSFREE; |
| 348 | | sasi->msg = 0; |
| 349 | | sasi->cd = 0; |
| 350 | | sasi->io = 0; |
| 351 | | sasi->bsy = 0; |
| 352 | | sasi->req = 0; |
| 353 | | sasi->status = 0; |
| 354 | | sasi->status_port = 0; // reset all status bits to 0 |
| 328 | m_phase = SASI_PHASE_BUSFREE; |
| 329 | m_msg = 0; |
| 330 | m_cd = 0; |
| 331 | m_io = 0; |
| 332 | m_bsy = 0; |
| 333 | m_req = 0; |
| 334 | m_status = 0; |
| 335 | m_status_port = 0; // reset all status bits to 0 |
| 355 | 336 | return 0x00; |
| 356 | 337 | } |
| 357 | | if(sasi->phase == SASI_PHASE_STATUS) |
| 338 | if(m_phase == SASI_PHASE_STATUS) |
| 358 | 339 | { |
| 359 | | sasi->phase = SASI_PHASE_MESSAGE; |
| 360 | | sasi->msg = 1; |
| 361 | | sasi->status_port |= 0x10; |
| 340 | m_phase = SASI_PHASE_MESSAGE; |
| 341 | m_msg = 1; |
| 342 | m_status_port |= 0x10; |
| 362 | 343 | // reset REQ temporarily |
| 363 | | sasi->req = 0; |
| 364 | | sasi->status_port &= ~0x01; |
| 365 | | device->machine().scheduler().timer_set(attotime::from_nsec(450), FUNC(req_delay), 0, sasi); |
| 344 | m_req = 0; |
| 345 | m_status_port &= ~0x01; |
| 346 | timer_set(attotime::from_nsec(450)); |
| 366 | 347 | |
| 367 | | return sasi->status; |
| 348 | return m_status; |
| 368 | 349 | } |
| 369 | | if(sasi->phase == SASI_PHASE_READ) |
| 350 | if(m_phase == SASI_PHASE_READ) |
| 370 | 351 | { |
| 371 | | if(sasi->transfer_byte_count == 0) |
| 352 | if(m_transfer_byte_count == 0) |
| 372 | 353 | { |
| 373 | | switch(sasi->command[0]) |
| 354 | switch(m_command[0]) |
| 374 | 355 | { |
| 375 | 356 | case SASI_CMD_REQUEST_SENSE: |
| 376 | 357 | // set up sense bytes |
| 377 | | sasi->sense[0] = 0x01; // "No index signal" |
| 378 | | sasi->sense[1] = 0; |
| 379 | | sasi->sense[2] = 0; |
| 380 | | sasi->sense[3] = 0; |
| 381 | | if(sasi->command[3] == 0) |
| 382 | | sasi->transfer_byte_total = 4; |
| 358 | m_sense[0] = 0x01; // "No index signal" |
| 359 | m_sense[1] = 0; |
| 360 | m_sense[2] = 0; |
| 361 | m_sense[3] = 0; |
| 362 | if(m_command[3] == 0) |
| 363 | m_transfer_byte_total = 4; |
| 383 | 364 | else |
| 384 | | sasi->transfer_byte_total = sasi->command[3]; |
| 365 | m_transfer_byte_total = m_command[3]; |
| 385 | 366 | break; |
| 386 | 367 | case SASI_CMD_READ: |
| 387 | | sasi->transfer_byte_total = (0x100 * sasi->command[4]); |
| 388 | | sasi->transfer_byte_count = 0; |
| 368 | m_transfer_byte_total = (0x100 * m_command[4]); |
| 369 | m_transfer_byte_count = 0; |
| 389 | 370 | break; |
| 390 | 371 | default: |
| 391 | | sasi->transfer_byte_total = 0; |
| 372 | m_transfer_byte_total = 0; |
| 392 | 373 | } |
| 393 | 374 | } |
| 394 | 375 | |
| 395 | | switch(sasi->command[0]) |
| 376 | switch(m_command[0]) |
| 396 | 377 | { |
| 397 | 378 | case SASI_CMD_REQUEST_SENSE: |
| 398 | | retval = sasi->sense[sasi->transfer_byte_count]; |
| 379 | retval = m_sense[m_transfer_byte_count]; |
| 399 | 380 | logerror("REQUEST SENSE: read value 0x%02x\n",retval); |
| 400 | 381 | break; |
| 401 | 382 | case SASI_CMD_READ: |
| 402 | | if(!image->exists()) |
| 383 | if(!exists()) |
| 403 | 384 | { |
| 404 | | sasi->phase = SASI_PHASE_STATUS; |
| 405 | | sasi->io = 1; // Output |
| 406 | | sasi->status_port |= 0x04; // C/D remains the same |
| 407 | | sasi->status = 0x02; |
| 385 | m_phase = SASI_PHASE_STATUS; |
| 386 | m_io = 1; // Output |
| 387 | m_status_port |= 0x04; // C/D remains the same |
| 388 | m_status = 0x02; |
| 408 | 389 | logerror("SASI: No HD connected.\n"); |
| 409 | 390 | } |
| 410 | 391 | else |
| 411 | 392 | { |
| 412 | | retval = SASIReadByte(device); |
| 393 | unsigned char val; |
| 394 | fread(&val,1); |
| 395 | retval = val; |
| 413 | 396 | } |
| 414 | 397 | break; |
| 415 | 398 | default: |
| 416 | 399 | retval = 0; |
| 417 | 400 | } |
| 418 | 401 | |
| 419 | | sasi->req = 0; |
| 420 | | sasi->status_port &= ~0x01; |
| 421 | | device->machine().scheduler().timer_set(attotime::from_nsec(450), FUNC(req_delay), 0, sasi); |
| 422 | | sasi->transfer_byte_count++; |
| 423 | | if(sasi->transfer_byte_count >= sasi->transfer_byte_total) |
| 402 | m_req = 0; |
| 403 | m_status_port &= ~0x01; |
| 404 | timer_set(attotime::from_nsec(450)); |
| 405 | m_transfer_byte_count++; |
| 406 | if(m_transfer_byte_count >= m_transfer_byte_total) |
| 424 | 407 | { |
| 425 | 408 | // End of transfer |
| 426 | | sasi->phase = SASI_PHASE_STATUS; |
| 427 | | sasi->io = 1; |
| 428 | | sasi->status_port |= 0x04; |
| 429 | | sasi->cd = 1; |
| 430 | | sasi->status_port |= 0x08; |
| 409 | m_phase = SASI_PHASE_STATUS; |
| 410 | m_io = 1; |
| 411 | m_status_port |= 0x04; |
| 412 | m_cd = 1; |
| 413 | m_status_port |= 0x08; |
| 431 | 414 | logerror("SASI: Read transfer complete\n"); |
| 432 | 415 | } |
| 433 | 416 | |
| r14698 | r14699 | |
| 435 | 418 | } |
| 436 | 419 | return 0x00; |
| 437 | 420 | case 0x01: |
| 438 | | // logerror("SASI: [%08x] read from status port, read 0x%02x\n",activecpu_get_pc(),sasi->status_port); |
| 439 | | return sasi->status_port; |
| 421 | // logerror("SASI: [%08x] read from status port, read 0x%02x\n",activecpu_get_pc(),m_status_port); |
| 422 | return m_status_port; |
| 440 | 423 | case 0x02: |
| 441 | 424 | return 0xff; // write-only |
| 442 | 425 | case 0x03: |
| r14698 | r14699 | |
| 445 | 428 | return 0xff; |
| 446 | 429 | } |
| 447 | 430 | } |
| 448 | | |
| 449 | | DEVICE_GET_INFO(x68k_hdc) |
| 450 | | { |
| 451 | | switch (state) |
| 452 | | { |
| 453 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 454 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(sasi_ctrl_t); break; |
| 455 | | case DEVINFO_INT_IMAGE_TYPE: info->i = IO_HARDDISK; break; |
| 456 | | case DEVINFO_INT_IMAGE_READABLE: info->i = 1; break; |
| 457 | | case DEVINFO_INT_IMAGE_WRITEABLE: info->i = 1; break; |
| 458 | | case DEVINFO_INT_IMAGE_CREATABLE: info->i = 1; break; |
| 459 | | |
| 460 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 461 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(x68k_hdc); break; |
| 462 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 463 | | case DEVINFO_FCT_RESET: /*info->reset = DEVICE_RESET_NAME(x68k_hdc);*/ break; |
| 464 | | case DEVINFO_FCT_IMAGE_CREATE: info->f = (genf *)DEVICE_IMAGE_CREATE_NAME(sasihd); break; |
| 465 | | |
| 466 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 467 | | case DEVINFO_STR_NAME: strcpy(info->s, "SASI Hard Disk"); break; |
| 468 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "SASI Hard Disk Controller"); break; |
| 469 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 470 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 471 | | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright the MESS Team"); break; |
| 472 | | case DEVINFO_STR_IMAGE_INSTANCE_NAME: strcpy(info->s, "sasihd"); break; |
| 473 | | case DEVINFO_STR_IMAGE_BRIEF_INSTANCE_NAME: strcpy(info->s, "sasi"); break; |
| 474 | | case DEVINFO_STR_IMAGE_FILE_EXTENSIONS: strcpy(info->s, "hdf"); break; |
| 475 | | } |
| 476 | | } |
| 477 | | |
| 478 | | DEFINE_LEGACY_IMAGE_DEVICE(X68KHDC, x68k_hdc); |