Previous 199869 Revisions Next

r26230 Sunday 17th November, 2013 at 14:10:29 UTC by Jürgen Buchmüller
Use auto_alloc_array() and remove non-automatic memory deallocation
[/branches/alto2/src/emu/cpu/alto2]a2disk.c a2disp.c a2ether.c a2mem.c a2mouse.c a2roms.c a2roms.h alto2.c alto2.h
[/branches/alto2/src/emu/machine]diablo_hd.c

branches/alto2/src/emu/machine/diablo_hd.c
r26229r26230
109109 */
110110diablo_hd_device::~diablo_hd_device()
111111{
112   for (int page = 0; page < m_pages; page++) {
113      if (m_cache && m_cache[page])
114         global_free(m_cache[page]);
115      if (m_bits && m_bits[page])
116         global_free(m_bits[page]);
117   }
118   if (m_cache) {
119      global_free(m_cache);
120      m_cache = 0;
121   }
122   if (m_bits) {
123      global_free(m_bits);
124      m_bits = 0;
125   }
126112}
127113
128114#if   DIABLO_DEBUG
r26229r26230
323309   }
324310
325311   /* allocate a buffer for this page */
326   m_cache[m_page] = global_alloc_array(UINT8, sizeof(diablo_sector_t));
312   m_cache[m_page] = auto_alloc_array(machine(), UINT8, sizeof(diablo_sector_t));
327313   /* and read the page from the hard_disk image */
328314   if (hard_disk_read(m_disk, m_page, m_cache[m_page])) {
329315      LOG_DRIVE((2,"[DHD%u]   C/H/S:%d/%d/%d => page:%d loaded\n", m_unit, m_cylinder, m_head, m_sector, m_page));
330316   } else {
331317      LOG_DRIVE((0,"[DHD%u]   C/H/S:%d/%d/%d => page:%d read failed\n", m_unit, m_cylinder, m_head, m_sector, m_page));
332      global_free(m_cache[m_page]);
318      auto_free(machine(), m_cache[m_page]);
333319      m_cache[m_page] = 0;
334320   }
335321}
r26229r26230
453439   diablo_sector_t *s = reinterpret_cast<diablo_sector_t *>(m_cache[m_page]);
454440
455441   /* allocate a bits image */
456   UINT32 *bits = reinterpret_cast<UINT32 *>(global_alloc_array(UINT32, 400));
442   UINT32 *bits = reinterpret_cast<UINT32 *>(auto_alloc_array(machine(), UINT32, 400));
457443
458444   if (m_diablo31) {
459445      /* write sync bit after 31 words - 1 bit */
r26229r26230
784770      LOG_DRIVE((0,"[DHD%u]   cksum check - header:%06o label:%06o data:%06o\n", m_unit, cksum_header, cksum_label, cksum_data));
785771#endif
786772   }
787   global_free(m_bits[m_page]);
773   auto_free(machine(), m_bits[m_page]);
788774   m_bits[m_page] = 0;
789775
790776   if (!hard_disk_write(m_disk, m_page, m_cache[m_page])) {
r26229r26230
11521138   int bit = 0;
11531139
11541140   if (m_rdgate_0) {
1155      LOG_DRIVE((8,"[DHD%u]   rdgate not asserted\n", m_unit));
1141      LOG_DRIVE((0,"[DHD%u]   rdgate not asserted\n", m_unit));
11561142      return 1;   // read gate is not asserted (active 0)
11571143   }
11581144
r26229r26230
11961182
11971183   if (index < 0 || index >= bits_per_sector()) {
11981184      LOG_DRIVE((0,"[DHD%u]   index out of range (%d)\n", m_unit, index));
1199      return 1;   // don't read before or beyond the sector
1185      return 0;   // don't read before or beyond the sector
12001186   }
12011187
12021188   if (0 == m_sector_mark_0) {
12031189      LOG_DRIVE((0,"[DHD%u]   read while sector mark is asserted\n", m_unit));
1204      return 1;   // no clock while sector mark is low (?)
1190      return 0;   // no clock while sector mark is low (?)
12051191   }
12061192
12071193   if (-1 == m_page) {
12081194      LOG_DRIVE((0,"[DHD%u]   invalid page\n", m_unit));
1209      return 1;   // invalid page
1195      return 0;   // invalid page
12101196   }
12111197
12121198   UINT32 *bits = expand_sector();
r26229r26230
12681254   m_packs = 1;      // FIXME: get from configuration?
12691255   m_unit = strstr(m_image->tag(), "diablo0") ? 0 : 1;
12701256
1271   m_cache = global_alloc_array(UINT8*, DIABLO_PAGES);
1257   m_cache = auto_alloc_array(machine(), UINT8*, DIABLO_PAGES);
12721258   memset(m_cache, 0, sizeof(UINT8*) * DIABLO_PAGES);
1273   m_bits = global_alloc_array(UINT32*, DIABLO_PAGES);
1259   m_bits = auto_alloc_array(machine(), UINT32*, DIABLO_PAGES);
12741260   memset(m_bits, 0, sizeof(UINT32*) * DIABLO_PAGES);
12751261
12761262   m_timer = timer_alloc(1, 0);
branches/alto2/src/emu/cpu/alto2/a2mem.c
r26229r26230
783783   memset(&m_mem, 0, sizeof(m_mem));
784784
785785   // allocate 128KB of main memory
786   m_mem.ram = global_alloc_array(UINT32, sizeof(UINT16)*ALTO2_RAM_SIZE);
786   m_mem.ram = auto_alloc_array(machine(), UINT32, sizeof(UINT16)*ALTO2_RAM_SIZE);
787787   memset(m_mem.ram, 0, sizeof(UINT32)*sizeof(UINT16)*ALTO2_RAM_SIZE);
788   m_mem.hpb = global_alloc_array(UINT8,  sizeof(UINT16)*ALTO2_RAM_SIZE);
788   m_mem.hpb = auto_alloc_array(machine(), UINT8,  sizeof(UINT16)*ALTO2_RAM_SIZE);
789789   memset(m_mem.hpb, 0, sizeof(UINT8)*sizeof(UINT16)*ALTO2_RAM_SIZE);
790790
791791   /**
r26229r26230
845845
846846void alto2_cpu_device::exit_memory()
847847{
848   if (m_mem.hpb) {
849      global_free(m_mem.hpb);
850      m_mem.hpb = 0;
851   }
852   if (m_mem.ram) {
853      global_free(m_mem.ram);
854      m_mem.ram = 0;
855   }
848   // nothing to do yet
856849}
branches/alto2/src/emu/cpu/alto2/a2roms.c
r26229r26230
9898 * @param segments number of segments in one page of the result
9999 * @return pointer to the newly allocated memory filled with source bits
100100 */
101UINT8* prom_load(const prom_load_t* prom, const UINT8* src, int pages, int segments)
101UINT8* prom_load(running_machine& machine, const prom_load_t* prom, const UINT8* src, int pages, int segments)
102102{
103103   void* array = 0;
104104   size_t type = prom->type;
r26229r26230
109109
110110   switch (type) {
111111   case sizeof(UINT8):
112      array = global_alloc_array(UINT8, pages * size);
112      array = auto_alloc_array(machine, UINT8, pages * size);
113113      break;
114114   case sizeof(UINT16):
115      array = global_alloc_array(UINT16, pages * size);
115      array = auto_alloc_array(machine, UINT16, pages * size);
116116      break;
117117   case sizeof(UINT32):
118      array = global_alloc_array(UINT32, pages * size);
118      array = auto_alloc_array(machine, UINT32, pages * size);
119119      break;
120120   }
121121
branches/alto2/src/emu/cpu/alto2/a2roms.h
r26229r26230
3232#define   DMAP_DEFAULT      {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}
3333#define   DMAP_REVERSE_0_3   {3,2,1,0,}
3434
35extern UINT8* prom_load(const prom_load_t* prom, const UINT8* src, int pages = 1, int segments = 1);
35extern UINT8* prom_load(running_machine& machine, const prom_load_t* prom, const UINT8* src, int pages = 1, int segments = 1);
3636#endif // _CPU_A2ROMS_H_
branches/alto2/src/emu/cpu/alto2/a2mouse.c
r26229r26230
208208
209209void alto2_cpu_device::exit_mouse()
210210{
211    if (m_madr_a32)
212        global_free(m_madr_a32);
213    m_madr_a32 = 0;
211    // nothing to do yet
214212}
branches/alto2/src/emu/cpu/alto2/a2disk.c
r26229r26230
915915 *  TW_SECLATE   (46*ALTO2_UCYCLE)
916916 *  TW_SECLATE   8596
917917 */
918#define TW_SECLATE  85960
918#define TW_SECLATE  (50*ALTO2_UCYCLE)
919919
920920/** @brief monoflop 52b pulse duration
921921 * Rt = 20k, Cext = 0.01µF (=10000pF) => 57960ns (~58us)
r26229r26230
22212221{
22222222   (void)ptr;
22232223   diablo_hd_device* dhd = m_drive[m_dsk.drive];
2224   int bits = dhd->bits_per_sector();
22252224   int clk = arg & 1;
22262225   int bit = 0;
22272226
r26229r26230
22662265   }
22672266
22682267   /* more bits to clock? */
2269   if (++arg < bits) {
2268   if (++arg < dhd->bits_per_sector()) {
22702269#if   USE_BITCLK_TIMER
22712270      m_dsk.bitclk_timer->adjust(dhd->bit_time(), arg);
22722271#else
22732272      if (!m_dsk.bitclk_time)
22742273         m_dsk.bitclk_time = static_cast<int>(dhd->bit_time().as_double() * ATTOSECONDS_PER_NANOSECOND);
22752274      m_bitclk_time += m_dsk.bitclk_time;
2275      m_bitclk_index = arg;
22762276#endif
22772277   } else {
22782278      // stop the bitclock timer
branches/alto2/src/emu/cpu/alto2/alto2.c
r26229r26230
187187   exit_disp();
188188   exit_disk();
189189   exit_memory();
190
191   if (m_ucode_crom) {
192      global_free(m_ucode_crom);
193      m_ucode_crom = 0;
194   }
195   if (m_ucode_cram) {
196      global_free(m_ucode_cram);
197      m_ucode_cram = 0;
198   }
199   if (m_const_data) {
200      global_free(m_const_data);
201      m_const_data = 0;
202   }
203
204   if (m_ctl2k_u3) {
205      global_free(m_ctl2k_u3);
206      m_ctl2k_u3 = 0;
207   }
208   if (m_ctl2k_u38) {
209      global_free(m_ctl2k_u38);
210      m_ctl2k_u38 = 0;
211   }
212   if (m_ctl2k_u76) {
213      global_free(m_ctl2k_u76);
214      m_ctl2k_u76 = 0;
215   }
216   if (m_cram3k_a37) {
217      global_free(m_cram3k_a37);
218      m_cram3k_a37 = 0;
219   }
220   if (m_madr_a64) {
221      global_free(m_madr_a64);
222      m_madr_a64 = 0;
223   }
224   if (m_madr_a65) {
225      global_free(m_madr_a65);
226      m_madr_a65 = 0;
227   }
228   if (m_madr_a90) {
229      global_free(m_madr_a90);
230      m_madr_a90 = 0;
231   }
232   if (m_madr_a91) {
233      global_free(m_madr_a91);
234      m_madr_a91 = 0;
235   }
236   if (m_alu_a10) {
237      global_free(m_alu_a10);
238      m_alu_a10 = 0;
239   }
240
241190}
242191
243192#if   ALTO2_DEBUG
r26229r26230
1018967   m_iomem = &space(AS_2);
1019968
1020969   // decode micro code PROMs to CROM
1021   m_ucode_crom = prom_load(pl_ucode, memregion("ucode_proms")->base(), ALTO2_UCODE_ROM_PAGES, 8);
970   m_ucode_crom = prom_load(machine(), pl_ucode, memregion("ucode_proms")->base(), ALTO2_UCODE_ROM_PAGES, 8);
1022971
1023972   // allocate micro code CRAM
1024   m_ucode_cram = global_alloc_array(UINT8, sizeof(UINT32) * ALTO2_UCODE_RAM_PAGES * ALTO2_UCODE_PAGE_SIZE);
973   m_ucode_cram = auto_alloc_array(machine(), UINT8, sizeof(UINT32) * ALTO2_UCODE_RAM_PAGES * ALTO2_UCODE_PAGE_SIZE);
1025974   // fill with inverted bits value
1026975   for (offs_t offset = 0; offset < ALTO2_UCODE_RAM_PAGES * ALTO2_UCODE_PAGE_SIZE; offset++)
1027976      *reinterpret_cast<UINT32 *>(m_ucode_cram + offset * 4) = ALTO2_UCODE_INVERTED;
1028977
1029978   // decode constant PROMs to const data
1030   m_const_data = prom_load(pl_const, memregion("const_proms")->base(), 1, 4);
979   m_const_data = prom_load(machine(), pl_const, memregion("const_proms")->base(), 1, 4);
1031980
1032   m_disp_a38 = prom_load(&pl_displ_a38, memregion("displ_a38")->base());
1033   m_disp_a63 = prom_load(&pl_displ_a63, memregion("displ_a63")->base());
1034   m_disp_a66 = prom_load(&pl_displ_a66, memregion("displ_a66")->base());
1035   m_ctl2k_u3 = prom_load(&pl_2kctl_u3, memregion("2kctl_u3")->base());
1036   m_ctl2k_u38 = prom_load(&pl_2kctl_u38, memregion("2kctl_u38")->base());
1037   m_ctl2k_u76 = prom_load(&pl_2kctl_u76, memregion("2kctl_u76")->base());
1038   m_alu_a10 = prom_load(&pl_alu_a10, memregion("alu_a10")->base());
1039   m_cram3k_a37 = prom_load(&pl_3kcram_a37, memregion("3kcram_a37")->base());
1040   m_madr_a32 = prom_load(&pl_madr_a32, memregion("madr_a32")->base());
1041   m_madr_a64 = prom_load(&pl_madr_a64, memregion("madr_a64")->base());
1042   m_madr_a65 = prom_load(&pl_madr_a65, memregion("madr_a65")->base());
1043   m_madr_a90 = prom_load(&pl_madr_a90, memregion("madr_a90")->base());
1044   m_madr_a91 = prom_load(&pl_madr_a91, memregion("madr_a91")->base());
1045   m_ether_a41 = prom_load(&pl_enet_a41, memregion("ether_a41")->base());
1046   m_ether_a42 = prom_load(&pl_enet_a42, memregion("ether_a42")->base());
1047   m_ether_a49 = prom_load(&pl_enet_a49, memregion("ether_a49")->base());
981   m_disp_a38 = prom_load(machine(), &pl_displ_a38, memregion("displ_a38")->base());
982   m_disp_a63 = prom_load(machine(), &pl_displ_a63, memregion("displ_a63")->base());
983   m_disp_a66 = prom_load(machine(), &pl_displ_a66, memregion("displ_a66")->base());
984   m_ctl2k_u3 = prom_load(machine(), &pl_2kctl_u3, memregion("2kctl_u3")->base());
985   m_ctl2k_u38 = prom_load(machine(), &pl_2kctl_u38, memregion("2kctl_u38")->base());
986   m_ctl2k_u76 = prom_load(machine(), &pl_2kctl_u76, memregion("2kctl_u76")->base());
987   m_alu_a10 = prom_load(machine(), &pl_alu_a10, memregion("alu_a10")->base());
988   m_cram3k_a37 = prom_load(machine(), &pl_3kcram_a37, memregion("3kcram_a37")->base());
989   m_madr_a32 = prom_load(machine(), &pl_madr_a32, memregion("madr_a32")->base());
990   m_madr_a64 = prom_load(machine(), &pl_madr_a64, memregion("madr_a64")->base());
991   m_madr_a65 = prom_load(machine(), &pl_madr_a65, memregion("madr_a65")->base());
992   m_madr_a90 = prom_load(machine(), &pl_madr_a90, memregion("madr_a90")->base());
993   m_madr_a91 = prom_load(machine(), &pl_madr_a91, memregion("madr_a91")->base());
994   m_ether_a41 = prom_load(machine(), &pl_enet_a41, memregion("ether_a41")->base());
995   m_ether_a42 = prom_load(machine(), &pl_enet_a42, memregion("ether_a42")->base());
996   m_ether_a49 = prom_load(machine(), &pl_enet_a49, memregion("ether_a49")->base());
1048997
1049998   save_item(NAME(m_task_mpc));
1050999   save_item(NAME(m_task_next2));
r26229r26230
27012650          */
27022651         m_bitclk_time -= ALTO2_UCYCLE;
27032652         disk_bitclk(0, m_bitclk_index);
2704         m_bitclk_index++;
27052653      }
27062654#endif
27072655
branches/alto2/src/emu/cpu/alto2/a2disp.c
r26229r26230
439439{
440440   memset(&m_dsp, 0, sizeof(m_dsp));
441441   m_dsp.hlc = ALTO2_DISPLAY_HLC_START;
442   m_dsp.raw_bitmap = global_alloc_array(UINT16, ALTO2_DISPLAY_HEIGHT * ALTO2_DISPLAY_SCANLINE_WORDS);
442   m_dsp.raw_bitmap = auto_alloc_array(machine(), UINT16, ALTO2_DISPLAY_HEIGHT * ALTO2_DISPLAY_SCANLINE_WORDS);
443443   for (int y = 0; y < ALTO2_DISPLAY_HEIGHT; y++)
444444      memset(m_dsp.raw_bitmap + y * ALTO2_DISPLAY_SCANLINE_WORDS, 0, ALTO2_DISPLAY_VISIBLE_WORDS * sizeof(UINT16));
445445
446   m_dsp.scanline_dirty = global_alloc_array(UINT8, ALTO2_DISPLAY_HEIGHT);
446   m_dsp.scanline_dirty = auto_alloc_array(machine(), UINT8, ALTO2_DISPLAY_HEIGHT);
447447   memset(m_dsp.scanline_dirty, 1, sizeof(UINT8) * ALTO2_DISPLAY_HEIGHT);
448448}
449449
450450void alto2_cpu_device::exit_disp()
451451{
452   if (m_dsp.scanline_dirty) {
453      global_free(m_dsp.scanline_dirty);
454      m_dsp.scanline_dirty = 0;
455   }
456   if (m_dsp.raw_bitmap) {
457      global_free(m_dsp.raw_bitmap);
458      m_dsp.raw_bitmap = 0;
459   }
460   if (m_disp_a38) {
461      global_free(m_disp_a38);
462      m_disp_a38 = 0;
463   }
464   if (m_disp_a63) {
465      global_free(m_disp_a63);
466      m_disp_a63 = 0;
467   }
468   if (m_disp_a66) {
469      global_free(m_disp_a66);
470      m_disp_a66 = 0;
471   }
452   // nothing to do yet
472453}
473454
474455#define   BLACK   1
branches/alto2/src/emu/cpu/alto2/alto2.h
r26229r26230
2626#define   USE_PRIO_F9318         0   //!< define to 1 to use the F9318 priority encoder code
2727#define   USE_ALU_74181         0   //!< define to 1 to use the SN74181 ALU code
2828#define   DEBUG_DISPLAY_TIMING   0   //!< define to 1 to debug the display timing
29#define   USE_BITCLK_TIMER      0   //!< define to 1 to use a very high rate timer for the disk bit clock
29#define   USE_BITCLK_TIMER      1   //!< define to 1 to use a very high rate timer for the disk bit clock
3030#define   ALTO2_HAMMING_CHECK      0   //!< define to 1 to incorporate the Hamming code and Parity check
3131
3232#define   ALTO2_TASKS      16         //!< 16 task slots
branches/alto2/src/emu/cpu/alto2/a2ether.c
r26229r26230
678678
679679void alto2_cpu_device::exit_ether()
680680{
681   if (m_ether_a41) {
682      global_free(m_ether_a41);
683      m_ether_a41 = 0;
684   }
685   if (m_ether_a42) {
686      global_free(m_ether_a42);
687      m_ether_a42 = 0;
688   }
689   if (m_ether_a49) {
690      global_free(m_ether_a49);
691      m_ether_a49 = 0;
692   }
681   // nothing to do yet
693682}
694683

Previous 199869 Revisions Next


© 1997-2024 The MAME Team