summaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2021-06-22 21:13:03 +1000
committer Vas Crabb <vas@vastheman.com>2021-06-22 21:13:03 +1000
commit0d57290b583603bcfbb21e03093ed76dbbe7efaa (patch)
treedd27d2ed9dcbd63b0f4fda5e3a80670db5e740b4 /src
parent6a6073b26d5cbf8791e8faef4809db9195ada8ee (diff)
cpu/alto2: Fixed allocation widths for decoded ROMs, and removed a bunch of reinterpret_cast.
Diffstat (limited to 'src')
-rw-r--r--src/devices/cpu/alto2/a2disp.cpp6
-rw-r--r--src/devices/cpu/alto2/a2ether.cpp6
-rw-r--r--src/devices/cpu/alto2/a2hw.cpp4
-rw-r--r--src/devices/cpu/alto2/a2mouse.cpp2
-rw-r--r--src/devices/cpu/alto2/a2roms.cpp84
-rw-r--r--src/devices/cpu/alto2/a2roms.h4
-rw-r--r--src/devices/cpu/alto2/alto2cpu.cpp45
-rw-r--r--src/devices/cpu/alto2/alto2cpu.h6
-rw-r--r--src/devices/machine/smartmed.cpp12
9 files changed, 81 insertions, 88 deletions
diff --git a/src/devices/cpu/alto2/a2disp.cpp b/src/devices/cpu/alto2/a2disp.cpp
index 037f0f8f12d..216542cfd67 100644
--- a/src/devices/cpu/alto2/a2disp.cpp
+++ b/src/devices/cpu/alto2/a2disp.cpp
@@ -517,9 +517,9 @@ void alto2_cpu_device::init_disp()
save_item(NAME(m_dsp.xpreg));
save_item(NAME(m_dsp.csr));
- m_disp_a38 = prom_load(machine(), &pl_displ_a38, memregion("displ_a38")->base());
- m_disp_a63 = prom_load(machine(), &pl_displ_a63, memregion("displ_a63")->base());
- m_disp_a66 = prom_load(machine(), &pl_displ_a66, memregion("displ_a66")->base());
+ m_disp_a38 = prom_load<uint8_t>(machine(), &pl_displ_a38, memregion("displ_a38")->base());
+ m_disp_a63 = prom_load<uint8_t>(machine(), &pl_displ_a63, memregion("displ_a63")->base());
+ m_disp_a66 = prom_load<uint8_t>(machine(), &pl_displ_a66, memregion("displ_a66")->base());
m_dsp.hlc = A2_DISP_HLC_START;
diff --git a/src/devices/cpu/alto2/a2ether.cpp b/src/devices/cpu/alto2/a2ether.cpp
index 2c1a3d56a89..5ed7f9b9107 100644
--- a/src/devices/cpu/alto2/a2ether.cpp
+++ b/src/devices/cpu/alto2/a2ether.cpp
@@ -1318,9 +1318,9 @@ void alto2_cpu_device::init_ether(int task)
save_item(NAME(m_eth.tx_count));
save_item(NAME(m_eth.breath_of_life));
- m_ether_a41 = prom_load(machine(), &pl_enet_a41, memregion("ether_a41")->base());
- m_ether_a42 = prom_load(machine(), &pl_enet_a42, memregion("ether_a42")->base());
- m_ether_a49 = prom_load(machine(), &pl_enet_a49, memregion("ether_a49")->base());
+ m_ether_a41 = prom_load<uint8_t>(machine(), &pl_enet_a41, memregion("ether_a41")->base());
+ m_ether_a42 = prom_load<uint8_t>(machine(), &pl_enet_a42, memregion("ether_a42")->base());
+ m_ether_a49 = prom_load<uint8_t>(machine(), &pl_enet_a49, memregion("ether_a49")->base());
m_eth.rx_packet = std::make_unique<uint16_t[]>(sizeof(uint16_t)*ALTO2_ETHER_PACKET_SIZE);
m_eth.tx_packet = std::make_unique<uint16_t[]>(sizeof(uint16_t)*ALTO2_ETHER_PACKET_SIZE);
diff --git a/src/devices/cpu/alto2/a2hw.cpp b/src/devices/cpu/alto2/a2hw.cpp
index acb5c913232..561267fe63c 100644
--- a/src/devices/cpu/alto2/a2hw.cpp
+++ b/src/devices/cpu/alto2/a2hw.cpp
@@ -398,8 +398,8 @@ static const prom_load_t pl_madr_a65 =
void alto2_cpu_device::init_hw()
{
memset(&m_hw, 0, sizeof(m_hw));
- m_madr_a64 = prom_load(machine(), &pl_madr_a64, memregion("madr_a64")->base());
- m_madr_a65 = prom_load(machine(), &pl_madr_a65, memregion("madr_a65")->base());
+ m_madr_a64 = prom_load<uint8_t>(machine(), &pl_madr_a64, memregion("madr_a64")->base());
+ m_madr_a65 = prom_load<uint8_t>(machine(), &pl_madr_a65, memregion("madr_a65")->base());
}
void alto2_cpu_device::exit_hw()
diff --git a/src/devices/cpu/alto2/a2mouse.cpp b/src/devices/cpu/alto2/a2mouse.cpp
index 4ee209e6c1d..677ef24f87c 100644
--- a/src/devices/cpu/alto2/a2mouse.cpp
+++ b/src/devices/cpu/alto2/a2mouse.cpp
@@ -233,7 +233,7 @@ static const prom_load_t pl_madr_a32 =
void alto2_cpu_device::init_mouse()
{
memset(&m_mouse, 0, sizeof(m_mouse));
- m_madr_a32 = prom_load(machine(), &pl_madr_a32, memregion("madr_a32")->base());
+ m_madr_a32 = prom_load<uint8_t>(machine(), &pl_madr_a32, memregion("madr_a32")->base());
}
void alto2_cpu_device::exit_mouse()
diff --git a/src/devices/cpu/alto2/a2roms.cpp b/src/devices/cpu/alto2/a2roms.cpp
index 53decc730a0..fe55ef21f8b 100644
--- a/src/devices/cpu/alto2/a2roms.cpp
+++ b/src/devices/cpu/alto2/a2roms.cpp
@@ -104,17 +104,20 @@ static void write_type_and_xor(void *base, int type, uint32_t addr, uint32_t dan
* @param segments number of segments in one page of the result
* @return pointer to the newly allocated memory filled with source bits
*/
-std::unique_ptr<uint8_t[]> prom_load(running_machine& machine, const prom_load_t* prom, const uint8_t* src, int pages, int segments)
+template <typename T>
+std::unique_ptr<T []> prom_load(running_machine& machine, const prom_load_t* prom, const uint8_t* src, int pages, int segments)
{
- size_t type = prom->type;
- size_t size = prom->size;
+ assert(sizeof(T) == prom->type);
+
+ size_t const size = prom->size;
#if DEBUG_PROM_LOAD
- uint8_t width = prom->width;
+ size_t const type = prom->type;
+ uint8_t const width = prom->width;
#endif
- std::unique_ptr<uint8_t[]> array = std::make_unique<uint8_t[]>(pages * size * type);
+ std::unique_ptr<T []> array = std::make_unique<T []>(pages * size);
- uint8_t* base = array.get();
+ uint8_t* base = reinterpret_cast<uint8_t *>(array.get());
for (int page = 0; page < pages; page++)
{
uint8_t* dst = base + (prom->type * prom->size * page);
@@ -140,47 +143,38 @@ std::unique_ptr<uint8_t[]> prom_load(running_machine& machine, const prom_load_t
}
#if DEBUG_PROM_LOAD
- switch (type) {
- case sizeof(uint8_t):
- {
- uint8_t* data = reinterpret_cast<uint8_t*>(array.get());
- for (int addr = 0; addr < pages*size; addr++) {
- if (0 == (addr % 16))
- printf("%04x:", addr);
- if (width <= 4)
- printf(" %x", data[addr]);
- else
- printf(" %02x", data[addr]);
- if (15 == (addr % 16))
- printf("\n");
- }
+ for (int addr = 0; addr < pages*size; addr++) {
+ switch (type) {
+ case sizeof(uint8_t):
+ if (0 == (addr % 16))
+ printf("%04x:", addr);
+ if (width <= 4)
+ printf(" %x", array[addr]);
+ else
+ printf(" %02x", array[addr]);
+ if (15 == (addr % 16))
+ printf("\n");
+ break;
+ case sizeof(uint16_t):
+ if (0 == (addr % 8))
+ printf("%04x:", addr);
+ printf(" %04x", array[addr]);
+ if (7 == (addr % 8))
+ printf("\n");
+ break;
+ case sizeof(uint32_t):
+ if (0 == (addr % 4))
+ printf("%04x:", addr);
+ printf(" %08x", array[addr]);
+ if (3 == (addr % 4))
+ printf("\n");
+ break;
}
- break;
- case sizeof(uint16_t):
- {
- uint16_t* data = reinterpret_cast<uint16_t*>(array.get());
- for (int addr = 0; addr < pages*size; addr++) {
- if (0 == (addr % 8))
- printf("%04x:", addr);
- printf(" %04x", data[addr]);
- if (7 == (addr % 8))
- printf("\n");
- }
- }
- break;
- case sizeof(uint32_t):
- {
- uint32_t* data = reinterpret_cast<uint32_t*>(array.get());
- for (int addr = 0; addr < pages*size; addr++) {
- if (0 == (addr % 4))
- printf("%04x:", addr);
- printf(" %08x", data[addr]);
- if (3 == (addr % 4))
- printf("\n");
- }
- }
- break;
}
#endif
return array;
}
+
+template std::unique_ptr<uint8_t []> prom_load<uint8_t>(running_machine& machine, const prom_load_t* prom, const uint8_t* src, int pages, int segments);
+template std::unique_ptr<uint16_t []> prom_load<uint16_t>(running_machine& machine, const prom_load_t* prom, const uint8_t* src, int pages, int segments);
+template std::unique_ptr<uint32_t []> prom_load<uint32_t>(running_machine& machine, const prom_load_t* prom, const uint8_t* src, int pages, int segments);
diff --git a/src/devices/cpu/alto2/a2roms.h b/src/devices/cpu/alto2/a2roms.h
index 4fcc010cc80..930732a497f 100644
--- a/src/devices/cpu/alto2/a2roms.h
+++ b/src/devices/cpu/alto2/a2roms.h
@@ -8,6 +8,7 @@
#ifndef MAME_CPU_ALTO2_A2ROMS_H
#define MAME_CPU_ALTO2_A2ROMS_H
+#pragma once
/**
* @brief structure to define a ROM's or PROM's loading options
@@ -38,5 +39,6 @@ typedef struct {
#define DMAP_DEFAULT {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}
#define DMAP_REVERSE_0_3 {3,2,1,0,}
-extern std::unique_ptr<uint8_t[]> prom_load(running_machine& machine, const prom_load_t* prom, const uint8_t* src, int pages = 1, int segments = 1);
+template <typename T> std::unique_ptr<T []> prom_load(running_machine& machine, const prom_load_t* prom, const uint8_t* src, int pages = 1, int segments = 1);
+
#endif // MAME_CPU_ALTO2_A2ROMS_H
diff --git a/src/devices/cpu/alto2/alto2cpu.cpp b/src/devices/cpu/alto2/alto2cpu.cpp
index 43e747e4283..98cba1502d1 100644
--- a/src/devices/cpu/alto2/alto2cpu.cpp
+++ b/src/devices/cpu/alto2/alto2cpu.cpp
@@ -138,8 +138,6 @@ alto2_cpu_device::alto2_cpu_device(const machine_config& mconfig, const char* ta
m_ucode_ram_base(ALTO2_UCODE_PAGE_SIZE),
m_ucode_size(3*ALTO2_UCODE_PAGE_SIZE),
m_sreg_banks(1),
- m_ucode_crom(nullptr),
- m_const_data(nullptr),
m_icount(0),
m_task(0),
m_next_task(0),
@@ -802,24 +800,23 @@ void alto2_cpu_device::device_start()
// Decode 2 pages of micro code PROMs to CROM
// If m_cram_config == 1 or 3, only the first page will be used
- m_ucode_crom = prom_load(machine(), pl_ucode, memregion("ucode_proms")->base(), 2, 8);
+ m_ucode_crom = prom_load<uint32_t>(machine(), pl_ucode, memregion("ucode_proms")->base(), 2, 8);
// allocate micro code CRAM for max 3 pages
- m_ucode_cram = std::make_unique<uint8_t[]>(sizeof(uint32_t) * 3 * ALTO2_UCODE_PAGE_SIZE);
+ m_ucode_cram = std::make_unique<uint32_t []>(3 * ALTO2_UCODE_PAGE_SIZE);
// fill with the micro code inverted bits value
- for (offs_t offset = 0; offset < 3 * ALTO2_UCODE_PAGE_SIZE; offset++)
- *reinterpret_cast<uint32_t *>(m_ucode_cram.get() + offset * 4) = ALTO2_UCODE_INVERTED;
+ std::fill_n(m_ucode_cram.get(), 3 * ALTO2_UCODE_PAGE_SIZE, ALTO2_UCODE_INVERTED);
// decode constant PROMs to m_const_data
- m_const_data = prom_load(machine(), pl_const, memregion("const_proms")->base(), 1, 4);
+ m_const_data = prom_load<uint16_t>(machine(), pl_const, memregion("const_proms")->base(), 1, 4);
- m_ctl2k_u3 = prom_load(machine(), &pl_2kctl_u3, memregion("2kctl_u3")->base());
- m_ctl2k_u38 = prom_load(machine(), &pl_2kctl_u38, memregion("2kctl_u38")->base());
- m_ctl2k_u76 = prom_load(machine(), &pl_2kctl_u76, memregion("2kctl_u76")->base());
- m_alu_a10 = prom_load(machine(), &pl_alu_a10, memregion("alu_a10")->base());
- m_cram3k_a37 = prom_load(machine(), &pl_3kcram_a37, memregion("3kcram_a37")->base());
- m_madr_a90 = prom_load(machine(), &pl_madr_a90, memregion("madr_a90")->base());
- m_madr_a91 = prom_load(machine(), &pl_madr_a91, memregion("madr_a91")->base());
+ m_ctl2k_u3 = prom_load<uint8_t>(machine(), &pl_2kctl_u3, memregion("2kctl_u3")->base());
+ m_ctl2k_u38 = prom_load<uint8_t>(machine(), &pl_2kctl_u38, memregion("2kctl_u38")->base());
+ m_ctl2k_u76 = prom_load<uint8_t>(machine(), &pl_2kctl_u76, memregion("2kctl_u76")->base());
+ m_alu_a10 = prom_load<uint8_t>(machine(), &pl_alu_a10, memregion("alu_a10")->base());
+ m_cram3k_a37 = prom_load<uint8_t>(machine(), &pl_3kcram_a37, memregion("3kcram_a37")->base());
+ m_madr_a90 = prom_load<uint8_t>(machine(), &pl_madr_a90, memregion("madr_a90")->base());
+ m_madr_a91 = prom_load<uint8_t>(machine(), &pl_madr_a91, memregion("madr_a91")->base());
#if DEBUG_ALU_A10_PROM
// dump ALU a10 PROM after loading
@@ -1009,28 +1006,28 @@ void alto2_cpu_device::state_string_export(const device_state_entry &entry, std:
uint32_t alto2_cpu_device::crom_cram_r(offs_t offset)
{
if (offset < m_ucode_ram_base)
- return *reinterpret_cast<uint32_t *>(m_ucode_crom.get() + offset * 4);
- return *reinterpret_cast<uint32_t *>(m_ucode_cram.get() + (offset - m_ucode_ram_base) * 4);
+ return m_ucode_crom[offset];
+ else
+ return m_ucode_cram[offset - m_ucode_ram_base];
}
//! write microcode CROM or CRAM (CROM of course can't be written)
void alto2_cpu_device::crom_cram_w(offs_t offset, uint32_t data)
{
- if (offset < m_ucode_ram_base)
- return;
- *reinterpret_cast<uint32_t *>(m_ucode_cram.get() + (offset - m_ucode_ram_base) * 4) = data;
+ if (offset >= m_ucode_ram_base)
+ m_ucode_cram[offset - m_ucode_ram_base] = data;
}
//! read constants PROM
uint16_t alto2_cpu_device::const_r(offs_t offset)
{
- return *reinterpret_cast<uint16_t *>(m_const_data.get() + offset * 2);
+ return m_const_data[offset];
}
//! direct read access to the microcode CROM or CRAM
-#define RD_UCODE(addr) (addr < m_ucode_ram_base ? \
- *reinterpret_cast<uint32_t *>(m_ucode_crom.get() + addr * 4) : \
- *reinterpret_cast<uint32_t *>(m_ucode_cram.get() + (addr - m_ucode_ram_base) * 4))
+#define RD_UCODE(addr) (((addr) < m_ucode_ram_base) ? \
+ m_ucode_crom[addr] : \
+ m_ucode_cram[(addr) - m_ucode_ram_base])
//-------------------------------------------------
// device_reset - device-specific reset
@@ -2338,7 +2335,7 @@ void alto2_cpu_device::execute_run()
// The constant memory is gated to the bus by F1 == f1_const, F2 == f2_const, or BS >= 4
if (!do_bs || bs() >= bs_task_4) {
const uint32_t addr = 8 * m_rsel + bs();
- const uint16_t data = m_const_data[2*addr] | (m_const_data[2*addr+1] << 8);
+ const uint16_t data = m_const_data[addr];
m_bus &= data;
LOG((this,LOG_CPU,2," %#o; BUS &= %#o CONST[%03o]\n", m_bus, data, addr));
}
diff --git a/src/devices/cpu/alto2/alto2cpu.h b/src/devices/cpu/alto2/alto2cpu.h
index 3d1216beaed..1e4ee84375e 100644
--- a/src/devices/cpu/alto2/alto2cpu.h
+++ b/src/devices/cpu/alto2/alto2cpu.h
@@ -251,9 +251,9 @@ private:
uint32_t m_ucode_size; //!< Size of both, CROM and CRAM together
uint32_t m_sreg_banks; //!< Number of S register banks; derived from m_cram_config
- std::unique_ptr<uint8_t[]> m_ucode_crom;
- std::unique_ptr<uint8_t[]> m_ucode_cram;
- std::unique_ptr<uint8_t[]> m_const_data;
+ std::unique_ptr<uint32_t[]> m_ucode_crom;
+ std::unique_ptr<uint32_t[]> m_ucode_cram;
+ std::unique_ptr<uint16_t[]> m_const_data;
void ucode_map(address_map &map);
void const_map(address_map &map);
diff --git a/src/devices/machine/smartmed.cpp b/src/devices/machine/smartmed.cpp
index 0a7c8911571..ebf51159519 100644
--- a/src/devices/machine/smartmed.cpp
+++ b/src/devices/machine/smartmed.cpp
@@ -305,20 +305,20 @@ void smartmedia_image_device::call_unload()
{
if (custom_header.version == 0)
{
- fseek( 2 + 1, SEEK_CUR);
- fwrite( m_feeprom_data, m_page_total_size * m_num_pages);
+ fseek(2 + 1, SEEK_CUR);
+ fwrite(m_feeprom_data, m_page_total_size * m_num_pages);
}
else if (custom_header.version == 1)
{
- fseek( 3 + 1 + 256 + 16, SEEK_CUR);
- fwrite( m_feeprom_data, m_page_total_size * m_num_pages);
+ fseek(3 + 1 + 256 + 16, SEEK_CUR);
+ fwrite(m_feeprom_data, m_page_total_size * m_num_pages);
}
}
}
else if (m_image_format == 2)
{
- fseek( sizeof( disk_image_format_2_header), SEEK_SET);
- fwrite( m_feeprom_data, m_page_total_size * m_num_pages);
+ fseek(sizeof(disk_image_format_2_header), SEEK_SET);
+ fwrite(m_feeprom_data, m_page_total_size * m_num_pages);
}
}
#endif