Previous 15994 Revisions Next

r5785 Friday 18th September, 2009 at 08:27:48 UTC by Miodrag Milanović
[TI99] Smartmed converted to device
[src/mess/drivers]geneve.c ti99_4p.c ti99_4x.c ti99_8.c
[src/mess/machine]99_usbsm.c smartmed.c smartmed.h

src/mess/machine/smartmed.c
r5784r5785
5959   header_len = sizeof(disk_image_header)
6060};
6161
62static struct
62typedef struct _smartmedia_t smartmedia_t;
63struct _smartmedia_t
6364{
6465   int page_data_size;   // 256 for a 2MB card, 512 otherwise
6566   int page_total_size;// 264 for a 2MB card, 528 otherwise
r5784r5785
9697   UINT8 *pagereg;   // page register used by program command
9798   UINT8 id[2];      // chip ID
9899   UINT8 mp_opcode;   // multi-plane operation code
99} smartmedia[MAX_SMARTMEDIA];
100};
100101
102
103INLINE 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
101113/*
102114   Init a SmartMedia image
103115*/
104116DEVICE_START( smartmedia )
105117{
106   int id = image_index_in_device(device);
107   assert((id >= 0) && (id < MAX_SMARTMEDIA));
118   smartmedia_t *sm = get_safe_token(device);
108119
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;
123134}
124135
125136/*
r5784r5785
127138*/
128139DEVICE_IMAGE_LOAD( smartmedia )
129140{
130   int id = image_index_in_device(image);
141   smartmedia_t *sm = get_safe_token(image);
131142   disk_image_header custom_header;
132143   int bytes_read;
133144
134   if (id >= MAX_SMARTMEDIA)
135   {
136      logerror("smartmedia: invalid chip %d\n", id);
137      return INIT_FAIL;
138   }
139145
140   /*if (device_load_mess_hd(image, file))
141      return INIT_FAIL;*/
142
143   //mess_hd_get_hard_disk_file(image)
144
145146   bytes_read = image_fread(image, &custom_header, sizeof(custom_header));
146147   if (bytes_read != sizeof(custom_header))
147148   {
r5784r5785
153154      return INIT_FAIL;
154155   }
155156
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;
166167   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;
171172
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);
175176
176177   return INIT_PASS;
177178}
r5784r5785
181182*/
182183DEVICE_IMAGE_UNLOAD( smartmedia )
183184{
184   int id = image_index_in_device(image);
185   smartmedia_t *sm = get_safe_token(image);
185186
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;
191201
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
209202   return;
210203}
211204
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*/
216int smartmedia_machine_init(int id)
205int smartmedia_present(const device_config *device)
217206{
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;
230209}
231210
232int smartmedia_present(int id)
211int smartmedia_protected(const device_config *device)
233212{
234   return smartmedia[id].num_pages != 0;
213   smartmedia_t *sm = get_safe_token(device);
214   return (sm->status & 0x80) != 0;
235215}
236216
237int smartmedia_protected(int id)
238{
239   return (smartmedia[id].status & 0x80) != 0;
240}
241
242217/*
243218   write a byte to SmartMedia command port
244219*/
245void smartmedia_command_w(int id, UINT8 data)
220void smartmedia_command_w(const device_config *device, UINT8 data)
246221{
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))
250225      return;
251   }
252226
253   if (!smartmedia_present(id))
254      return;
255
256227   switch (data)
257228   {
258229   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;
263234      break;
264235   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;
269240      break;
270241   case 0x01:
271      if (smartmedia[id].page_data_size <= 256)
242      if (sm->page_data_size <= 256)
272243      {
273244         logerror("smartmedia: unsupported upper data field select (256-byte pages)\n");
274         smartmedia[id].mode = SM_M_INIT;
245         sm->mode = SM_M_INIT;
275246      }
276247      else
277248      {
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;
282253      }
283254      break;
284255   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;
289260      break;
290261   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);
295266      break;
296267   case 0x10:
297268   case 0x15:
298      if (smartmedia[id].mode != SM_M_PROGRAM)
269      if (sm->mode != SM_M_PROGRAM)
299270      {
300271         logerror("smartmedia: illegal page program confirm command\n");
301         smartmedia[id].mode = SM_M_INIT;
272         sm->mode = SM_M_INIT;
302273      }
303274      else
304275      {
305276         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;
310281         if (data == 0x15)
311            smartmedia[id].accumulated_status = smartmedia[id].status & 0x1f;
282            sm->accumulated_status = sm->status & 0x1f;
312283         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;
315286      }
316287      break;
317288   /*case 0x11:
318289      break;*/
319290   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;
323294      break;
324295   case 0xd0:
325      if (smartmedia[id].mode != SM_M_PROGRAM)
296      if (sm->mode != SM_M_PROGRAM)
326297      {
327298         logerror("smartmedia: illegal block erase confirm command\n");
328         smartmedia[id].mode = SM_M_INIT;
299         sm->mode = SM_M_INIT;
329300      }
330301      else
331302      {
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;
338309      }
339310      break;
340311   case 0x70:
341      smartmedia[id].mode = SM_M_READSTATUS;
312      sm->mode = SM_M_READSTATUS;
342313      break;
343314   /*case 0x71:
344315      break;*/
345316   case 0x90:
346      smartmedia[id].mode = SM_M_READID;
317      sm->mode = SM_M_READID;
347318      break;
348319   /*case 0x91:
349320      break;*/
350321   default:
351322      logerror("smartmedia: unsupported command 0x%02x\n", data);
352      smartmedia[id].mode = SM_M_INIT;
323      sm->mode = SM_M_INIT;
353324      break;
354325   }
355326}
r5784r5785
357328/*
358329   write a byte to SmartMedia address port
359330*/
360void smartmedia_address_w(int id, UINT8 data)
331void smartmedia_address_w(const device_config *device, UINT8 data)
361332{
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))
365336      return;
366   }
367337
368   if (!smartmedia_present(id))
369      return;
370
371   switch (smartmedia[id].mode)
338   switch (sm->mode)
372339   {
373340   case SM_M_INIT:
374341      logerror("smartmedia: unexpected address port write\n");
375342      break;
376343   case SM_M_READ:
377344   case SM_M_PROGRAM:
378      if (smartmedia[id].addr_load_ptr == 0)
345      if (sm->addr_load_ptr == 0)
379346      {
380         switch (smartmedia[id].pointer_mode)
347         switch (sm->pointer_mode)
381348         {
382349         case SM_PM_A:
383            smartmedia[id].byte_addr = data;
350            sm->byte_addr = data;
384351            break;
385352         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;
388355            break;
389356         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;
391358            break;
392359         }
393360      }
394361      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++;
398365      break;
399366   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++;
403370      break;
404371   case SM_M_READSTATUS:
405372      logerror("smartmedia: unexpected address port write\n");
406373      break;
407374   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++;
411378      break;
412379   }
413380}
r5784r5785
415382/*
416383   read a byte from SmartMedia data port
417384*/
418UINT8 smartmedia_data_r(int id)
385UINT8 smartmedia_data_r(const device_config *device)
419386{
420387   UINT8 reply = 0;
388   smartmedia_t *sm = get_safe_token(device);
421389
422   if (id >= MAX_SMARTMEDIA)
423   {
424      logerror("smartmedia: invalid chip %d\n", id);
390   if (!smartmedia_present(device))
425391      return 0;
426   }
427392
428   if (!smartmedia_present(id))
429      return 0;
430
431   switch (smartmedia[id].mode)
393   switch (sm->mode)
432394   {
433395   case SM_M_INIT:
434396      logerror("smartmedia: unexpected data port read\n");
435397      break;
436398   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)
440402      {
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;
445407      }
446408      break;
447409   case SM_M_PROGRAM:
r5784r5785
451413      logerror("smartmedia: unexpected data port read\n");
452414      break;
453415   case SM_M_READSTATUS:
454      reply = smartmedia[id].status & 0xc1;
416      reply = sm->status & 0xc1;
455417      break;
456418   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];
459421      break;
460422   }
461423
r5784r5785
465427/*
466428   write a byte to SmartMedia data port
467429*/
468void smartmedia_data_w(int id, UINT8 data)
430void smartmedia_data_w(const device_config *device, UINT8 data)
469431{
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))
473435      return;
474   }
475436
476   if (!smartmedia_present(id))
477      return;
478
479   switch (smartmedia[id].mode)
437   switch (sm->mode)
480438   {
481439   case SM_M_INIT:
482440   case SM_M_READ:
483441      logerror("smartmedia: unexpected data port write\n");
484442      break;
485443   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;
490448      break;
491449   case SM_M_ERASE:
492450   case SM_M_READSTATUS:
r5784r5785
495453      break;
496454   }
497455}
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*/
462static 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
472DEVICE_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}
src/mess/machine/smartmed.h
r5784r5785
22   smartmed.h: header file for smartmed.c
33*/
44
5DEVICE_START( smartmedia );
6DEVICE_IMAGE_LOAD( smartmedia );
7DEVICE_IMAGE_UNLOAD( smartmedia );
5#ifndef __SMARTMEDIA_H__
6#define __SMARTMEDIA_H__
87
9int smartmedia_machine_init(int id);
108
11int smartmedia_present(int id);
12int smartmedia_protected(int id);
9/***************************************************************************
10    FUNCTION PROTOTYPES
11***************************************************************************/
1312
14UINT8 smartmedia_data_r(int id);
15void smartmedia_command_w(int id, UINT8 data);
16void smartmedia_address_w(int id, UINT8 data);
17void smartmedia_data_w(int id, UINT8 data);
13/* device interface */
14DEVICE_GET_INFO( smartmedia );
15
16int smartmedia_present(const device_config *device);
17int smartmedia_protected(const device_config *device);
18
19UINT8 smartmedia_data_r(const device_config *device);
20void smartmedia_command_w(const device_config *device, UINT8 data);
21void smartmedia_address_w(const device_config *device, UINT8 data);
22void smartmedia_data_w(const device_config *device, UINT8 data);
23
24/***************************************************************************
25    DEVICE CONFIGURATION MACROS
26***************************************************************************/
27
28#define SMARTMEDIA   DEVICE_GET_INFO_NAME(smartmedia)
29
30#define MDRV_SMARTMEDIA_ADD(_tag) \
31   MDRV_DEVICE_ADD(_tag, SMARTMEDIA, 0)
32
33#endif /* __SMARTMEDIA_H__ */
src/mess/machine/99_usbsm.c
r5784r5785
3737static void usbsm_cru_w(running_machine *machine, int offset, int data);
3838static  READ8_HANDLER(usbsm_mem_r);
3939static WRITE8_HANDLER(usbsm_mem_w);
40static UINT16 usbsm_mem_16_r(offs_t offset);
41static void usbsm_mem_16_w(offs_t offset, UINT16 data);
40static UINT16 usbsm_mem_16_r(const address_space* space,offs_t offset);
41static void usbsm_mem_16_w(const address_space* space,offs_t offset, UINT16 data);
4242
4343/* pointer to the SRAM area */
4444static UINT16 *ti99_usbsm_RAM;
r5784r5785
8484{
8585   if (strataflash_init(machine, 0))
8686      return 1;
87   if (smartmedia_machine_init(0))
88      return 1;
8987
9088   ti99_peb_set_card_handlers(0x1600, & usbsm_handlers);
9189
r5784r5785
104102static int usbsm_cru_r(running_machine *machine, int offset)
105103{
106104   int reply = 0;
107
105   const device_config *smartmedia =devtag_get_device(machine, "smartmedia");
108106   offset &= 3;
109107
110108   switch (offset)
r5784r5785
126124                  1: Card absent or not protected.
127125       */
128126      reply = 0x33;
129      if (! smartmedia_present(0))
127      if (! smartmedia_present(smartmedia))
130128         reply |= 0xc0;
131      else if (! smartmedia_protected(0))
129      else if (! smartmedia_protected(smartmedia))
132130         reply |= 0x80;
133131      break;
134132   }
r5784r5785
198196{
199197   if (tms9995_mode ? (!(offset & 1)) : (offset & 1))
200198   {   /* first read triggers 16-bit read cycle */
201      input_latch = usbsm_mem_16_r(offset >> 1);
199      input_latch = usbsm_mem_16_r(space,offset >> 1);
202200   }
203201
204202   /* return latched input */
r5784r5785
218216
219217   if (tms9995_mode ? (offset & 1) : (!(offset & 1)))
220218   {   /* second write triggers 16-bit write cycle */
221      usbsm_mem_16_w(offset >> 1, output_latch);
219      usbsm_mem_16_w(space,offset >> 1, output_latch);
222220   }
223221}
224222
225223/*
226224   demultiplexed read in USB-SmartMedia DSR space
227225*/
228static UINT16 usbsm_mem_16_r(offs_t offset)
226static UINT16 usbsm_mem_16_r(const address_space* space,offs_t offset)
229227{
230228   UINT16 reply = 0;
231
229   const device_config *smartmedia =devtag_get_device(space->machine, "smartmedia");
232230   if (offset < 0x800)
233231   {   /* 0x4000-0x4fff range */
234232      if ((cru_register & cru_reg_io_regs_enable) && (offset >= 0x7f8))
235233      {   /* SmartMedia interface */
236234         if (offset == 0)
237            reply = smartmedia_data_r(0) << 8;
235            reply = smartmedia_data_r(smartmedia) << 8;
238236      }
239237      else
240238      {   /* FEEPROM */
r5784r5785
259257/*
260258   demultiplexed write in USB-SmartMedia DSR space
261259*/
262static void usbsm_mem_16_w(offs_t offset, UINT16 data)
260static void usbsm_mem_16_w(const address_space* space,offs_t offset, UINT16 data)
263261{
262   const device_config *smartmedia =devtag_get_device(space->machine, "smartmedia");
264263   if (offset < 0x800)
265264   {   /* 0x4000-0x4fff range */
266265      if ((cru_register & cru_reg_io_regs_enable) && (offset >= 0x7f8))
r5784r5785
268267         switch (offset & 3)
269268         {
270269         case 0:
271            smartmedia_data_w(0, data >> 8);
270            smartmedia_data_w(smartmedia, data >> 8);
272271            break;
273272         case 1:
274            smartmedia_address_w(0, data >> 8);
273            smartmedia_address_w(smartmedia, data >> 8);
275274            break;
276275         case 2:
277            smartmedia_command_w(0, data >> 8);
276            smartmedia_command_w(smartmedia, data >> 8);
278277            break;
279278         case 3:
280279            /* bogus, don't use(?) */
src/mess/drivers/ti99_8.c
r5784r5785
530530   MDRV_FLOPPY_4_DRIVES_ADD(ti99_8_floppy_config)   
531531
532532   MDRV_TI99_CARTRIDGE_ADD("ti99_multicart")
533   MDRV_SMARTMEDIA_ADD("smartmedia")
533534MACHINE_DRIVER_END
534535
535536/*
r5784r5785
607608   }
608609}
609610
610static void ti99_8_memcard_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info)
611{
612   /* memcard */
613   switch(state)
614   {
615      /* --- the following bits of info are returned as 64-bit signed integers --- */
616      case MESS_DEVINFO_INT_TYPE:                     info->i = IO_MEMCARD; break;
617      case MESS_DEVINFO_INT_READABLE:                  info->i = 1; break;
618      case MESS_DEVINFO_INT_WRITEABLE:                  info->i = 1; break;
619      case MESS_DEVINFO_INT_CREATABLE:                  info->i = 0; break;
620      case MESS_DEVINFO_INT_COUNT:                     info->i = 1; break;
621611
622      /* --- the following bits of info are returned as pointers to data or functions --- */
623      case MESS_DEVINFO_PTR_START:                     info->start = DEVICE_START_NAME(smartmedia); break;
624      case MESS_DEVINFO_PTR_LOAD:                     info->load = DEVICE_IMAGE_LOAD_NAME(smartmedia); break;
625      case MESS_DEVINFO_PTR_UNLOAD:                  info->unload = DEVICE_IMAGE_UNLOAD_NAME(smartmedia); break;
626
627      /* --- the following bits of info are returned as NULL-terminated strings --- */
628      case MESS_DEVINFO_STR_FILE_EXTENSIONS:            strcpy(info->s = device_temp_str(), ""); break;
629   }
630}
631
632612static SYSTEM_CONFIG_START(ti99_8)
633613   /* one cartridge port */
634614   /* one cassette unit port */
r5784r5785
636616   /* expansion port (similar to 99/4(a) - yet slightly different) */
637617   CONFIG_DEVICE(ti99_8_parallel_getinfo)
638618   CONFIG_DEVICE(ti99_8_serial_getinfo)
639   /*CONFIG_DEVICE(ti99_8_quickload_getinfo)*/
640   CONFIG_DEVICE(ti99_8_memcard_getinfo)
619   /*CONFIG_DEVICE(ti99_8_quickload_getinfo)*/   
641620SYSTEM_CONFIG_END
642621
643622/*      YEAR    NAME        PARENT      COMPAT  MACHINE     INPUT   INIT        CONFIG      COMPANY                 FULLNAME */
src/mess/drivers/geneve.c
r5784r5785
518518   MDRV_WD179X_ADD("wd179x", ti99_wd17xx_interface )
519519   
520520   MDRV_FLOPPY_4_DRIVES_ADD(geneve_floppy_config)
521   
522   MDRV_SMARTMEDIA_ADD("smartmedia")
521523MACHINE_DRIVER_END
522524
523525
r5784r5785
611613   }
612614}
613615
614static void geneve_memcard_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info)
615{
616   /* memcard */
617   switch(state)
618   {
619      /* --- the following bits of info are returned as 64-bit signed integers --- */
620      case MESS_DEVINFO_INT_TYPE:                     info->i = IO_MEMCARD; break;
621      case MESS_DEVINFO_INT_READABLE:                  info->i = 1; break;
622      case MESS_DEVINFO_INT_WRITEABLE:                  info->i = 1; break;
623      case MESS_DEVINFO_INT_CREATABLE:                  info->i = 0; break;
624      case MESS_DEVINFO_INT_COUNT:                     info->i = 1; break;
625
626      /* --- the following bits of info are returned as pointers to data or functions --- */
627      case MESS_DEVINFO_PTR_START:                     info->start = DEVICE_START_NAME(smartmedia); break;
628      case MESS_DEVINFO_PTR_LOAD:                     info->load = DEVICE_IMAGE_LOAD_NAME(smartmedia); break;
629      case MESS_DEVINFO_PTR_UNLOAD:                  info->unload = DEVICE_IMAGE_UNLOAD_NAME(smartmedia); break;
630
631      /* --- the following bits of info are returned as NULL-terminated strings --- */
632      case MESS_DEVINFO_STR_FILE_EXTENSIONS:            strcpy(info->s = device_temp_str(), ""); break;
633   }
634}
635
636616static SYSTEM_CONFIG_START(geneve)   
637617   CONFIG_DEVICE(geneve_parallel_getinfo)
638618   CONFIG_DEVICE(geneve_serial_getinfo)
639   CONFIG_DEVICE(geneve_memcard_getinfo)
640619SYSTEM_CONFIG_END
641620
642621/*    YEAR  NAME      PARENT    COMPAT  MACHINE      INPUT    INIT      CONFIG  COMPANY     FULLNAME */
src/mess/drivers/ti99_4p.c
r5784r5785
291291   MDRV_TMS9902_ADD("tms9902_1", tms9902_params_1)
292292
293293   MDRV_FLOPPY_4_DRIVES_ADD(ti99_4p_floppy_config)   
294   
295   MDRV_SMARTMEDIA_ADD("smartmedia")
294296MACHINE_DRIVER_END
295297
296298
r5784r5785
382384}
383385#endif
384386
385static void ti99_4p_memcard_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info)
386{
387   /* memcard */
388   switch(state)
389   {
390      /* --- the following bits of info are returned as 64-bit signed integers --- */
391      case MESS_DEVINFO_INT_TYPE:                     info->i = IO_MEMCARD; break;
392      case MESS_DEVINFO_INT_READABLE:                  info->i = 1; break;
393      case MESS_DEVINFO_INT_WRITEABLE:                  info->i = 1; break;
394      case MESS_DEVINFO_INT_CREATABLE:                  info->i = 0; break;
395      case MESS_DEVINFO_INT_COUNT:                     info->i = 1; break;
396387
397      /* --- the following bits of info are returned as pointers to data or functions --- */
398      case MESS_DEVINFO_PTR_START:                     info->start = DEVICE_START_NAME(smartmedia); break;
399      case MESS_DEVINFO_PTR_LOAD:                     info->load = DEVICE_IMAGE_LOAD_NAME(smartmedia); break;
400      case MESS_DEVINFO_PTR_UNLOAD:                  info->unload = DEVICE_IMAGE_UNLOAD_NAME(smartmedia); break;
401
402      /* --- the following bits of info are returned as NULL-terminated strings --- */
403      case MESS_DEVINFO_STR_FILE_EXTENSIONS:            strcpy(info->s = device_temp_str(), ""); break;
404   }
405}
406
407388static SYSTEM_CONFIG_START(ti99_4p)
408389   CONFIG_DEVICE(ti99_4p_parallel_getinfo)
409390   CONFIG_DEVICE(ti99_4p_serial_getinfo)
410   /*CONFIG_DEVICE(ti99_4p_quickload_getinfo)*/
411   CONFIG_DEVICE(ti99_4p_memcard_getinfo)
391   /*CONFIG_DEVICE(ti99_4p_quickload_getinfo)*/   
412392SYSTEM_CONFIG_END
413393
414394/*    YEAR  NAME      PARENT   COMPAT   MACHINE      INPUT    INIT     CONFIG   COMPANY     FULLNAME */
src/mess/drivers/ti99_4x.c
r5784r5785
789789   MDRV_WD179X_ADD("wd179x", ti99_wd17xx_interface )   
790790   MDRV_FLOPPY_4_DRIVES_ADD(ti99_4_floppy_config)   
791791   MDRV_TI99_CARTRIDGE_ADD("ti99_multicart")
792   
792   MDRV_SMARTMEDIA_ADD("smartmedia")
793793MACHINE_DRIVER_END
794794
795795
r5784r5785
953953   }
954954}
955955#endif
956
957static void ti99_4_memcard_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info)
958{
959   /* memcard */
960   switch(state)
961   {
962      /* --- the following bits of info are returned as 64-bit signed integers --- */
963      case MESS_DEVINFO_INT_TYPE:                     info->i = IO_MEMCARD; break;
964      case MESS_DEVINFO_INT_READABLE:                  info->i = 1; break;
965      case MESS_DEVINFO_INT_WRITEABLE:                  info->i = 1; break;
966      case MESS_DEVINFO_INT_CREATABLE:                  info->i = 0; break;
967      case MESS_DEVINFO_INT_COUNT:                     info->i = 1; break;
968
969      /* --- the following bits of info are returned as pointers to data or functions --- */
970      case MESS_DEVINFO_PTR_START:                     info->start = DEVICE_START_NAME(smartmedia); break;
971      case MESS_DEVINFO_PTR_LOAD:                     info->load = DEVICE_IMAGE_LOAD_NAME(smartmedia); break;
972      case MESS_DEVINFO_PTR_UNLOAD:                  info->unload = DEVICE_IMAGE_UNLOAD_NAME(smartmedia); break;
973
974      /* --- the following bits of info are returned as NULL-terminated strings --- */
975      case MESS_DEVINFO_STR_FILE_EXTENSIONS:            strcpy(info->s = device_temp_str(), ""); break;
976   }
977}     
978956   
979957static SYSTEM_CONFIG_START(ti99_4)   
980958   CONFIG_DEVICE(ti99_4_parallel_getinfo)
981959   CONFIG_DEVICE(ti99_4_serial_getinfo)
982960   /*CONFIG_DEVICE(ti99_4_quickload_getinfo)*/
983   CONFIG_DEVICE(ti99_4_memcard_getinfo)
984961SYSTEM_CONFIG_END
985962
986963/*    YEAR  NAME      PARENT   COMPAT   MACHINE      INPUT    INIT      CONFIG  COMPANY             FULLNAME */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team