src/mess/machine/smartmed.c
| r5784 | r5785 | |
| 59 | 59 | header_len = sizeof(disk_image_header) |
| 60 | 60 | }; |
| 61 | 61 | |
| 62 | | static struct |
| 62 | typedef struct _smartmedia_t smartmedia_t; |
| 63 | struct _smartmedia_t |
| 63 | 64 | { |
| 64 | 65 | int page_data_size; // 256 for a 2MB card, 512 otherwise |
| 65 | 66 | int page_total_size;// 264 for a 2MB card, 528 otherwise |
| r5784 | r5785 | |
| 96 | 97 | UINT8 *pagereg; // page register used by program command |
| 97 | 98 | UINT8 id[2]; // chip ID |
| 98 | 99 | UINT8 mp_opcode; // multi-plane operation code |
| 99 | | } smartmedia[MAX_SMARTMEDIA]; |
| 100 | }; |
| 100 | 101 | |
| 102 | |
| 103 | INLINE smartmedia_t *get_safe_token(const device_config *device) |
| 104 | { |
| 105 | assert(device != NULL); |
| 106 | assert(device->token != NULL); |
| 107 | assert(device->type == SMARTMEDIA); |
| 108 | |
| 109 | return (smartmedia_t *)device->token; |
| 110 | } |
| 111 | |
| 112 | |
| 101 | 113 | /* |
| 102 | 114 | Init a SmartMedia image |
| 103 | 115 | */ |
| 104 | 116 | DEVICE_START( smartmedia ) |
| 105 | 117 | { |
| 106 | | int id = image_index_in_device(device); |
| 107 | | assert((id >= 0) && (id < MAX_SMARTMEDIA)); |
| 118 | smartmedia_t *sm = get_safe_token(device); |
| 108 | 119 | |
| 109 | | smartmedia[id].page_data_size = 0; |
| 110 | | smartmedia[id].page_total_size = 0; |
| 111 | | smartmedia[id].num_pages = 0; |
| 112 | | smartmedia[id].log2_pages_per_block = 0; |
| 113 | | smartmedia[id].data_ptr = NULL; |
| 114 | | smartmedia[id].mode = SM_M_INIT; |
| 115 | | smartmedia[id].pointer_mode = SM_PM_A; |
| 116 | | smartmedia[id].page_addr = 0; |
| 117 | | smartmedia[id].byte_addr = 0; |
| 118 | | smartmedia[id].status = 0x40; |
| 119 | | smartmedia[id].accumulated_status = 0; |
| 120 | | smartmedia[id].pagereg = NULL; |
| 121 | | smartmedia[id].id[0] = smartmedia[id].id[1] = 0; |
| 122 | | smartmedia[id].mp_opcode = 0; |
| 120 | sm->page_data_size = 0; |
| 121 | sm->page_total_size = 0; |
| 122 | sm->num_pages = 0; |
| 123 | sm->log2_pages_per_block = 0; |
| 124 | sm->data_ptr = NULL; |
| 125 | sm->mode = SM_M_INIT; |
| 126 | sm->pointer_mode = SM_PM_A; |
| 127 | sm->page_addr = 0; |
| 128 | sm->byte_addr = 0; |
| 129 | sm->status = 0x40; |
| 130 | sm->accumulated_status = 0; |
| 131 | sm->pagereg = NULL; |
| 132 | sm->id[0] = sm->id[1] = 0; |
| 133 | sm->mp_opcode = 0; |
| 123 | 134 | } |
| 124 | 135 | |
| 125 | 136 | /* |
| r5784 | r5785 | |
| 127 | 138 | */ |
| 128 | 139 | DEVICE_IMAGE_LOAD( smartmedia ) |
| 129 | 140 | { |
| 130 | | int id = image_index_in_device(image); |
| 141 | smartmedia_t *sm = get_safe_token(image); |
| 131 | 142 | disk_image_header custom_header; |
| 132 | 143 | int bytes_read; |
| 133 | 144 | |
| 134 | | if (id >= MAX_SMARTMEDIA) |
| 135 | | { |
| 136 | | logerror("smartmedia: invalid chip %d\n", id); |
| 137 | | return INIT_FAIL; |
| 138 | | } |
| 139 | 145 | |
| 140 | | /*if (device_load_mess_hd(image, file)) |
| 141 | | return INIT_FAIL;*/ |
| 142 | | |
| 143 | | //mess_hd_get_hard_disk_file(image) |
| 144 | | |
| 145 | 146 | bytes_read = image_fread(image, &custom_header, sizeof(custom_header)); |
| 146 | 147 | if (bytes_read != sizeof(custom_header)) |
| 147 | 148 | { |
| r5784 | r5785 | |
| 153 | 154 | return INIT_FAIL; |
| 154 | 155 | } |
| 155 | 156 | |
| 156 | | smartmedia[id].page_data_size = get_UINT32BE(custom_header.page_data_size); |
| 157 | | smartmedia[id].page_total_size = get_UINT32BE(custom_header.page_total_size); |
| 158 | | smartmedia[id].num_pages = get_UINT32BE(custom_header.num_pages); |
| 159 | | smartmedia[id].log2_pages_per_block = get_UINT32BE(custom_header.log2_pages_per_block); |
| 160 | | smartmedia[id].data_ptr = auto_alloc_array(image->machine, UINT8, smartmedia[id].page_total_size*smartmedia[id].num_pages); |
| 161 | | smartmedia[id].mode = SM_M_INIT; |
| 162 | | smartmedia[id].pointer_mode = SM_PM_A; |
| 163 | | smartmedia[id].page_addr = 0; |
| 164 | | smartmedia[id].byte_addr = 0; |
| 165 | | smartmedia[id].status = 0x40; |
| 157 | sm->page_data_size = get_UINT32BE(custom_header.page_data_size); |
| 158 | sm->page_total_size = get_UINT32BE(custom_header.page_total_size); |
| 159 | sm->num_pages = get_UINT32BE(custom_header.num_pages); |
| 160 | sm->log2_pages_per_block = get_UINT32BE(custom_header.log2_pages_per_block); |
| 161 | sm->data_ptr = auto_alloc_array(image->machine, UINT8, sm->page_total_size*sm->num_pages); |
| 162 | sm->mode = SM_M_INIT; |
| 163 | sm->pointer_mode = SM_PM_A; |
| 164 | sm->page_addr = 0; |
| 165 | sm->byte_addr = 0; |
| 166 | sm->status = 0x40; |
| 166 | 167 | if (!image_is_writable(image)) |
| 167 | | smartmedia[id].status |= 0x80; |
| 168 | | smartmedia[id].accumulated_status = 0; |
| 169 | | smartmedia[id].pagereg = auto_alloc_array(image->machine, UINT8, smartmedia[id].page_total_size); |
| 170 | | smartmedia[id].id[0] = smartmedia[id].id[1] = 0; |
| 168 | sm->status |= 0x80; |
| 169 | sm->accumulated_status = 0; |
| 170 | sm->pagereg = auto_alloc_array(image->machine, UINT8, sm->page_total_size); |
| 171 | sm->id[0] = sm->id[1] = 0; |
| 171 | 172 | |
| 172 | | image_fread(image, smartmedia[id].id, 2); |
| 173 | | image_fread(image, &smartmedia[id].mp_opcode, 1); |
| 174 | | image_fread(image, smartmedia[id].data_ptr, smartmedia[id].page_total_size*smartmedia[id].num_pages); |
| 173 | image_fread(image, sm->id, 2); |
| 174 | image_fread(image, &sm->mp_opcode, 1); |
| 175 | image_fread(image, sm->data_ptr, sm->page_total_size*sm->num_pages); |
| 175 | 176 | |
| 176 | 177 | return INIT_PASS; |
| 177 | 178 | } |
| r5784 | r5785 | |
| 181 | 182 | */ |
| 182 | 183 | DEVICE_IMAGE_UNLOAD( smartmedia ) |
| 183 | 184 | { |
| 184 | | int id = image_index_in_device(image); |
| 185 | smartmedia_t *sm = get_safe_token(image); |
| 185 | 186 | |
| 186 | | if (id >= MAX_SMARTMEDIA) |
| 187 | | { |
| 188 | | logerror("smartmedia: invalid chip %d\n", id); |
| 189 | | return; |
| 190 | | } |
| 187 | sm->page_data_size = 0; |
| 188 | sm->page_total_size = 0; |
| 189 | sm->num_pages = 0; |
| 190 | sm->log2_pages_per_block = 0; |
| 191 | sm->data_ptr = NULL; |
| 192 | sm->mode = SM_M_INIT; |
| 193 | sm->pointer_mode = SM_PM_A; |
| 194 | sm->page_addr = 0; |
| 195 | sm->byte_addr = 0; |
| 196 | sm->status = 0x40; |
| 197 | sm->accumulated_status = 0; |
| 198 | sm->pagereg = auto_alloc_array(image->machine, UINT8, sm->page_total_size); |
| 199 | sm->id[0] = sm->id[1] = 0; |
| 200 | sm->mp_opcode = 0; |
| 191 | 201 | |
| 192 | | //device_unload_mess_hd(image); |
| 193 | | |
| 194 | | smartmedia[id].page_data_size = 0; |
| 195 | | smartmedia[id].page_total_size = 0; |
| 196 | | smartmedia[id].num_pages = 0; |
| 197 | | smartmedia[id].log2_pages_per_block = 0; |
| 198 | | smartmedia[id].data_ptr = NULL; |
| 199 | | smartmedia[id].mode = SM_M_INIT; |
| 200 | | smartmedia[id].pointer_mode = SM_PM_A; |
| 201 | | smartmedia[id].page_addr = 0; |
| 202 | | smartmedia[id].byte_addr = 0; |
| 203 | | smartmedia[id].status = 0x40; |
| 204 | | smartmedia[id].accumulated_status = 0; |
| 205 | | smartmedia[id].pagereg = auto_alloc_array(image->machine, UINT8, smartmedia[id].page_total_size); |
| 206 | | smartmedia[id].id[0] = smartmedia[id].id[1] = 0; |
| 207 | | smartmedia[id].mp_opcode = 0; |
| 208 | | |
| 209 | 202 | return; |
| 210 | 203 | } |
| 211 | 204 | |
| 212 | | /* |
| 213 | | Initialize one SmartMedia chip: may be called at driver init or image load |
| 214 | | time (or machine init time if you don't use MESS image core) |
| 215 | | */ |
| 216 | | int smartmedia_machine_init(int id) |
| 205 | int smartmedia_present(const device_config *device) |
| 217 | 206 | { |
| 218 | | if (id >= MAX_SMARTMEDIA) |
| 219 | | { |
| 220 | | logerror("smartmedia: invalid chip %d\n", id); |
| 221 | | return 1; |
| 222 | | } |
| 223 | | |
| 224 | | smartmedia[id].mode = SM_M_INIT; |
| 225 | | smartmedia[id].pointer_mode = SM_PM_A; |
| 226 | | smartmedia[id].status = (smartmedia[id].status & 0x80) | 0x40; |
| 227 | | smartmedia[id].accumulated_status = 0; |
| 228 | | |
| 229 | | return 0; |
| 207 | smartmedia_t *sm = get_safe_token(device); |
| 208 | return sm->num_pages != 0; |
| 230 | 209 | } |
| 231 | 210 | |
| 232 | | int smartmedia_present(int id) |
| 211 | int smartmedia_protected(const device_config *device) |
| 233 | 212 | { |
| 234 | | return smartmedia[id].num_pages != 0; |
| 213 | smartmedia_t *sm = get_safe_token(device); |
| 214 | return (sm->status & 0x80) != 0; |
| 235 | 215 | } |
| 236 | 216 | |
| 237 | | int smartmedia_protected(int id) |
| 238 | | { |
| 239 | | return (smartmedia[id].status & 0x80) != 0; |
| 240 | | } |
| 241 | | |
| 242 | 217 | /* |
| 243 | 218 | write a byte to SmartMedia command port |
| 244 | 219 | */ |
| 245 | | void smartmedia_command_w(int id, UINT8 data) |
| 220 | void smartmedia_command_w(const device_config *device, UINT8 data) |
| 246 | 221 | { |
| 247 | | if (id >= MAX_SMARTMEDIA) |
| 248 | | { |
| 249 | | logerror("smartmedia: invalid chip %d\n", id); |
| 222 | smartmedia_t *sm = get_safe_token(device); |
| 223 | |
| 224 | if (!smartmedia_present(device)) |
| 250 | 225 | return; |
| 251 | | } |
| 252 | 226 | |
| 253 | | if (!smartmedia_present(id)) |
| 254 | | return; |
| 255 | | |
| 256 | 227 | switch (data) |
| 257 | 228 | { |
| 258 | 229 | case 0xff: |
| 259 | | smartmedia[id].mode = SM_M_INIT; |
| 260 | | smartmedia[id].pointer_mode = SM_PM_A; |
| 261 | | smartmedia[id].status = (smartmedia[id].status & 0x80) | 0x40; |
| 262 | | smartmedia[id].accumulated_status = 0; |
| 230 | sm->mode = SM_M_INIT; |
| 231 | sm->pointer_mode = SM_PM_A; |
| 232 | sm->status = (sm->status & 0x80) | 0x40; |
| 233 | sm->accumulated_status = 0; |
| 263 | 234 | break; |
| 264 | 235 | case 0x00: |
| 265 | | smartmedia[id].mode = SM_M_READ; |
| 266 | | smartmedia[id].pointer_mode = SM_PM_A; |
| 267 | | smartmedia[id].page_addr = 0; |
| 268 | | smartmedia[id].addr_load_ptr = 0; |
| 236 | sm->mode = SM_M_READ; |
| 237 | sm->pointer_mode = SM_PM_A; |
| 238 | sm->page_addr = 0; |
| 239 | sm->addr_load_ptr = 0; |
| 269 | 240 | break; |
| 270 | 241 | case 0x01: |
| 271 | | if (smartmedia[id].page_data_size <= 256) |
| 242 | if (sm->page_data_size <= 256) |
| 272 | 243 | { |
| 273 | 244 | logerror("smartmedia: unsupported upper data field select (256-byte pages)\n"); |
| 274 | | smartmedia[id].mode = SM_M_INIT; |
| 245 | sm->mode = SM_M_INIT; |
| 275 | 246 | } |
| 276 | 247 | else |
| 277 | 248 | { |
| 278 | | smartmedia[id].mode = SM_M_READ; |
| 279 | | smartmedia[id].pointer_mode = SM_PM_B; |
| 280 | | smartmedia[id].page_addr = 0; |
| 281 | | smartmedia[id].addr_load_ptr = 0; |
| 249 | sm->mode = SM_M_READ; |
| 250 | sm->pointer_mode = SM_PM_B; |
| 251 | sm->page_addr = 0; |
| 252 | sm->addr_load_ptr = 0; |
| 282 | 253 | } |
| 283 | 254 | break; |
| 284 | 255 | case 0x50: |
| 285 | | smartmedia[id].mode = SM_M_READ; |
| 286 | | smartmedia[id].pointer_mode = SM_PM_C; |
| 287 | | smartmedia[id].page_addr = 0; |
| 288 | | smartmedia[id].addr_load_ptr = 0; |
| 256 | sm->mode = SM_M_READ; |
| 257 | sm->pointer_mode = SM_PM_C; |
| 258 | sm->page_addr = 0; |
| 259 | sm->addr_load_ptr = 0; |
| 289 | 260 | break; |
| 290 | 261 | case 0x80: |
| 291 | | smartmedia[id].mode = SM_M_PROGRAM; |
| 292 | | smartmedia[id].page_addr = 0; |
| 293 | | smartmedia[id].addr_load_ptr = 0; |
| 294 | | memset(smartmedia[id].pagereg, 0xff, smartmedia[id].page_total_size); |
| 262 | sm->mode = SM_M_PROGRAM; |
| 263 | sm->page_addr = 0; |
| 264 | sm->addr_load_ptr = 0; |
| 265 | memset(sm->pagereg, 0xff, sm->page_total_size); |
| 295 | 266 | break; |
| 296 | 267 | case 0x10: |
| 297 | 268 | case 0x15: |
| 298 | | if (smartmedia[id].mode != SM_M_PROGRAM) |
| 269 | if (sm->mode != SM_M_PROGRAM) |
| 299 | 270 | { |
| 300 | 271 | logerror("smartmedia: illegal page program confirm command\n"); |
| 301 | | smartmedia[id].mode = SM_M_INIT; |
| 272 | sm->mode = SM_M_INIT; |
| 302 | 273 | } |
| 303 | 274 | else |
| 304 | 275 | { |
| 305 | 276 | int i; |
| 306 | | smartmedia[id].status = (smartmedia[id].status & 0x80) | smartmedia[id].accumulated_status; |
| 307 | | for (i=0; i<smartmedia[id].page_total_size; i++) |
| 308 | | smartmedia[id].data_ptr[smartmedia[id].page_addr*smartmedia[id].page_total_size + i] &= smartmedia[id].pagereg[i]; |
| 309 | | smartmedia[id].status |= 0x40; |
| 277 | sm->status = (sm->status & 0x80) | sm->accumulated_status; |
| 278 | for (i=0; i<sm->page_total_size; i++) |
| 279 | sm->data_ptr[sm->page_addr*sm->page_total_size + i] &= sm->pagereg[i]; |
| 280 | sm->status |= 0x40; |
| 310 | 281 | if (data == 0x15) |
| 311 | | smartmedia[id].accumulated_status = smartmedia[id].status & 0x1f; |
| 282 | sm->accumulated_status = sm->status & 0x1f; |
| 312 | 283 | else |
| 313 | | smartmedia[id].accumulated_status = 0; |
| 314 | | smartmedia[id].mode = SM_M_INIT; |
| 284 | sm->accumulated_status = 0; |
| 285 | sm->mode = SM_M_INIT; |
| 315 | 286 | } |
| 316 | 287 | break; |
| 317 | 288 | /*case 0x11: |
| 318 | 289 | break;*/ |
| 319 | 290 | case 0x60: |
| 320 | | smartmedia[id].mode = SM_M_ERASE; |
| 321 | | smartmedia[id].page_addr = 0; |
| 322 | | smartmedia[id].addr_load_ptr = 0; |
| 291 | sm->mode = SM_M_ERASE; |
| 292 | sm->page_addr = 0; |
| 293 | sm->addr_load_ptr = 0; |
| 323 | 294 | break; |
| 324 | 295 | case 0xd0: |
| 325 | | if (smartmedia[id].mode != SM_M_PROGRAM) |
| 296 | if (sm->mode != SM_M_PROGRAM) |
| 326 | 297 | { |
| 327 | 298 | logerror("smartmedia: illegal block erase confirm command\n"); |
| 328 | | smartmedia[id].mode = SM_M_INIT; |
| 299 | sm->mode = SM_M_INIT; |
| 329 | 300 | } |
| 330 | 301 | else |
| 331 | 302 | { |
| 332 | | smartmedia[id].status &= 0x80; |
| 333 | | memset(smartmedia[id].data_ptr + (smartmedia[id].page_addr & (-1 << smartmedia[id].log2_pages_per_block)), 0, (size_t)(1 << smartmedia[id].log2_pages_per_block)); |
| 334 | | smartmedia[id].status |= 0x40; |
| 335 | | smartmedia[id].mode = SM_M_INIT; |
| 336 | | if (smartmedia[id].pointer_mode == SM_PM_B) |
| 337 | | smartmedia[id].pointer_mode = SM_PM_A; |
| 303 | sm->status &= 0x80; |
| 304 | memset(sm->data_ptr + (sm->page_addr & (-1 << sm->log2_pages_per_block)), 0, (size_t)(1 << sm->log2_pages_per_block)); |
| 305 | sm->status |= 0x40; |
| 306 | sm->mode = SM_M_INIT; |
| 307 | if (sm->pointer_mode == SM_PM_B) |
| 308 | sm->pointer_mode = SM_PM_A; |
| 338 | 309 | } |
| 339 | 310 | break; |
| 340 | 311 | case 0x70: |
| 341 | | smartmedia[id].mode = SM_M_READSTATUS; |
| 312 | sm->mode = SM_M_READSTATUS; |
| 342 | 313 | break; |
| 343 | 314 | /*case 0x71: |
| 344 | 315 | break;*/ |
| 345 | 316 | case 0x90: |
| 346 | | smartmedia[id].mode = SM_M_READID; |
| 317 | sm->mode = SM_M_READID; |
| 347 | 318 | break; |
| 348 | 319 | /*case 0x91: |
| 349 | 320 | break;*/ |
| 350 | 321 | default: |
| 351 | 322 | logerror("smartmedia: unsupported command 0x%02x\n", data); |
| 352 | | smartmedia[id].mode = SM_M_INIT; |
| 323 | sm->mode = SM_M_INIT; |
| 353 | 324 | break; |
| 354 | 325 | } |
| 355 | 326 | } |
| r5784 | r5785 | |
| 357 | 328 | /* |
| 358 | 329 | write a byte to SmartMedia address port |
| 359 | 330 | */ |
| 360 | | void smartmedia_address_w(int id, UINT8 data) |
| 331 | void smartmedia_address_w(const device_config *device, UINT8 data) |
| 361 | 332 | { |
| 362 | | if (id >= MAX_SMARTMEDIA) |
| 363 | | { |
| 364 | | logerror("smartmedia: invalid chip %d\n", id); |
| 333 | smartmedia_t *sm = get_safe_token(device); |
| 334 | |
| 335 | if (!smartmedia_present(device)) |
| 365 | 336 | return; |
| 366 | | } |
| 367 | 337 | |
| 368 | | if (!smartmedia_present(id)) |
| 369 | | return; |
| 370 | | |
| 371 | | switch (smartmedia[id].mode) |
| 338 | switch (sm->mode) |
| 372 | 339 | { |
| 373 | 340 | case SM_M_INIT: |
| 374 | 341 | logerror("smartmedia: unexpected address port write\n"); |
| 375 | 342 | break; |
| 376 | 343 | case SM_M_READ: |
| 377 | 344 | case SM_M_PROGRAM: |
| 378 | | if (smartmedia[id].addr_load_ptr == 0) |
| 345 | if (sm->addr_load_ptr == 0) |
| 379 | 346 | { |
| 380 | | switch (smartmedia[id].pointer_mode) |
| 347 | switch (sm->pointer_mode) |
| 381 | 348 | { |
| 382 | 349 | case SM_PM_A: |
| 383 | | smartmedia[id].byte_addr = data; |
| 350 | sm->byte_addr = data; |
| 384 | 351 | break; |
| 385 | 352 | case SM_PM_B: |
| 386 | | smartmedia[id].byte_addr = data + 256; |
| 387 | | smartmedia[id].pointer_mode = SM_PM_A; |
| 353 | sm->byte_addr = data + 256; |
| 354 | sm->pointer_mode = SM_PM_A; |
| 388 | 355 | break; |
| 389 | 356 | case SM_PM_C: |
| 390 | | smartmedia[id].byte_addr = (data & 0x0f) + smartmedia[id].page_data_size; |
| 357 | sm->byte_addr = (data & 0x0f) + sm->page_data_size; |
| 391 | 358 | break; |
| 392 | 359 | } |
| 393 | 360 | } |
| 394 | 361 | else |
| 395 | | smartmedia[id].page_addr = (smartmedia[id].page_addr & ~(0xff << ((smartmedia[id].addr_load_ptr-1) * 8))) |
| 396 | | | (data << ((smartmedia[id].addr_load_ptr-1) * 8)); |
| 397 | | smartmedia[id].addr_load_ptr++; |
| 362 | sm->page_addr = (sm->page_addr & ~(0xff << ((sm->addr_load_ptr-1) * 8))) |
| 363 | | (data << ((sm->addr_load_ptr-1) * 8)); |
| 364 | sm->addr_load_ptr++; |
| 398 | 365 | break; |
| 399 | 366 | case SM_M_ERASE: |
| 400 | | smartmedia[id].page_addr = (smartmedia[id].page_addr & ~(0xff << (smartmedia[id].addr_load_ptr * 8))) |
| 401 | | | (data << (smartmedia[id].addr_load_ptr * 8)); |
| 402 | | smartmedia[id].addr_load_ptr++; |
| 367 | sm->page_addr = (sm->page_addr & ~(0xff << (sm->addr_load_ptr * 8))) |
| 368 | | (data << (sm->addr_load_ptr * 8)); |
| 369 | sm->addr_load_ptr++; |
| 403 | 370 | break; |
| 404 | 371 | case SM_M_READSTATUS: |
| 405 | 372 | logerror("smartmedia: unexpected address port write\n"); |
| 406 | 373 | break; |
| 407 | 374 | case SM_M_READID: |
| 408 | | if (smartmedia[id].addr_load_ptr == 0) |
| 409 | | smartmedia[id].byte_addr = data; |
| 410 | | smartmedia[id].addr_load_ptr++; |
| 375 | if (sm->addr_load_ptr == 0) |
| 376 | sm->byte_addr = data; |
| 377 | sm->addr_load_ptr++; |
| 411 | 378 | break; |
| 412 | 379 | } |
| 413 | 380 | } |
| r5784 | r5785 | |
| 415 | 382 | /* |
| 416 | 383 | read a byte from SmartMedia data port |
| 417 | 384 | */ |
| 418 | | UINT8 smartmedia_data_r(int id) |
| 385 | UINT8 smartmedia_data_r(const device_config *device) |
| 419 | 386 | { |
| 420 | 387 | UINT8 reply = 0; |
| 388 | smartmedia_t *sm = get_safe_token(device); |
| 421 | 389 | |
| 422 | | if (id >= MAX_SMARTMEDIA) |
| 423 | | { |
| 424 | | logerror("smartmedia: invalid chip %d\n", id); |
| 390 | if (!smartmedia_present(device)) |
| 425 | 391 | return 0; |
| 426 | | } |
| 427 | 392 | |
| 428 | | if (!smartmedia_present(id)) |
| 429 | | return 0; |
| 430 | | |
| 431 | | switch (smartmedia[id].mode) |
| 393 | switch (sm->mode) |
| 432 | 394 | { |
| 433 | 395 | case SM_M_INIT: |
| 434 | 396 | logerror("smartmedia: unexpected data port read\n"); |
| 435 | 397 | break; |
| 436 | 398 | case SM_M_READ: |
| 437 | | reply = smartmedia[id].data_ptr[smartmedia[id].page_addr*smartmedia[id].page_total_size + smartmedia[id].byte_addr]; |
| 438 | | smartmedia[id].byte_addr++; |
| 439 | | if (smartmedia[id].byte_addr == smartmedia[id].page_total_size) |
| 399 | reply = sm->data_ptr[sm->page_addr*sm->page_total_size + sm->byte_addr]; |
| 400 | sm->byte_addr++; |
| 401 | if (sm->byte_addr == sm->page_total_size) |
| 440 | 402 | { |
| 441 | | smartmedia[id].byte_addr = (smartmedia[id].pointer_mode != SM_PM_C) ? 0 : smartmedia[id].page_data_size; |
| 442 | | smartmedia[id].page_addr++; |
| 443 | | if (smartmedia[id].page_addr == smartmedia[id].num_pages) |
| 444 | | smartmedia[id].page_addr = 0; |
| 403 | sm->byte_addr = (sm->pointer_mode != SM_PM_C) ? 0 : sm->page_data_size; |
| 404 | sm->page_addr++; |
| 405 | if (sm->page_addr == sm->num_pages) |
| 406 | sm->page_addr = 0; |
| 445 | 407 | } |
| 446 | 408 | break; |
| 447 | 409 | case SM_M_PROGRAM: |
| r5784 | r5785 | |
| 451 | 413 | logerror("smartmedia: unexpected data port read\n"); |
| 452 | 414 | break; |
| 453 | 415 | case SM_M_READSTATUS: |
| 454 | | reply = smartmedia[id].status & 0xc1; |
| 416 | reply = sm->status & 0xc1; |
| 455 | 417 | break; |
| 456 | 418 | case SM_M_READID: |
| 457 | | if (smartmedia[id].byte_addr < 2) |
| 458 | | reply = smartmedia[id].id[smartmedia[id].byte_addr]; |
| 419 | if (sm->byte_addr < 2) |
| 420 | reply = sm->id[sm->byte_addr]; |
| 459 | 421 | break; |
| 460 | 422 | } |
| 461 | 423 | |
| r5784 | r5785 | |
| 465 | 427 | /* |
| 466 | 428 | write a byte to SmartMedia data port |
| 467 | 429 | */ |
| 468 | | void smartmedia_data_w(int id, UINT8 data) |
| 430 | void smartmedia_data_w(const device_config *device, UINT8 data) |
| 469 | 431 | { |
| 470 | | if (id >= MAX_SMARTMEDIA) |
| 471 | | { |
| 472 | | logerror("smartmedia: invalid chip %d\n", id); |
| 432 | smartmedia_t *sm = get_safe_token(device); |
| 433 | |
| 434 | if (!smartmedia_present(device)) |
| 473 | 435 | return; |
| 474 | | } |
| 475 | 436 | |
| 476 | | if (!smartmedia_present(id)) |
| 477 | | return; |
| 478 | | |
| 479 | | switch (smartmedia[id].mode) |
| 437 | switch (sm->mode) |
| 480 | 438 | { |
| 481 | 439 | case SM_M_INIT: |
| 482 | 440 | case SM_M_READ: |
| 483 | 441 | logerror("smartmedia: unexpected data port write\n"); |
| 484 | 442 | break; |
| 485 | 443 | case SM_M_PROGRAM: |
| 486 | | smartmedia[id].pagereg[smartmedia[id].byte_addr] = data; |
| 487 | | smartmedia[id].byte_addr++; |
| 488 | | if (smartmedia[id].byte_addr == smartmedia[id].page_total_size) |
| 489 | | smartmedia[id].byte_addr = (smartmedia[id].pointer_mode != SM_PM_C) ? 0 : smartmedia[id].page_data_size; |
| 444 | sm->pagereg[sm->byte_addr] = data; |
| 445 | sm->byte_addr++; |
| 446 | if (sm->byte_addr == sm->page_total_size) |
| 447 | sm->byte_addr = (sm->pointer_mode != SM_PM_C) ? 0 : sm->page_data_size; |
| 490 | 448 | break; |
| 491 | 449 | case SM_M_ERASE: |
| 492 | 450 | case SM_M_READSTATUS: |
| r5784 | r5785 | |
| 495 | 453 | break; |
| 496 | 454 | } |
| 497 | 455 | } |
| 456 | |
| 457 | |
| 458 | /* |
| 459 | Initialize one SmartMedia chip: may be called at driver init or image load |
| 460 | time (or machine init time if you don't use MESS image core) |
| 461 | */ |
| 462 | static DEVICE_RESET(smartmedia) |
| 463 | { |
| 464 | smartmedia_t *sm = get_safe_token(device); |
| 465 | |
| 466 | sm->mode = SM_M_INIT; |
| 467 | sm->pointer_mode = SM_PM_A; |
| 468 | sm->status = (sm->status & 0x80) | 0x40; |
| 469 | sm->accumulated_status = 0; |
| 470 | } |
| 471 | |
| 472 | DEVICE_GET_INFO( smartmedia ) |
| 473 | { |
| 474 | switch ( state ) |
| 475 | { |
| 476 | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break; |
| 477 | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(smartmedia_t); break; |
| 478 | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; |
| 479 | case DEVINFO_INT_IMAGE_TYPE: info->i = IO_MEMCARD; break; |
| 480 | case DEVINFO_INT_IMAGE_READABLE: info->i = 1; break; |
| 481 | case DEVINFO_INT_IMAGE_WRITEABLE: info->i = 1; break; |
| 482 | case DEVINFO_INT_IMAGE_CREATABLE: info->i = 0; break; |
| 483 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME( smartmedia ); break; |
| 484 | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME( smartmedia ); break; |
| 485 | case DEVINFO_FCT_IMAGE_LOAD: info->f = (genf *) DEVICE_IMAGE_LOAD_NAME( smartmedia ); break; |
| 486 | case DEVINFO_FCT_IMAGE_UNLOAD: info->f = (genf *) DEVICE_IMAGE_UNLOAD_NAME(smartmedia ); break; |
| 487 | case DEVINFO_STR_NAME: strcpy( info->s, "SmartMedia Flash ROM"); break; |
| 488 | case DEVINFO_STR_FAMILY: strcpy(info->s, "SmartMedia Flash ROM"); break; |
| 489 | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 490 | case DEVINFO_STR_IMAGE_FILE_EXTENSIONS: strcpy(info->s, ""); break; |
| 491 | } |
| 492 | } |