Previous 199869 Revisions Next

r22579 Saturday 27th April, 2013 at 15:03:48 UTC by Robbbert
(MESS) pipbug, binbug, instruct: fixed memory leak
[src/mess/drivers]binbug.c instruct.c pipbug.c

trunk/src/mess/drivers/binbug.c
r22578r22579
222222{
223223   address_space &space = m_maincpu->space(AS_PROGRAM);
224224   int i;
225   int quick_addr = 0x0440;
225   int quick_addr = 0x440;
226226   int exec_addr;
227227   int quick_length;
228228   UINT8 *quick_data;
229229   int read_;
230   int result = IMAGE_INIT_FAIL;
230231
231232   quick_length = image.length();
232   quick_data = (UINT8*)malloc(quick_length);
233   if (!quick_data)
233   if (quick_length < 0x0444)
234234   {
235      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file");
236      image.message(" Cannot open file");
237      return IMAGE_INIT_FAIL;
235      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too short");
236      image.message(" File too short");
238237   }
239
240   read_ = image.fread( quick_data, quick_length);
241   if (read_ != quick_length)
238   else if (quick_length > 0x8000)
242239   {
243      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file");
244      image.message(" Cannot read the file");
245      return IMAGE_INIT_FAIL;
240      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too long");
241      image.message(" File too long");
246242   }
247
248   if (quick_data[0] != 0xc4)
243   else
249244   {
250      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header");
251      image.message(" Invalid header");
252      return IMAGE_INIT_FAIL;
253   }
245      quick_data = (UINT8*)malloc(quick_length);
246      if (!quick_data)
247      {
248         image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file");
249         image.message(" Cannot open file");
250      }
251      else
252      {
253         read_ = image.fread( quick_data, quick_length);
254         if (read_ != quick_length)
255         {
256            image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file");
257            image.message(" Cannot read the file");
258         }
259         else if (quick_data[0] != 0xc4)
260         {
261            image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header");
262            image.message(" Invalid header");
263         }
264         else
265         {
266            exec_addr = quick_data[1] * 256 + quick_data[2];
254267
255   exec_addr = quick_data[1] * 256 + quick_data[2];
268            if (exec_addr >= quick_length)
269            {
270               image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Exec address beyond end of file");
271               image.message(" Exec address beyond end of file");
272            }
273            else
274            {
275               for (i = quick_addr; i < read_; i++)
276                  space.write_byte(i, quick_data[i]);
256277
257   if (exec_addr >= quick_length)
258   {
259      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Exec address beyond end of file");
260      image.message(" Exec address beyond end of file");
261      return IMAGE_INIT_FAIL;
262   }
278               /* display a message about the loaded quickload */
279               image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr);
263280
264   if (quick_length < 0x444)
265   {
266      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too short");
267      image.message(" File too short");
268      return IMAGE_INIT_FAIL;
269   }
281               // Start the quickload
282               m_maincpu->set_pc(exec_addr);
270283
271   if (quick_length > 0x8000)
272   {
273      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too long");
274      image.message(" File too long");
275      return IMAGE_INIT_FAIL;
276   }
284               result = IMAGE_INIT_PASS;
285            }
286         }
287      }
277288
278   for (i = quick_addr; i < quick_length; i++)
279   {
280      space.write_byte(i, quick_data[i]);
289      free( quick_data );
281290   }
282291
283   /* display a message about the loaded quickload */
284   image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr);
285
286   // Start the quickload
287   m_maincpu->set_pc(exec_addr);
288   return IMAGE_INIT_PASS;
292   return result;
289293}
290294
291295static MACHINE_CONFIG_START( binbug, binbug_state )
r22578r22579
3603640x0C = enable; 0x0E = protect). There are 256 pages so
361365each page is 256 bytes.
362366
363To turn the clock on (if it was working), put a non-zero
364into D80D.
367The clock is controlled by the byte in D80D.
365368
366369Monitor Commands:
367370C (compare)*
trunk/src/mess/drivers/instruct.c
r22578r22579
231231{
232232   address_space &space = m_maincpu->space(AS_PROGRAM);
233233   int i;
234   int quick_addr = 0x0100;
234   int quick_addr = 0x100;
235235   int exec_addr;
236236   int quick_length;
237237   UINT8 *quick_data;
238238   int read_;
239   int result = IMAGE_INIT_FAIL;
239240
240241   quick_length = image.length();
241   quick_data = (UINT8*)malloc(quick_length);
242   if (!quick_data)
242   if (quick_length < 0x0104)
243243   {
244      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file");
245      image.message(" Cannot open file");
246      return IMAGE_INIT_FAIL;
244      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too short");
245      image.message(" File too short");
247246   }
248
249   read_ = image.fread( quick_data, quick_length);
250   if (read_ != quick_length)
247   else if (quick_length > 0x17c0)
251248   {
252      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file");
253      image.message(" Cannot read the file");
254      return IMAGE_INIT_FAIL;
249      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too long");
250      image.message(" File too long");
255251   }
256
257   if (quick_data[0] != 0xc5)
252   else
258253   {
259      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header");
260      image.message(" Invalid header");
261      return IMAGE_INIT_FAIL;
262   }
254      quick_data = (UINT8*)malloc(quick_length);
255      if (!quick_data)
256      {
257         image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file");
258         image.message(" Cannot open file");
259      }
260      else
261      {
262         read_ = image.fread( quick_data, quick_length);
263         if (read_ != quick_length)
264         {
265            image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file");
266            image.message(" Cannot read the file");
267         }
268         else if (quick_data[0] != 0xc5)
269         {
270            image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header");
271            image.message(" Invalid header");
272         }
273         else
274         {
275            exec_addr = quick_data[1] * 256 + quick_data[2];
263276
264   exec_addr = quick_data[1] * 256 + quick_data[2];
277            if (exec_addr >= quick_length)
278            {
279               image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Exec address beyond end of file");
280               image.message(" Exec address beyond end of file");
281            }
282            else
283            {
284               for (i = quick_addr; i < read_; i++)
285                  space.write_byte(i, quick_data[i]);
265286
266   if (exec_addr >= quick_length)
267   {
268      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Exec address beyond end of file");
269      image.message(" Exec address beyond end of file");
270      return IMAGE_INIT_FAIL;
271   }
287               /* display a message about the loaded quickload */
288               image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr);
272289
273   if (quick_length < 0x104)
274   {
275      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too short");
276      image.message(" File too short");
277      return IMAGE_INIT_FAIL;
278   }
290               // Start the quickload
291               m_maincpu->set_pc(exec_addr);
279292
280   if (quick_length > 0x17c0)
281   {
282      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too long");
283      image.message(" File too long");
284      return IMAGE_INIT_FAIL;
285   }
293               result = IMAGE_INIT_PASS;
294            }
295         }
296      }
286297
287   for (i = quick_addr; i < quick_length; i++)
288   {
289      space.write_byte(i, quick_data[i]);
298      free( quick_data );
290299   }
291300
292   /* display a message about the loaded quickload */
293   image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr);
294
295   // Start the quickload
296   m_maincpu->set_pc(exec_addr);
297   return IMAGE_INIT_PASS;
301   return result;
298302}
299303
300304static MACHINE_CONFIG_START( instruct, instruct_state )
trunk/src/mess/drivers/pipbug.c
r22578r22579
9797{
9898   address_space &space = m_maincpu->space(AS_PROGRAM);
9999   int i;
100   int quick_addr = 0x0440;
100   int quick_addr = 0x440;
101101   int exec_addr;
102102   int quick_length;
103103   UINT8 *quick_data;
104104   int read_;
105   int result = IMAGE_INIT_FAIL;
105106
106107   quick_length = image.length();
107   quick_data = (UINT8*)malloc(quick_length);
108   if (!quick_data)
108   if (quick_length < 0x0444)
109109   {
110      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file");
111      image.message(" Cannot open file");
112      return IMAGE_INIT_FAIL;
110      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too short");
111      image.message(" File too short");
113112   }
114
115   read_ = image.fread( quick_data, quick_length);
116   if (read_ != quick_length)
113   else if (quick_length > 0x8000)
117114   {
118      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file");
119      image.message(" Cannot read the file");
120      return IMAGE_INIT_FAIL;
115      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too long");
116      image.message(" File too long");
121117   }
122
123   if (quick_data[0] != 0xc4)
118   else
124119   {
125      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header");
126      image.message(" Invalid header");
127      return IMAGE_INIT_FAIL;
128   }
120      quick_data = (UINT8*)malloc(quick_length);
121      if (!quick_data)
122      {
123         image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file");
124         image.message(" Cannot open file");
125      }
126      else
127      {
128         read_ = image.fread( quick_data, quick_length);
129         if (read_ != quick_length)
130         {
131            image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file");
132            image.message(" Cannot read the file");
133         }
134         else if (quick_data[0] != 0xc4)
135         {
136            image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header");
137            image.message(" Invalid header");
138         }
139         else
140         {
141            exec_addr = quick_data[1] * 256 + quick_data[2];
129142
130   exec_addr = quick_data[1] * 256 + quick_data[2];
143            if (exec_addr >= quick_length)
144            {
145               image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Exec address beyond end of file");
146               image.message(" Exec address beyond end of file");
147            }
148            else
149            {
150               for (i = quick_addr; i < read_; i++)
151                  space.write_byte(i, quick_data[i]);
131152
132   if (exec_addr >= quick_length)
133   {
134      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Exec address beyond end of file");
135      image.message(" Exec address beyond end of file");
136      return IMAGE_INIT_FAIL;
137   }
153               /* display a message about the loaded quickload */
154               image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr);
138155
139   if (quick_length < 0x444)
140   {
141      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too short");
142      image.message(" File too short");
143      return IMAGE_INIT_FAIL;
144   }
156               // Start the quickload
157               m_maincpu->set_pc(exec_addr);
145158
146   if (quick_length > 0x8000)
147   {
148      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too long");
149      image.message(" File too long");
150      return IMAGE_INIT_FAIL;
151   }
159               result = IMAGE_INIT_PASS;
160            }
161         }
162      }
152163
153   for (i = quick_addr; i < quick_length; i++)
154   {
155      space.write_byte(i, quick_data[i]);
164      free( quick_data );
156165   }
157166
158   /* display a message about the loaded quickload */
159   image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr);
160
161   // Start the quickload
162   m_maincpu->set_pc(exec_addr);
163   return IMAGE_INIT_PASS;
167   return result;
164168}
165169
166170static MACHINE_CONFIG_START( pipbug, pipbug_state )

Previous 199869 Revisions Next


© 1997-2024 The MAME Team