Previous 199869 Revisions Next

r30864 Friday 6th June, 2014 at 14:47:45 UTC by Michael Zapf
(MESS) ti99: replaced malloc by global_alloc_array (nw)
[src/mess/machine/ti99]gromport.c gromport.h

trunk/src/mess/machine/ti99/gromport.c
r30863r30864
11441144   if (m_pcb->m_grom_size > 0)
11451145   {
11461146      regg = memregion(CARTGROM_TAG);
1147      grom_ptr = m_softlist? get_software_region("grom_socket") : (UINT8*)m_rpk->get_contents_of_socket("grom_socket");
1147      grom_ptr = m_softlist? get_software_region("grom_socket") : m_rpk->get_contents_of_socket("grom_socket");
11481148      memcpy(regg->base(), grom_ptr, m_pcb->m_grom_size);
11491149      m_pcb->m_grom_ptr = regg->base();   // for gromemu
11501150      m_pcb->m_grom_address = 0;          // for gromemu
r30863r30864
11621162   {
11631163      if (VERBOSE>6) LOG("gromport: rom_socket.size=0x%04x\n", m_pcb->m_rom_size);
11641164      regr = memregion(CARTROM_TAG);
1165      m_pcb->m_rom_ptr = m_softlist? get_software_region("rom_socket") : (UINT8*)m_rpk->get_contents_of_socket("rom_socket");
1165      m_pcb->m_rom_ptr = m_softlist? get_software_region("rom_socket") : m_rpk->get_contents_of_socket("rom_socket");
11661166      memcpy(regr->base(), m_pcb->m_rom_ptr, m_pcb->m_rom_size);
11671167      // Set both pointers to the same region for now
11681168      m_pcb->m_rom_ptr = m_pcb->m_rom2_ptr = regr->base();
r30863r30864
11731173   {
11741174      // sizes do not differ between rom and rom2
11751175      regr2 = memregion(CARTROM2_TAG);
1176      m_pcb->m_rom2_ptr = m_softlist? get_software_region("rom2_socket") : (UINT8*)m_rpk->get_contents_of_socket("rom2_socket");
1176      m_pcb->m_rom2_ptr = m_softlist? get_software_region("rom2_socket") : m_rpk->get_contents_of_socket("rom2_socket");
11771177      memcpy(regr2->base(), m_pcb->m_rom2_ptr, rom2_length);
11781178      m_pcb->m_rom2_ptr = regr2->base();
11791179   }
r30863r30864
11851185      if (m_pcb->m_ram_size > 0)
11861186      {
11871187         // TODO: Consider to use a region as well. If so, do not forget to memcpy.
1188         m_pcb->m_ram_ptr = (UINT8*)m_rpk->get_contents_of_socket("ram_socket");
1188         m_pcb->m_ram_ptr = m_rpk->get_contents_of_socket("ram_socket");
11891189      }
11901190   }
11911191}
r30863r30864
20762076/*
20772077    Deliver the contents of the socket by name of the socket.
20782078*/
2079void* rpk::get_contents_of_socket(const char *socket_name)
2079UINT8* rpk::get_contents_of_socket(const char *socket_name)
20802080{
20812081   rpk_socket *socket = m_sockets.find(socket_name);
20822082   if (socket==NULL) return NULL;
r30863r30864
21232123    not a network socket)
21242124***************************************************************/
21252125
2126rpk_socket::rpk_socket(const char* id, int length, void* contents, const char *pathname)
2126rpk_socket::rpk_socket(const char* id, int length, UINT8* contents, const char *pathname)
21272127: m_id(id), m_length(length), m_next(NULL), m_contents(contents), m_pathname(pathname)
21282128{
21292129};
21302130
2131rpk_socket::rpk_socket(const char* id, int length, void* contents)
2131rpk_socket::rpk_socket(const char* id, int length, UINT8* contents)
21322132: m_id(id), m_length(length), m_next(NULL), m_contents(contents), m_pathname(NULL)
21332133{
21342134};
r30863r30864
21712171   zip_error ziperr;
21722172   UINT32 crc;
21732173   int length;
2174   void* contents;
2174   UINT8* contents;
21752175   const zip_file_header *header;
21762176
21772177   // find the file attribute (required)
r30863r30864
21972197   length = header->uncompressed_length;
21982198
21992199   // Allocate storage
2200   contents = malloc(length);
2200   contents = global_alloc_array_clear(UINT8, length);
22012201   if (contents==NULL) throw rpk_exception(RPK_OUT_OF_MEMORY);
22022202
22032203   // and unzip file from the zip file
r30863r30864
22312231   const char* ram_filename;
22322232   const char* ram_pname;
22332233   int length;
2234   void* contents;
2234   UINT8* contents;
22352235
22362236   // find the length attribute
22372237   length_string = xml_get_attribute_string(ram_resource_node, "length", NULL);
r30863r30864
22592259   }
22602260
22612261   // Allocate memory for this resource
2262   contents = malloc(length);
2262   contents = global_alloc_array_clear(UINT8, length);
22632263   if (contents==NULL) throw rpk_exception(RPK_OUT_OF_MEMORY);
22642264
22652265   if (VERBOSE>6) LOG("gromport/RPK: Allocating RAM buffer (%d bytes) for socket '%s'\n", length, socketname);
r30863r30864
22782278         ram_filename = xml_get_attribute_string(ram_resource_node, "file", NULL);
22792279         if (ram_filename==NULL)
22802280         {
2281            free(contents);
2281            global_free_array(contents);
22822282            throw rpk_exception(RPK_INVALID_RAM_SPEC, "<ram type='persistent'> must have a 'file' attribute");
22832283         }
22842284         astring ram_pathname(system_name, PATH_SEPARATOR, ram_filename);
trunk/src/mess/machine/ti99/gromport.h
r30863r30864
406406   friend class rpk;
407407
408408public:
409   rpk_socket(const char *id, int length, void *contents);
410   rpk_socket(const char *id, int length, void *contents, const char *pathname);
409   rpk_socket(const char *id, int length, UINT8 *contents);
410   rpk_socket(const char *id, int length, UINT8 *contents, const char *pathname);
411411
412412   const char*     id() { return m_id; }
413413   int             get_content_length() { return m_length; }
414   void*           get_contents() { return m_contents; }
414   UINT8*          get_contents() { return m_contents; }
415415   bool            persistent_ram() { return m_pathname != NULL; }
416416   const char*     get_pathname() { return m_pathname; }
417   void            cleanup() { if (m_contents != NULL) free(m_contents); }
417   void            cleanup() { if (m_contents != NULL) global_free_array(m_contents); }
418418
419419private:
420   const char      *m_id;
420   const char*     m_id;
421421   UINT32          m_length;
422   rpk_socket      *m_next;
423   void            *m_contents;
424   const char      *m_pathname;
422   rpk_socket*     m_next;
423   UINT8*          m_contents;
424   const char*     m_pathname;
425425};
426426
427427class rpk_reader
r30863r30864
447447   ~rpk();
448448
449449   int         get_type(void) { return m_type; }
450   void*       get_contents_of_socket(const char *socket_name);
450   UINT8*      get_contents_of_socket(const char *socket_name);
451451   int         get_resource_length(const char *socket_name);
452452   void        close();
453453

Previous 199869 Revisions Next


© 1997-2024 The MAME Team