Previous 199869 Revisions Next

r22576 Saturday 27th April, 2013 at 12:36:16 UTC by smf
frees the buffer after a quickload (nw)
[src/mess/drivers]cd2650.c

trunk/src/mess/drivers/cd2650.c
r22575r22576
172172   int quick_length;
173173   UINT8 *quick_data;
174174   int read_;
175   int result = IMAGE_INIT_FAIL;
175176
176177   quick_length = image.length();
177178   quick_data = (UINT8*)malloc(quick_length);
r22575r22576
179180   {
180181      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file");
181182      image.message(" Cannot open file");
182      return IMAGE_INIT_FAIL;
183183   }
184
185   read_ = image.fread( quick_data, quick_length);
186   if (read_ != quick_length)
184   else
187185   {
188      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file");
189      image.message(" Cannot read the file");
190      return IMAGE_INIT_FAIL;
191   }
186      read_ = image.fread( quick_data, quick_length);
187      if (read_ != quick_length)
188      {
189         image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file");
190         image.message(" Cannot read the file");
191      }
192      else if (quick_data[0] != 0x40)
193      {
194         image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header");
195         image.message(" Invalid header");
196      }
197      else
198      {
199         exec_addr = quick_data[1] * 256 + quick_data[2];
192200
193   if (quick_data[0] != 0x40)
194   {
195      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header");
196      image.message(" Invalid header");
197      return IMAGE_INIT_FAIL;
198   }
201         if (exec_addr >= quick_length)
202         {
203            image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Exec address beyond end of file");
204            image.message(" Exec address beyond end of file");
205         }
206         else if (quick_length < 0x0444)
207         {
208            image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too short");
209            image.message(" File too short");
210         }
211         else if (quick_length > 0x8000)
212         {
213            image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too long");
214            image.message(" File too long");
215         }
216         else
217         {
218            read_ = 0x1000;
219            if (quick_length < 0x1000)
220               read_ = quick_length;
199221
200   exec_addr = quick_data[1] * 256 + quick_data[2];
222            for (i = quick_addr; i < read_; i++)
223               space.write_byte(i, quick_data[i]);
201224
202   if (exec_addr >= quick_length)
203   {
204      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Exec address beyond end of file");
205      image.message(" Exec address beyond end of file");
206      return IMAGE_INIT_FAIL;
207   }
225            read_ = 0x1780;
226            if (quick_length < 0x1780)
227               read_ = quick_length;
208228
209   if (quick_length < 0x0444)
210   {
211      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too short");
212      image.message(" File too short");
213      return IMAGE_INIT_FAIL;
214   }
229            if (quick_length > 0x157f)
230               for (i = 0x1580; i < read_; i++)
231                  space.write_byte(i, quick_data[i]);
215232
216   if (quick_length > 0x8000)
217   {
218      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too long");
219      image.message(" File too long");
220      return IMAGE_INIT_FAIL;
221   }
233            if (quick_length > 0x17ff)
234               for (i = 0x1800; i < quick_length; i++)
235                  space.write_byte(i, quick_data[i]);
222236
223   read_ = 0x1000;
224   if (quick_length < 0x1000)
225      read_ = quick_length;
237            /* display a message about the loaded quickload */
238            image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr);
226239
227   for (i = quick_addr; i < read_; i++)
228      space.write_byte(i, quick_data[i]);
240            // Start the quickload
241            m_maincpu->set_pc(exec_addr);
229242
230   read_ = 0x1780;
231   if (quick_length < 0x1780)
232      read_ = quick_length;
243            result = IMAGE_INIT_PASS;
244         }
245      }
233246
234   if (quick_length > 0x157f)
235      for (i = 0x1580; i < read_; i++)
236         space.write_byte(i, quick_data[i]);
247      free( quick_data );
248   }
237249
238   if (quick_length > 0x17ff)
239      for (i = 0x1800; i < quick_length; i++)
240         space.write_byte(i, quick_data[i]);
241
242   /* display a message about the loaded quickload */
243   image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr);
244
245   // Start the quickload
246   m_maincpu->set_pc(exec_addr);
247   return IMAGE_INIT_PASS;
250   return result;
248251}
249252
250253static MACHINE_CONFIG_START( cd2650, cd2650_state )

Previous 199869 Revisions Next


© 1997-2024 The MAME Team