Previous 15994 Revisions Next

r1158 Sunday 21st October, 2007 at 02:08:40 UTC by R. Belmont
Remove redundant flash ROM implementations, convert Avigo and PCW16 to MAME's universal flash setup.
[src/mess]mess.mak
[src/mess/drivers]avigo.c pcw16.c
[src/mess/includes]28f008sa.h am29f080.h
[src/mess/machine]28f008sa.c am29f080.c

src/mess/includes/28f008sa.h
r1157r1158
1void flash_init(int);
2void flash_reset(int);
3void flash_finish(int);
4void flash_store(int, const char *);
5void flash_restore(int, const char *);
6char *flash_get_base(int);
7
8int     flash_bank_handler_r(int index1, int offset);
9void    flash_bank_handler_w(int index1, int offset, int data);
10
src/mess/includes/am29f080.h
r1157r1158
1void amd_flash_init(int);
2void amd_flash_reset(int);
3void amd_flash_finish(int);
4void amd_flash_store(int, const char *);
5void amd_flash_restore(int, const char *);
6char *amd_flash_get_base(int);
7
8int     amd_flash_bank_handler_r(int index1, int offset);
9void    amd_flash_bank_handler_w(int index1, int offset, int data);
10
src/mess/machine/28f008sa.c
r1157r1158
1/*******************************************/
2/* Intel 28F008SA 5 Volt Flash-File Memory */
3
4#include "driver.h"
5
6#include "includes/28f008sa.h"
7
8/* commands */
9#define FLASH_COMMAND_READ_ARRAY_OR_RESET               0x00FF
10#define FLASH_COMMAND_INTELLIGENT_IDENTIFIER            0x0090
11#define FLASH_COMMAND_READ_STATUS_REGISTER               0x0070
12#define FLASH_COMMAND_CLEAR_STATUS_REGISTER               0x0050
13#define FLASH_COMMAND_ERASE_SETUP_OR_ERASE_CONFIRM         0x0020
14#define FLASH_COMMAND_ERASE_SUSPEND_OR_ERASE_RESUME         0x00b0
15#define FLASH_COMMAND_BYTE_WRITE_SETUP_OR_WRITE            0x0040
16#define FLASH_COMMAND_ALTERNATIVE_BYTE_WRITE_SETUP_OR_WRITE   0x0010
17#define FLASH_COMMAND_ERASE_CONFIRM                     0x00d0
18
19/* status bits */
20#define FLASH_STATUS_WRITE_STATE_MACHINE_STATUS_READY                  0x0080
21#define FLASH_STATUS_WRITE_STATE_MACHINE_STATUS_BUSY                  0x0000
22
23#define FLASH_STATUS_ERASE_SUSPEND_STATUS_SUSPENDED                     0x0040
24#define FLASH_STATUS_ERASE_SUSPEND_STATUS_ERASE_IN_PROGRESS_OR_COMPLETED   0x0000
25
26#define FLASH_STATUS_ERASE_STATUS_ERROR_IN_BLOCK                     0x0020
27#define FLASH_STATUS_ERASE_STATUS_SUCCESSFUL_BLOCK_ERASE               0x0000
28
29#define FLASH_STATUS_BYTE_WRITE_STATUS_ERROR                        0x0010
30#define FLASH_STATUS_BYTE_WRITE_STATUS_SUCCESSFUL                     0x0000
31
32#define FLASH_STATUS_VPP_STATUS_LOW_OPERATION_ABORTED                  0x0008
33#define FLASH_STATUS_VPP_STATUS_HIGH                              0x0000
34
35#define FLASH_STATUS_RESERVED                                    (0x0004 | 0x0002 | 0x0001)
36
37#define FLASH_MANUFACTURER_CODE            0x089
38#define FLASH_DEVICE_CODE               0x0a2
39
40/* setup command has been issued */
41#define FLASH_ERASE_STATUS_SETUP 0x001
42/* suspended */
43#define FLASH_ERASE_STATUS_SUSPENDED 0x002
44/* nothing */
45#define FLASH_ERASE_STATUS_NONE   0x000
46/* erase in progress */
47#define FLASH_ERASE_STATUS_ERASING 0x003
48
49/* datasheet states that a block will be erase typically in 1.6 seconds */
50#define FLASH_TIME_PER_BLOCK_SECS (1.6f)
51#define FLASH_TIME_PER_BYTE_IN_SECS (FLASH_TIME_PER_BLOCK_SECS/65536.0f)
52
53typedef struct FLASH_FILE_MEMORY
54{
55   /* internal status register */
56   unsigned long flash_status;
57   /* command */
58   unsigned long flash_command;
59   /* number of command cycles required */
60   unsigned long flash_command_parameters_required;
61
62   /* index of 64k block to erase */
63   unsigned long flash_erase_block;
64
65   /* offset we were last suspended at, or offset the erase procedure started at*/
66   unsigned long flash_offset;
67
68   void   *flash_timer;
69
70   int      flash_erase_status;
71
72   /* address of 1mb data */
73   char *base;
74} FLASH_FILE_MEMORY;
75
76#define MAX_FLASH_DEVICES 4
77
78static FLASH_FILE_MEMORY flash[MAX_FLASH_DEVICES];
79
80char *flash_get_base(int index1)
81{
82   return flash[index1].base;
83}
84
85static void flash_check_complete_erase(int index1)
86{
87   if (flash[index1].flash_offset>=65536)
88   {
89
90      flash[index1].flash_status = (FLASH_STATUS_WRITE_STATE_MACHINE_STATUS_READY |
91            FLASH_STATUS_ERASE_SUSPEND_STATUS_ERASE_IN_PROGRESS_OR_COMPLETED);
92
93      /* set erase state to none */
94      flash[index1].flash_erase_status = FLASH_ERASE_STATUS_NONE;
95   }
96}
97
98
99/* callback for flash erase - if it gets to here, the erase procedure is completed */
100static TIMER_CALLBACK(flash_timer_callback)
101{
102   int index1 = param;
103   if (flash[index1].flash_offset<65536)
104   {
105      /* complete erase */
106      memset(flash[index1].base + (flash[index1].flash_erase_block<<16) + flash[index1].flash_offset, 0x0ff,65536-flash[index1].flash_offset);
107      flash[index1].flash_offset = 65536;
108   }
109
110   flash_check_complete_erase(index1);
111
112   /* stop timer from activating again, and do not let
113   MAME sub-system remove it from the list */
114   mame_timer_reset(flash[index1].flash_timer, time_never);
115}
116
117/* suspend erase operation */
118static void flash_suspend_erase(int index1)
119{
120   /* suspend */
121   flash[index1].flash_status = FLASH_STATUS_ERASE_SUSPEND_STATUS_SUSPENDED |
122                  FLASH_STATUS_WRITE_STATE_MACHINE_STATUS_READY;
123   
124
125   if (flash[index1].flash_timer!=0)
126   {
127      int num_bytes;
128      double time_elapsed;
129
130      /* get time passed */
131      time_elapsed = mame_time_to_double(mame_timer_timeelapsed(flash[index1].flash_timer));
132
133      /* at this point in time, I don't believe it is necessary to know number of bits that have
134      been erased*/
135
136      /* num bytes that have been erased in that time */
137      num_bytes = time_elapsed/FLASH_TIME_PER_BYTE_IN_SECS;
138
139      /* this should not happen, but check anyway */
140      if (num_bytes>65536)
141      {
142         num_bytes = 65536;
143      }
144
145      if (num_bytes!=0)
146      {
147         /* back-fill from previous suspend point with erase data (fills up to this point)*/
148         memset(flash[index1].base + (flash[index1].flash_erase_block<<16) + flash[index1].flash_offset, 0x0ff, num_bytes);
149      }
150      /* update offset */
151      flash[index1].flash_offset += num_bytes;
152
153      /* remove timer */
154      mame_timer_reset(flash[index1].flash_timer, time_never);
155
156      /* set erase state to suspended */
157      flash[index1].flash_erase_status = FLASH_ERASE_STATUS_SUSPENDED;
158   }
159
160   flash_check_complete_erase(index1);
161}
162
163static void flash_resume_erase(int index1)
164{
165   int num_bytes_remaining;
166
167   flash[index1].flash_status = (FLASH_STATUS_WRITE_STATE_MACHINE_STATUS_BUSY |
168               FLASH_STATUS_ERASE_SUSPEND_STATUS_ERASE_IN_PROGRESS_OR_COMPLETED);
169
170   flash[index1].flash_erase_status = FLASH_ERASE_STATUS_ERASING;
171
172   /* calc number of bytes remaining to erase */
173   num_bytes_remaining = 65536-flash[index1].flash_offset;
174
175   /* issue a timer for this */
176   mame_timer_adjust(flash[index1].flash_timer, double_to_mame_time((FLASH_TIME_PER_BYTE_IN_SECS*num_bytes_remaining)), index1, time_zero);
177}
178
179
180void   flash_init(int index1)
181{
182   flash[index1].flash_timer = mame_timer_alloc(flash_timer_callback);
183
184   /* 1mb ram */
185   flash[index1].base = (char *) auto_malloc(1024*1024);
186   memset(flash[index1].base, 0x080, 1024*1024);
187   flash_reset(index1);
188   /* no erase state */
189   flash[index1].flash_erase_status = FLASH_ERASE_STATUS_NONE;
190}
191
192void flash_finish(int index1)
193{
194   if (flash[index1].base!=NULL)
195      flash[index1].base = NULL;
196}
197
198void flash_store(int index1, const char *flash_name)
199{
200   file_error filerr;
201   mame_file *file;
202
203   if (flash[index1].base!=NULL)
204   {
205      filerr = mame_fopen(SEARCHPATH_MEMCARD, flash_name, OPEN_FLAG_WRITE, &file);
206
207      if (filerr == FILERR_NONE)
208      {
209         mame_fwrite(file, flash[index1].base, (1024*1024));
210   
211         mame_fclose(file);
212      }
213   }
214}
215
216
217
218void flash_restore(int index1, const char *flash_name)
219{
220   file_error filerr;
221   mame_file *file;
222
223   if (flash[index1].base!=NULL)
224   {
225      filerr = mame_fopen(SEARCHPATH_MEMCARD, flash_name, OPEN_FLAG_READ, &file);
226
227      if (filerr == FILERR_NONE)
228      {
229         mame_fread(file, flash[index1].base, (1024*1024));
230   
231         mame_fclose(file);
232      }
233   }
234}
235
236
237void flash_reset(int index1)
238{
239   flash[index1].flash_status = FLASH_STATUS_WRITE_STATE_MACHINE_STATUS_READY;
240   flash[index1].flash_command = FLASH_COMMAND_READ_ARRAY_OR_RESET;
241   flash[index1].flash_erase_status = FLASH_ERASE_STATUS_NONE;
242   mame_timer_reset(flash[index1].flash_timer, time_never);
243}
244   
245
246/* flash read - offset is offset within flash-file (offset within 1mb)*/
247int flash_bank_handler_r(int index1, int offset)
248{
249   switch (flash[index1].flash_command)
250   {
251      /* read mode, return flash-rom data */
252      case FLASH_COMMAND_READ_ARRAY_OR_RESET:
253         return flash[index1].base[offset];
254
255      /* read intelligent identifier */
256      case FLASH_COMMAND_INTELLIGENT_IDENTIFIER:
257      {
258         /* offset/address zero returns manufacturer code */
259         if (offset==0)
260            return FLASH_MANUFACTURER_CODE;
261         /* offset/address one returns device code */
262         if (offset==1)
263            return FLASH_DEVICE_CODE;
264      }
265      break;
266
267      /* read status */
268      case FLASH_COMMAND_BYTE_WRITE_SETUP_OR_WRITE:
269      case FLASH_COMMAND_ALTERNATIVE_BYTE_WRITE_SETUP_OR_WRITE:
270      case FLASH_COMMAND_ERASE_SETUP_OR_ERASE_CONFIRM:
271      case FLASH_COMMAND_READ_STATUS_REGISTER:
272      case FLASH_COMMAND_CLEAR_STATUS_REGISTER:
273      case FLASH_COMMAND_ERASE_SUSPEND_OR_ERASE_RESUME:
274      case FLASH_COMMAND_ERASE_CONFIRM:
275         return flash[index1].flash_status;
276
277   }
278
279   return 0x0ff;
280}
281
282/* flash write - offset is offset within flash-file (offset within 1mb)*/
283void flash_bank_handler_w(int index1, int offset, int data)
284{
285   /* for commands requiring more than one cycle */
286   if (flash[index1].flash_command_parameters_required!=0)
287   {
288      switch (flash[index1].flash_command)
289      {
290         case FLASH_COMMAND_BYTE_WRITE_SETUP_OR_WRITE:
291         case FLASH_COMMAND_ALTERNATIVE_BYTE_WRITE_SETUP_OR_WRITE:
292         {
293            /* ready, with no errors */
294            flash[index1].flash_status &= FLASH_STATUS_ERASE_SUSPEND_STATUS_SUSPENDED;
295            flash[index1].flash_status |= FLASH_STATUS_WRITE_STATE_MACHINE_STATUS_READY;
296            flash[index1].base[offset] = data;
297         
298            /* no parameters required */
299            flash[index1].flash_command_parameters_required = 0;
300         }
301         return;
302
303         default:
304            break;
305      }
306
307   }
308
309   
310   flash[index1].flash_command_parameters_required = 0;
311   /* set command */
312   flash[index1].flash_command = data;
313
314   switch (data)
315   {
316      case FLASH_COMMAND_READ_ARRAY_OR_RESET:
317      case FLASH_COMMAND_INTELLIGENT_IDENTIFIER:
318      case FLASH_COMMAND_READ_STATUS_REGISTER:
319      case FLASH_COMMAND_CLEAR_STATUS_REGISTER:
320      {
321         /* if clear status register */
322         if (data == FLASH_COMMAND_CLEAR_STATUS_REGISTER)
323         {
324            /* clear it */
325            flash[index1].flash_status &=FLASH_STATUS_ERASE_SUSPEND_STATUS_SUSPENDED;
326         }
327      }
328      break;
329
330      case FLASH_COMMAND_BYTE_WRITE_SETUP_OR_WRITE:
331      case FLASH_COMMAND_ALTERNATIVE_BYTE_WRITE_SETUP_OR_WRITE:
332      {
333         /* expecting a parameter */
334         flash[index1].flash_command_parameters_required = 1;
335      }
336      break;
337
338      /* setup an erase */
339      case FLASH_COMMAND_ERASE_SETUP_OR_ERASE_CONFIRM:
340      {
341         flash[index1].flash_erase_status = FLASH_ERASE_STATUS_SETUP;
342      }
343      break;
344
345      case FLASH_COMMAND_ERASE_SUSPEND_OR_ERASE_RESUME:
346      {
347         /* is it suspended? */
348         if ((flash[index1].flash_status & FLASH_STATUS_ERASE_SUSPEND_STATUS_SUSPENDED)==0)
349         {
350            /* no */
351
352            /* suspend it */
353            flash_suspend_erase(index1);
354         }
355      }
356      break;
357
358
359      case FLASH_COMMAND_ERASE_CONFIRM:
360      {
361         switch (flash[index1].flash_erase_status)
362         {
363            /* suspended? */
364            case FLASH_ERASE_STATUS_SUSPENDED:
365            {
366               /* has the erase procedure completed? */
367
368               /* if suspended.. and not completed */
369               /* confirm start erase */
370
371               /* no longer suspended */
372               flash_resume_erase(index1);
373            }
374            break;
375
376            /* setup? */
377            case FLASH_ERASE_STATUS_SETUP:
378            {
379               /* get block we are erasing */
380               flash[index1].flash_erase_block = offset>>16;
381
382               /* set initial offset */
383               flash[index1].flash_offset = 0;
384
385               /* start the timer for erase */
386               flash_resume_erase(index1);
387            }
388            break;
389
390            default:
391               break;
392         }
393      }
394      break;
395
396      default:
397         break;
398
399   }
400
401}
402
403/*******************************************/
src/mess/machine/am29f080.c
r1157r1158
1/*******************************************/
2/* Intel 28F008SA 5 Volt Flash-File Memory */
3
4#include "driver.h"
5
6#include "includes/am29f080.h"
7
8/* commands */
9
10enum
11{
12   AMD_FLASH_MODE_READ_ARRAY,
13   AMD_FLASH_MODE_AUTOSELECT,
14   AMD_FLASH_MODE_BYTE_PROGRAM,
15   AMD_FLASH_MODE_WAITING_ERASE_TYPE
16};
17
18
19#define AMD_FLASH_COMMAND_RESET            0x0F0
20#define AMD_FLASH_COMMAND_ERASE_SUSPEND      0x0B0
21#define AMD_FLASH_COMMAND_ERASE_RESUME      0x030
22#define AMD_FLASH_COMMAND_AUTOSELECT      0x090
23#define AMD_FLASH_COMMAND_ERASE            0x080
24#define AMD_FLASH_COMMAND_BYTE_PROGRAM      0x0A0
25#define AMD_FLASH_COMMAND_ERASE_CHIP      0x010
26#define AMD_FLASH_COMMAND_ERASE_SECTOR      0x030
27
28#define AMD_FLASH_MANUFACTURER_CODE            0x001
29#define AMD_FLASH_DEVICE_CODE               0x0d5
30
31struct amd_flash_interface
32{
33   /* ready/busy# output callback */
34   void (*amd_flash_ry_by_output)(int state);
35};
36
37
38
39typedef struct AMD_FLASH_FILE_MEMORY
40{
41   unsigned long amd_autoselect_state;
42   unsigned long mode;
43   unsigned char sector_group_protection;
44
45//   /* internal status register */
46//   unsigned long flash_status;
47//   /* command */
48//   unsigned long flash_command;
49//   /* number of command cycles required */
50//   unsigned long flash_command_parameters_required;
51//
52//   /* index of 64k block to erase */
53//   unsigned long flash_erase_block;
54//
55//   /* offset we were last suspended at, or offset the erase procedure started at*/
56//   unsigned long flash_offset;
57
58   void   *flash_timer;
59
60   int      flash_erase_status;
61
62   /* address of 1mb data */
63   char *base;
64
65   struct amd_flash_interface interface;
66} AMD_FLASH_FILE_MEMORY;
67
68
69#define MAX_FLASH_DEVICES 4
70
71static AMD_FLASH_FILE_MEMORY amd_flash[MAX_FLASH_DEVICES];
72
73
74#if 0
75void   amd_flash_set_interface(int index1, struct amd_flash_interface *interface)
76{
77   if ((index1<0) || (index1>=MAX_FLASH_DEVICES))
78      return;
79
80   memcpy(&amd_flash[index1].interface, interface, sizeof(struct amd_flash_interface));
81}
82
83/* set sector group protection status */
84void   amd_flash_set_sector_group_protection(int index1, int group_index, int is_protected)
85{
86   if ((index1<0) || (index1>=MAX_FLASH_DEVICES))
87      return;
88
89   if ((group_index<0) || (group_index>=7))
90      return;
91
92   amd_flash[index1].sector_group_protection &= ~(1<<group_index);
93   
94   if (is_protected)
95   {
96      amd_flash[index1].sector_group_protection |= (1<<group_index);
97   }
98}
99#endif
100
101
102
103char *amd_flash_get_base(int index1)
104{
105   return amd_flash[index1].base;
106}
107
108
109void   amd_flash_reset(int index1)
110{
111   amd_flash[index1].mode = AMD_FLASH_MODE_READ_ARRAY;
112   amd_flash[index1].amd_autoselect_state = 0;
113}
114   
115void amd_flash_init(int index1)
116{
117   /* all groups are write enabled! */
118   amd_flash[index1].sector_group_protection = 0;
119
120   /* 1mb ram */
121   amd_flash[index1].base = (char *)malloc(1024*1024);
122   if (amd_flash[index1].base!=NULL)
123   {
124      memset(amd_flash[index1].base, 0x080, 1024*1024);
125   }
126   amd_flash_reset(index1);
127}
128
129void amd_flash_finish(int index1)
130{
131   if (amd_flash[index1].base!=NULL)
132   {
133      free(amd_flash[index1].base);
134      amd_flash[index1].base = NULL;
135   }
136}
137
138void amd_flash_store(int index1, const char *flash_name)
139{
140   file_error filerr;
141   mame_file *file;
142
143   if (amd_flash[index1].base!=NULL)
144   {
145      filerr = mame_fopen(SEARCHPATH_MEMCARD, flash_name, OPEN_FLAG_WRITE, &file);
146      if (filerr == FILERR_NONE)
147      {
148         mame_fwrite(file, amd_flash[index1].base, (1024*1024));
149         mame_fclose(file);
150      }
151   }
152}
153
154
155
156void amd_flash_restore(int index1, const char *flash_name)
157{
158   file_error filerr;
159   mame_file *file;
160
161   if (amd_flash[index1].base!=NULL)
162   {
163      filerr = mame_fopen(SEARCHPATH_MEMCARD, flash_name, OPEN_FLAG_READ, &file);
164      if (filerr == FILERR_NONE)
165      {
166         mame_fread(file, amd_flash[index1].base, (1024*1024));
167         mame_fclose(file);
168      }
169   }
170}
171
172
173
174/* flash read - offset is offset within flash-file (offset within 1mb)*/
175int amd_flash_bank_handler_r(int index1, int offset)
176{
177
178   switch (amd_flash[index1].mode)
179   {
180      /* read byte */
181      case AMD_FLASH_MODE_READ_ARRAY:
182         return amd_flash[index1].base[offset];
183
184      case AMD_FLASH_MODE_AUTOSELECT:
185      {
186         logerror("amd flash read: offs: %04x\n",offset);
187         
188         switch (offset & 0x03)
189         {
190            /* get manufacturer code */
191            case 0:
192               return AMD_FLASH_MANUFACTURER_CODE;
193            /* get device code */
194            case 1:
195               return AMD_FLASH_DEVICE_CODE;
196
197            /* get sector protection. 01 = write protected, 00 = write enabled */
198            /* write protection applies to a group of sectors. Each sector is 64k, and
199            each group identifies two consecutive sectors. group 0 contains sector 0 and sector 1 */
200            case 2:
201            {
202               /* A19, A18, A17 define sector group */
203               unsigned long sector_group = (offset>>17) & 0x07;
204
205               /* return bit indicating protection status */
206               return (amd_flash[index1].sector_group_protection>>sector_group) & 0x01;
207            }
208            break;
209         
210            /* 3 - not defined! */
211            default:
212               break;
213         }
214
215      }
216      break;
217   }
218
219   return 0x0ff;
220}
221
222
223static void   amd_autoselect_sequence_update(int index1, int offset, int data)
224{
225   switch (amd_flash[index1].amd_autoselect_state)
226   {
227      case 0:
228      {
229         int addr = offset & 0x07ff;
230         if ((addr==0x0555) && (data==0x0aa))
231         {
232            logerror("amd flash: recognised address 0x0555 and data 0x0aa\n");
233            amd_flash[index1].amd_autoselect_state++;
234         }
235         else
236         {
237            amd_flash[index1].amd_autoselect_state = 0;
238         }
239      }
240      break;
241
242      case 1:
243      {
244         int addr = offset & 0x07ff;
245         if ((addr==0x02aa) && (data==0x055))
246         {
247            logerror("amd flash: recognised address 0x02aa and data 0x055\n");
248            amd_flash[index1].amd_autoselect_state++;
249            amd_flash[index1].mode = AMD_FLASH_MODE_AUTOSELECT;
250         }
251         else
252         {
253            amd_flash[index1].amd_autoselect_state = 0;
254         }
255      }
256      break;
257
258      case 2:
259      {
260         int addr = offset & 0x07ff;
261         amd_flash[index1].amd_autoselect_state = 0;
262
263         if (addr==0x0555)
264         {
265            logerror("amd flash: recognised address 0x0555, command: %02x\n",data);
266
267            switch (data)
268            {
269               /* not sure if this is correct for amd flash! */
270               case AMD_FLASH_COMMAND_RESET:
271               {
272                  /* return to read array */
273                  amd_flash[index1].mode = AMD_FLASH_MODE_READ_ARRAY;
274                  amd_flash[index1].amd_autoselect_state = 0;
275               }
276               break;
277
278               case AMD_FLASH_COMMAND_AUTOSELECT:
279               {
280                  amd_flash[index1].mode = AMD_FLASH_MODE_AUTOSELECT;
281               }
282               break;
283           
284               case AMD_FLASH_COMMAND_BYTE_PROGRAM:
285               {
286                  amd_flash[index1].mode = AMD_FLASH_MODE_BYTE_PROGRAM;
287               }
288               break;
289
290               case AMD_FLASH_COMMAND_ERASE:
291               {
292                  /* reset state */
293                  amd_flash[index1].amd_autoselect_state = 0;
294                  amd_flash[index1].mode = AMD_FLASH_MODE_WAITING_ERASE_TYPE;
295               }
296               break;
297            }
298         }
299      }
300      break;
301   }
302}
303
304
305/* flash write - offset is offset within flash-file (offset within 1mb)*/
306void amd_flash_bank_handler_w(int index1, int offset, int data)
307{
308   logerror("amd flash write: offs: %04x data: %02x\n",offset,data);
309
310//   /* reset? */
311//   if (data==AMD_FLASH_COMMAND_RESET)
312//   {
313//      /* return to read array */
314//      amd_flash[index1].mode = AMD_FLASH_MODE_READ_ARRAY;
315//      amd_flash[index1].amd_autoselect_state = 0;
316//      return;
317//   }
318
319   amd_autoselect_sequence_update(index1, offset, data);
320
321   switch (amd_flash[index1].mode)
322   {
323      case AMD_FLASH_MODE_BYTE_PROGRAM:
324      {
325         /* cannot turn a 0 into 1! */
326
327         /* write the byte */
328         amd_flash[index1].base[offset] &=data;
329      }
330      break;
331
332      default:
333         break;
334   }
335
336}
337
338/*******************************************/
src/mess/mess.mak
r1157r1158
453453   $(MESS_MACHINE)/msm8251.o  \
454454   $(MESS_MACHINE)/tc8521.o   \
455455   $(MESS_VIDEO)/crtc6845.o   \
456   $(MESS_MACHINE)/28f008sa.o \
457   $(MESS_MACHINE)/am29f080.o \
458456   $(MESS_MACHINE)/rriot.o    \
459457   $(MESS_MACHINE)/uart8250.o \
460458   $(MESS_MACHINE)/pc_mouse.o \
src/mess/drivers/pcw16.c
r1157r1158
106106// pcw/pcw16 beeper
107107#include "sound/beep.h"
108108
109#include "includes/28f008sa.h"
109#include "machine/intelfsh.h"
110110
111static void pcw16_machine_stop(running_machine *machine);
112
113111// interrupt counter
114112unsigned long pcw16_interrupt_counter;
115113// video control
r1157r1158
200198/* PCW16 Flash interface */
201199/* PCW16 can have two 1mb flash chips */
202200
201static NVRAM_HANDLER( pcw16 )
202{
203   nvram_handler_intelflash( machine, 0, file, read_or_write );
204   nvram_handler_intelflash( machine, 1, file, read_or_write );
205}
206
203207/* read flash0 */
204208static int pcw16_flash0_bank_handler_r(int bank, int offset)
205209{
206210   int flash_offset = (pcw16_banks[bank]<<14) | offset;
207211
208   return flash_bank_handler_r(0, flash_offset);
212   return intelflash_read(0, flash_offset);
209213}
210214
211215/* read flash1 */
r1157r1158
213217{
214218   int flash_offset = ((pcw16_banks[bank]&0x03f)<<14) | offset;
215219
216   return flash_bank_handler_r(1, flash_offset);
220   return intelflash_read(1, flash_offset);
217221}
218222
219223/* flash 0 */
r1157r1158
279283{
280284   int flash_offset = (pcw16_banks[bank]<<14) | offset;
281285
282   flash_bank_handler_w(0, flash_offset, data);
286   intelflash_write(0, flash_offset, data);
283287}
284288
285289/* read flash1 */
r1157r1158
287291{
288292   int flash_offset = ((pcw16_banks[bank]&0x03f)<<14) | offset;
289293
290   flash_bank_handler_w(1, flash_offset,data);
294   intelflash_write(1, flash_offset,data);
291295}
292296
293297/* flash 0 */
r1157r1158
438442         /* nvram */
439443         if ((bank_id & 0x040)==0)
440444         {
441            mem_ptr = (unsigned char *)flash_get_base(0);
445            mem_ptr = (unsigned char *)intelflash_getmemptr(0);
442446         }
443447         else
444448         {
445            mem_ptr = (unsigned char *)flash_get_base(1);
449            mem_ptr = (unsigned char *)intelflash_getmemptr(1);
446450         }
447451      }
448452
r1157r1158
13251329   pcw16_keyboard_init();
13261330   uart8250_reset(0);
13271331   uart8250_reset(1);
1328   flash_reset(0);
1329   flash_reset(1);
13301332}
13311333
13321334
r1157r1158
13451347
13461348static MACHINE_RESET( pcw16 )
13471349{
1348   /* flash 0 */
1349   flash_init(0);
1350   flash_restore(0, "pcw16f1.nv");
1351
1352   /* flash 1 */
1353   flash_init(1);
1354   flash_restore(1, "pcw16f2.nv");
1355
13561350   pcw16_system_status = 0;
13571351   pcw16_interrupt_counter = 0;
13581352
r1157r1158
13841378
13851379   beep_set_state(0,0);
13861380   beep_set_frequency(0,3750);
1387
1388   add_exit_callback(machine, pcw16_machine_stop);
13891381}
13901382
1391static void pcw16_machine_stop(running_machine *machine)
1392{
1393   /* flash 0 */
1394   flash_store(0,"pcw16f1.nv");
1395   flash_finish(0);
1396
1397   flash_store(1,"pcw16f2.nv");
1398   flash_finish(1);
1399}
1400
14011383INPUT_PORTS_START(pcw16)
14021384   PORT_START
14031385   /* vblank */
r1157r1158
14241406   MDRV_INTERLEAVE(1)
14251407
14261408   MDRV_MACHINE_RESET( pcw16 )
1409   MDRV_NVRAM_HANDLER( pcw16 )
14271410
14281411    /* video hardware */
14291412   MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER)
r1157r1158
14441427MACHINE_DRIVER_END
14451428
14461429
1430static DRIVER_INIT( pcw16 )
1431{
1432   /* init flashes */
1433   intelflash_init(0, FLASH_INTEL_E28F008SA, NULL);
1434   intelflash_init(1, FLASH_INTEL_E28F008SA, NULL);
1435}
1436
14471437/***************************************************************************
14481438
14491439  Game driver(s)
r1157r1158
14931483SYSTEM_CONFIG_END
14941484
14951485/*     YEAR  NAME     PARENT   COMPAT   MACHINE    INPUT     INIT   CONFIG,  COMPANY          FULLNAME */
1496COMP( 1995, pcw16,     0,      0,      pcw16,      pcw16,    0,       pcw16,   "Amstrad plc",   "PCW16", 0)
1486COMP( 1995, pcw16,     0,      0,      pcw16,      pcw16,    pcw16,       pcw16,   "Amstrad plc",   "PCW16", 0)
src/mess/drivers/avigo.c
r1157r1158
3939 ******************************************************************************/
4040#include "driver.h"
4141#include "includes/avigo.h"
42#include "includes/am29f080.h"
42#include "machine/intelfsh.h"
4343#include "includes/tc8521.h"
4444#include "machine/uart8250.h"
4545#include "sound/speaker.h"
r1157r1158
8181static int avigo_flash_at_0x8000;
8282static void *avigo_banked_opbase[4];
8383
84static NVRAM_HANDLER( avigo )
85{
86   int i;
87
88   for (i = 0; i < 3; i++)
89   {
90      nvram_handler_intelflash( machine, i, file, read_or_write );
91   }
92}
93
8494static void avigo_setbank(int bank, void *address, read8_handler rh, write8_handler wh)
8595{
8696   if (address)
r1157r1158
104114/* memory 0x0000-0x03fff */
105115static  READ8_HANDLER(avigo_flash_0x0000_read_handler)
106116{
107   int flash_offset = offset;
108   return amd_flash_bank_handler_r(0, flash_offset);
117   return intelflash_read(0, offset);
109118}
110119
111120/* memory 0x04000-0x07fff */
112121static  READ8_HANDLER(avigo_flash_0x4000_read_handler)
113122{
114
115        int flash_offset = (avigo_rom_bank_l<<14) | offset;
116
117   //   logerror("flash offset: %04x offset: %04x\n",flash_offset, offset);
118
119
120        return amd_flash_bank_handler_r(avigo_flash_at_0x4000, flash_offset);
123   return intelflash_read(avigo_flash_at_0x4000, (avigo_rom_bank_l<<14) | offset);
121124}
122125
123126/* memory 0x0000-0x03fff */
124127static WRITE8_HANDLER(avigo_flash_0x0000_write_handler)
125128{
126
127   int flash_offset = offset;
128
129   amd_flash_bank_handler_w(0, flash_offset, data);
129   intelflash_write(0, offset, data);
130130}
131131
132132/* memory 0x04000-0x07fff */
133133static WRITE8_HANDLER(avigo_flash_0x4000_write_handler)
134134{
135
136        int flash_offset = (avigo_rom_bank_l<<14) | offset;
137
138   //   logerror("flash offset: %04x offset: %04x\n",flash_offset, offset);
139
140        amd_flash_bank_handler_w(avigo_flash_at_0x4000, flash_offset, data);
135   intelflash_write(avigo_flash_at_0x4000, (avigo_rom_bank_l<<14) | offset, data);
141136}
142137
143138/* memory 0x08000-0x0bfff */
144139static  READ8_HANDLER(avigo_flash_0x8000_read_handler)
145140{
146
147        int flash_offset = (avigo_ram_bank_l<<14) | offset;
148
149   //   logerror("flash offset: %04x offset: %04x\n",flash_offset, offset);
150
151        return amd_flash_bank_handler_r(avigo_flash_at_0x8000, flash_offset);
141   return intelflash_read(avigo_flash_at_0x8000, (avigo_rom_bank_l<<14) | offset);
152142}
153143
154144#ifdef UNUSED_FUNCTION
155145/* memory 0x08000-0x0bfff */
156146static WRITE8_HANDLER(avigo_flash_0x8000_write_handler)
157147{
158
159        int flash_offset = (avigo_ram_bank_l<<14) | offset;
160
161   //   logerror("flash offset: %04x offset: %04x\n",flash_offset, offset);
162
163        amd_flash_bank_handler_w(avigo_flash_at_0x8000, flash_offset, data);
148   intelflash_write(avigo_flash_at_0x8000, (avigo_rom_bank_l<<14) | offset, data);
164149}
165150#endif
166151
r1157r1158
327312         break;
328313   }
329314
330   addr = (unsigned char *)amd_flash_get_base(avigo_flash_at_0x4000);
315   addr = (unsigned char *)intelflash_getmemptr(avigo_flash_at_0x4000);
331316   addr = addr + (avigo_rom_bank_l<<14);
332317   avigo_setbank(1, addr, avigo_flash_0x4000_read_handler, avigo_flash_0x4000_write_handler);
333318
r1157r1158
351336         avigo_flash_at_0x8000 = 1;
352337
353338
354         addr = (unsigned char *)amd_flash_get_base(avigo_flash_at_0x8000);
339         addr = (unsigned char *)intelflash_getmemptr(avigo_flash_at_0x8000);
355340         addr = addr + (avigo_ram_bank_l<<14);
356341         avigo_setbank(2, addr, avigo_flash_0x8000_read_handler,
357342            MWA8_NOP /* avigo_flash_0x8000_write_handler */);
r1157r1158
360345      case 0x07:
361346         avigo_flash_at_0x8000 = 0;
362347
363         addr = (unsigned char *)amd_flash_get_base(avigo_flash_at_0x8000);
348         addr = (unsigned char *)intelflash_getmemptr(avigo_flash_at_0x8000);
364349         addr = addr + (avigo_ram_bank_l<<14);
365350         avigo_setbank(2, addr, avigo_flash_0x8000_read_handler,
366351            MWA8_NOP /* avigo_flash_0x8000_write_handler */);
r1157r1158
419404   memset(avigo_banked_opbase, 0, sizeof(avigo_banked_opbase));
420405
421406   /* initialise flash memory */
422   amd_flash_init(0);
423   amd_flash_init(1);
424   amd_flash_init(2);
407   intelflash_init(0, FLASH_INTEL_E28F008SA, memory_region(REGION_CPU1)+0x10000);
408   intelflash_init(1, FLASH_INTEL_E28F008SA, memory_region(REGION_CPU1)+0x100000);
409   intelflash_init(2, FLASH_INTEL_E28F008SA, NULL);
425410
426    /* install os into flash from rom image data */
427   {
428      /* get base of rom data */
429      char *rom = (char *)memory_region(REGION_CPU1)+0x010000;
430      char *flash;
431
432      if (rom!=NULL)
433      {
434         /* copy first 1mb into first flash */
435         flash = (char *)amd_flash_get_base(0);
436         if (flash)
437            memcpy(flash, rom, 0x0100000);
438
439         /* copy second 1mb into second flash */
440         flash = (char *)amd_flash_get_base(1);
441         if (flash)
442            memcpy(flash, rom+0x0100000, 0x0150000-0x0100000);
443      }
444   }
445
446
447411   stylus_marker_x = AVIGO_SCREEN_WIDTH>>1;
448412   stylus_marker_y = AVIGO_SCREEN_HEIGHT>>1;
449413   stylus_press_x = 0;
450414   stylus_press_y = 0;
451415   avigo_vh_set_stylus_marker_position(stylus_marker_x, stylus_marker_y);
452416
453    /* if these files exist, they will overwrite the os installed
454   from the rom in the code above.
455   
456   This is ok. These files will be created by this driver and they will
457    contain the OS data in them! Since these files are in the flash
458   memory they can be written to. */
459
460   
461   amd_flash_restore(0, "avigof1.nv");
462   amd_flash_reset(0);
463
464    amd_flash_restore(1, "avigof2.nv");
465    amd_flash_reset(1);
466
467    amd_flash_restore(2, "avigof3.nv");
468    amd_flash_reset(2);
469
470417   /* initialise settings for port data */
471418   for (i=0; i<4; i++)
472419   {
r1157r1158
493440
494441   memory_set_opbase_handler(0, avigo_opbase_handler);
495442
496   addr = (unsigned char *)amd_flash_get_base(0);
443   addr = (unsigned char *)intelflash_getmemptr(0);
497444   avigo_setbank(0, addr, avigo_flash_0x0000_read_handler, avigo_flash_0x0000_write_handler);
498445
499446   avigo_setbank(3, mess_ram, NULL, NULL);
r1157r1158
502449   avigo_refresh_memory();
503450}
504451
505static void avigo_machine_stop(running_machine *machine)
506{
507   /* store and free flash memory */
508   amd_flash_store(0, "avigof1.nv");
509   amd_flash_finish(0);
510
511   amd_flash_store(1, "avigof2.nv");
512   amd_flash_finish(1);
513
514   amd_flash_store(2, "avigof3.nv");
515   amd_flash_finish(2);
516}
517
518452static MACHINE_START( avigo )
519453{
520454   /* a timer used to check status of pen */
r1157r1158
522456   mame_timer_pulse(MAME_TIME_IN_HZ(50), 0, avigo_dummy_timer_callback);
523457
524458   add_reset_callback(machine, avigo_machine_reset);
525   add_exit_callback(machine, avigo_machine_stop);
526459}
527460
528461
r1157r1158
935868   MDRV_INTERLEAVE(1)
936869
937870   MDRV_MACHINE_START( avigo )
871   MDRV_NVRAM_HANDLER( avigo )
938872
939873    /* video hardware */
940874   MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team