diff options
Diffstat (limited to 'src')
33 files changed, 1475 insertions, 933 deletions
diff --git a/src/devices/machine/ds1386.cpp b/src/devices/machine/ds1386.cpp new file mode 100644 index 00000000000..91a6e2f9c06 --- /dev/null +++ b/src/devices/machine/ds1386.cpp @@ -0,0 +1,594 @@ +// license:BSD-3-Clause +// copyright-holders:Ryan Holtz +/********************************************************************** + + Dallas DS1386/DS1386P RAMified Watchdog Timekeeper + + Note: Largely untested. + +**********************************************************************/ + +#include "ds1386.h" +#include "machine/timehelp.h" + +#define DISABLE_OSC (0x80) +#define DISABLE_SQW (0x40) + +#define COMMAND_TE (0x80) +#define COMMAND_IPSW (0x40) +#define COMMAND_IBH_LO (0x20) +#define COMMAND_PU_LVL (0x10) +#define COMMAND_WAM (0x08) +#define COMMAND_TDM (0x04) +#define COMMAND_WAF (0x02) +#define COMMAND_TDF (0x01) + +#define HOURS_12_24 (0x40) +#define HOURS_AM_PM (0x20) + +const device_type DS1386_8K = &device_creator<ds1386_8k_device>; +const device_type DS1386_32K = &device_creator<ds1386_32k_device>; + +ds1386_device::ds1386_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, size_t size) + : device_t(mconfig, type, name, tag, owner, clock, shortname, __FILE__) + , device_nvram_interface(mconfig, *this) + , m_tod_alarm(0) + , m_watchdog_alarm(0) + , m_square(1) + , m_inta_cb(*this) + , m_intb_cb(*this) + , m_sqw_cb(*this) + , m_clock_timer(nullptr) + , m_square_timer(nullptr) + , m_watchdog_timer(nullptr) + , m_inta_timer(nullptr) + , m_intb_timer(nullptr) + , m_default_data(*this, DEVICE_SELF, size) + , m_hundredths(0) + , m_seconds(0) + , m_minutes(0) + , m_minutes_alarm(0) + , m_hours(0) + , m_hours_alarm(0) + , m_days(0) + , m_days_alarm(0) + , m_date(0) + , m_months_enables(0) + , m_years(0) + , m_ram_size(size) +{ +} + +ds1386_8k_device::ds1386_8k_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : ds1386_device(mconfig, DS1386_8K, "DS1386-8K", tag, owner, clock, "ds1386_8k", 8192) +{ +} + +ds1386_32k_device::ds1386_32k_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : ds1386_device(mconfig, DS1386_32K, "DS1386-32K", tag, owner, clock, "ds1386_32k", 32768) +{ +} + +void ds1386_device::safe_inta_cb(int state) +{ + if (!m_inta_cb.isnull()) + m_inta_cb(state); +} + +void ds1386_device::safe_intb_cb(int state) +{ + if (!m_intb_cb.isnull()) + m_intb_cb(state); +} + +void ds1386_device::safe_sqw_cb(int state) +{ + if (!m_sqw_cb.isnull()) + m_sqw_cb(state); +} + +void ds1386_device::device_start() +{ + m_inta_cb.resolve(); + m_intb_cb.resolve(); + m_sqw_cb.resolve(); + + m_tod_alarm = 0; + m_watchdog_alarm = 0; + m_square = 1; + + safe_inta_cb(0); + safe_intb_cb(0); + safe_sqw_cb(1); + + // allocate timers + m_clock_timer = timer_alloc(CLOCK_TIMER); + m_clock_timer->adjust(attotime::from_hz(100), 0, attotime::from_hz(100)); + m_square_timer = timer_alloc(SQUAREWAVE_TIMER); + m_square_timer->adjust(attotime::never); + m_watchdog_timer = timer_alloc(WATCHDOG_TIMER); + m_watchdog_timer->adjust(attotime::never); + m_inta_timer= timer_alloc(INTA_TIMER); + m_inta_timer->adjust(attotime::never); + m_intb_timer= timer_alloc(INTB_TIMER); + m_intb_timer->adjust(attotime::never); + + set_current_time(); + + // state saving + save_item(NAME(m_tod_alarm)); + save_item(NAME(m_watchdog_alarm)); + save_item(NAME(m_square)); + + m_ram = std::make_unique<UINT8[]>(m_ram_size); + memset(&m_ram[0], 0, m_ram_size); +} + +void ds1386_device::device_reset() +{ + m_tod_alarm = 0; + m_watchdog_alarm = 0; + m_square = 1; + + safe_inta_cb(0); + safe_intb_cb(0); + safe_sqw_cb(1); + + m_clock_timer->adjust(attotime::from_hz(100), 0, attotime::from_hz(100)); + m_square_timer->adjust(attotime::never); + m_watchdog_timer->adjust(attotime::never); + + set_current_time(); +} + + +void ds1386_device::set_current_time() +{ + system_time systime; + machine().base_datetime(systime); + + m_hundredths = 0; + m_seconds = time_helper::make_bcd(systime.local_time.second); + m_minutes = time_helper::make_bcd(systime.local_time.minute); + m_hours = time_helper::make_bcd(systime.local_time.hour); + m_days = time_helper::make_bcd(systime.local_time.weekday + 1); + m_date = time_helper::make_bcd(systime.local_time.mday); + m_months_enables = time_helper::make_bcd(systime.local_time.month + 1); + m_years = time_helper::make_bcd(systime.local_time.year % 100); +} + +void ds1386_device::time_of_day_alarm() +{ + m_ram[REGISTER_COMMAND] |= COMMAND_TDF; + m_tod_alarm = 1; + + if (m_ram[REGISTER_COMMAND] & COMMAND_IPSW) + { + safe_inta_cb(m_tod_alarm); + if (m_ram[REGISTER_COMMAND] & COMMAND_PU_LVL) + { + m_inta_timer->adjust(attotime::from_msec(3)); + } + } + else + { + safe_intb_cb(m_tod_alarm); + if (m_ram[REGISTER_COMMAND] & COMMAND_PU_LVL) + { + m_intb_timer->adjust(attotime::from_msec(3)); + } + } +} + +void ds1386_device::watchdog_alarm() +{ + m_ram[REGISTER_COMMAND] |= COMMAND_WAF; + m_watchdog_alarm = 1; + + if (m_ram[REGISTER_COMMAND] & COMMAND_IPSW) + { + safe_intb_cb(m_watchdog_alarm); + if (m_ram[REGISTER_COMMAND] & COMMAND_PU_LVL) + { + m_intb_timer->adjust(attotime::from_msec(3)); + } + } + else + { + safe_inta_cb(m_watchdog_alarm); + if (m_ram[REGISTER_COMMAND] & COMMAND_PU_LVL) + { + m_inta_timer->adjust(attotime::from_msec(3)); + } + } +} + +void ds1386_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) +{ + switch (id) + { + case CLOCK_TIMER: + advance_hundredths(); + break; + + case SQUAREWAVE_TIMER: + m_square = ((m_square == 0) ? 1 : 0); + safe_sqw_cb(m_square); + break; + + case WATCHDOG_TIMER: + if ((m_ram[REGISTER_COMMAND] & COMMAND_WAF) == 0) + watchdog_alarm(); + break; + + case INTA_TIMER: + if (m_ram[REGISTER_COMMAND] & COMMAND_IPSW) + { + m_tod_alarm = 0; + } + else + { + m_watchdog_alarm = 0; + } + safe_inta_cb(0); + break; + + case INTB_TIMER: + if (m_ram[REGISTER_COMMAND] & COMMAND_IPSW) + { + m_watchdog_alarm = 0; + } + else + { + m_tod_alarm = 0; + } + safe_intb_cb(0); + break; + } +} + +void ds1386_device::advance_hundredths() +{ + if ((m_ram[REGISTER_COMMAND] & COMMAND_TE) != 0) + { + copy_ram_to_registers(); + } + + int carry = time_helper::inc_bcd(&m_hundredths, 0xff, 0x00, 0x99); + if (carry) + { + carry = time_helper::inc_bcd(&m_seconds, 0x7f, 0x00, 0x59); + } + if (carry) + { + carry = time_helper::inc_bcd(&m_minutes, 0x7f, 0x00, 0x59); + } + if (carry) + { + UINT8 value = 0; + UINT8 min_value = 0; + UINT8 max_value = 0; + if (m_hours & HOURS_12_24) + { + value = m_hours & 0x1f; + min_value = 0x01; + max_value = 0x12; + } + else + { + value = m_hours & 0x3f; + min_value = 0x00; + max_value = 0x23; + } + carry = time_helper::inc_bcd(&value, 0x1f, min_value, max_value); + + m_hours &= ~0x1f; + if (carry) + { + if (m_hours & HOURS_12_24) + { + if (m_hours & HOURS_AM_PM) + carry = 1; + else + carry = 0; + + m_hours = m_hours ^ HOURS_AM_PM; + } + else + { + m_hours &= ~0x3f; + } + } + else + { + if ((m_hours & HOURS_12_24) == 0) + m_hours &= ~0x3f; + } + m_hours |= value; + } + + if (carry) + { + UINT8 maxdays; + static const UINT8 daysinmonth[] = { 0x31, 0x28, 0x31, 0x30, 0x31, 0x30, 0x31, 0x31, 0x30, 0x31, 0x30, 0x31 }; + + time_helper::inc_bcd(&m_days, 0x07, 0x01, 0x07); + + UINT8 month = time_helper::from_bcd(m_months_enables); + UINT8 year = time_helper::from_bcd(m_years); + + if (month == 2 && (year % 4) == 0) + { + maxdays = 0x29; + } + else if (month >= 1 && month <= 12) + { + maxdays = daysinmonth[month - 1]; + } + else + { + maxdays = 0x31; + } + + carry = time_helper::inc_bcd(&m_date, 0x3f, 0x01, maxdays); + } + if (carry) + { + UINT8 enables = m_months_enables & 0xc0; + carry = time_helper::inc_bcd(&m_months_enables, 0x1f, 0x01, 0x12); + m_months_enables &= 0x3f; + m_months_enables |= enables; + } + if (carry) + { + carry = time_helper::inc_bcd(&m_years, 0xff, 0x00, 0x99); + } + + if ((m_ram[REGISTER_COMMAND] & COMMAND_TE) != 0) + { + copy_registers_to_ram(); + } + + check_tod_alarm(); +} + +void ds1386_device::copy_ram_to_registers() +{ + m_hundredths = m_ram[REGISTER_HUNDREDTHS]; + m_seconds = m_ram[REGISTER_SECONDS]; + m_minutes = m_ram[REGISTER_MINUTES]; + m_hours = m_ram[REGISTER_HOURS]; + m_days = m_ram[REGISTER_DAYS]; + m_date = m_ram[REGISTER_DATE]; + m_months_enables = m_ram[REGISTER_MONTHS]; + m_years = m_ram[REGISTER_YEARS]; +} + +void ds1386_device::copy_registers_to_ram() +{ + m_ram[REGISTER_HUNDREDTHS] = m_hundredths; + m_ram[REGISTER_SECONDS] = m_seconds; + m_ram[REGISTER_MINUTES] = m_minutes; + m_ram[REGISTER_HOURS] = m_hours; + m_ram[REGISTER_DAYS] = m_days; + m_ram[REGISTER_DATE] = m_date; + m_ram[REGISTER_MONTHS] = m_months_enables; + m_ram[REGISTER_YEARS] = m_years; +} + +void ds1386_device::check_tod_alarm() +{ + UINT8 mode = BIT(m_days_alarm, 7) | (BIT(m_hours_alarm, 5) << 1) | (BIT(m_minutes_alarm, 3) << 2); + bool zeroes = (m_hundredths == 0 && m_seconds == 0); + if (zeroes && (m_ram[REGISTER_COMMAND] & COMMAND_TDF) == 0) + { + bool minutes_match = (m_minutes & 0x7f) == (m_minutes_alarm & 0x7f); + bool hours_match = (m_hours & 0x7f) == (m_hours_alarm & 0x7f); + bool days_match = (m_days & 0x7) == (m_days_alarm & 0x07); + bool alarm_match = false; + switch (mode) + { + case ALARM_PER_MINUTE: + alarm_match = true; + break; + case ALARM_MINUTES_MATCH: + alarm_match = minutes_match; + break; + case ALARM_HOURS_MATCH: + alarm_match = hours_match; + break; + case ALARM_DAYS_MATCH: + alarm_match = days_match; + break; + default: + break; + } + if (alarm_match) + { + time_of_day_alarm(); + } + } +} + +void ds1386_device::nvram_default() +{ + memset(&m_ram[0], 0, m_ram_size); +} + +void ds1386_device::nvram_read(emu_file &file) +{ + file.read(&m_ram[0], m_ram_size); +} + +void ds1386_device::nvram_write(emu_file &file) +{ + file.write(&m_ram[0], m_ram_size); +} + +WRITE8_MEMBER( ds1386_device::data_w ) +{ + if (offset >= m_ram_size) + return; + + if (offset >= 0xe) + { + m_ram[offset] = data; + } + else + { + switch (offset) + { + case 0x00: // hundredths + case 0x03: // minutes alarm + case 0x05: // horus alarm + case 0x0a: // years + m_ram[offset] = data; + break; + + case 0x01: // seconds + case 0x02: // minutes + case 0x04: // hours + m_ram[offset] = data & 0x7f; + break; + + case 0x06: // days + m_ram[offset] = data & 0x07; + break; + + case 0x07: // days alarm + m_ram[offset] = data & 0x87; + break; + + case 0x08: // date + m_ram[offset] = data & 0x3f; + break; + + case 0x09: // months + { + UINT8 old_value = m_ram[offset]; + m_ram[offset] = data & 0xdf; + UINT8 changed = old_value ^ data; + if (changed & DISABLE_SQW) + { + if (m_ram[offset] & DISABLE_SQW) + { + m_square_timer->adjust(attotime::never); + } + else + { + m_square_timer->adjust(attotime::from_hz(2048)); + } + } + if (changed & DISABLE_OSC) + { + if (m_ram[offset] & DISABLE_OSC) + { + m_clock_timer->adjust(attotime::never); + } + else + { + m_clock_timer->adjust(attotime::from_hz(100)); + } + } + break; + } + + case 0x0c: // watchdog hundredths + case 0x0d: // watchdog seconds + { + if ((m_ram[REGISTER_COMMAND] & COMMAND_WAF) != 0 && (m_ram[REGISTER_COMMAND] & COMMAND_WAM) == 0) + { + m_ram[REGISTER_COMMAND] &= ~COMMAND_WAF; + m_watchdog_alarm = 0; + if (m_ram[REGISTER_COMMAND] & COMMAND_IPSW) + safe_intb_cb(0); + else + safe_inta_cb(0); + } + m_ram[offset] = data; + UINT8 wd_hundredths = m_ram[REGISTER_WATCHDOG_HUNDREDTHS]; + UINT8 wd_seconds = m_ram[REGISTER_WATCHDOG_SECONDS]; + int total_hundredths = (wd_hundredths & 0xf) + ((wd_hundredths >> 4) & 0xf) * 10 + (wd_seconds & 0xf) * 100 + ((wd_seconds >> 4) & 0xf) * 1000; + m_watchdog_timer->adjust(attotime::from_msec(total_hundredths * 10)); + break; + } + + case 0x0b: // command + { + UINT8 old = m_ram[offset]; + m_ram[offset] = data & 0xfc; + UINT8 changed = old ^ m_ram[offset]; + if (changed & COMMAND_IPSW) + { + int old_a = (old & COMMAND_IPSW) ? m_tod_alarm : m_watchdog_alarm; + int old_b = (old & COMMAND_IPSW) ? m_watchdog_alarm : m_tod_alarm; + int new_a = old_b; + int new_b = old_a; + + bool a_changed = old_a != new_a; + bool b_changed = old_b != new_b; + + std::swap(m_tod_alarm, m_watchdog_alarm); + + if (a_changed) + { + if (m_ram[offset] & COMMAND_IPSW) + safe_inta_cb(m_tod_alarm); + else + safe_inta_cb(m_watchdog_alarm); + } + if (b_changed) + { + if (m_ram[offset] & COMMAND_IPSW) + safe_intb_cb(m_watchdog_alarm); + else + safe_intb_cb(m_tod_alarm); + } + } + if (changed & COMMAND_WAM) + { + if (m_ram[offset] & COMMAND_WAF) + { + if (m_ram[offset] & COMMAND_IPSW) + safe_intb_cb(0); + else + safe_inta_cb(0); + } + else if (m_watchdog_alarm) + { + if (m_ram[offset] & COMMAND_IPSW) + safe_intb_cb(m_watchdog_alarm); + else + safe_inta_cb(m_watchdog_alarm); + } + } + if (changed & COMMAND_TDM) + { + if (m_ram[offset] & COMMAND_TDF) + { + if (m_ram[offset] & COMMAND_IPSW) + safe_inta_cb(0); + else + safe_intb_cb(0); + } + else if (m_tod_alarm) + { + if (m_ram[offset] & COMMAND_IPSW) + safe_inta_cb(m_tod_alarm); + else + safe_intb_cb(m_tod_alarm); + } + } + break; + } + } + } +} + +READ8_MEMBER( ds1386_device::data_r ) +{ + if (offset >= m_ram_size) + return 0; + + return m_ram[offset]; +} diff --git a/src/devices/machine/ds1386.h b/src/devices/machine/ds1386.h new file mode 100644 index 00000000000..1146416b923 --- /dev/null +++ b/src/devices/machine/ds1386.h @@ -0,0 +1,210 @@ +// license:BSD-3-Clause +// copyright-holders:Ryan Holtz +/********************************************************************** + + Dallas DS1386/DS1386P RAMified Watchdog Timekeeper + +*********************************************************************** + _____________ + /INTA 1 | | 32 Vcc + /INTB 2 | | 31 SQW + NC/A14 3 | | 30 Vcc + A12 4 | | 29 /WE + A7 5 | | 28 NC/A13 + A6 6 | | 27 A8 + A5 7 | | 26 A9 + A4 8 | | 25 A11 + A3 9 | | 24 /OE + A2 10 | | 23 A10 + A1 11 | | 22 /CE + A0 12 | | 21 DQ7 + DQ0 13 | | 20 DQ6 + DQ1 14 | | 19 DQ5 + DQ2 15 | | 18 DQ4 + GND 16 |_____________| 17 DQ3 + + DS1386 8k/32k x 8 + + __________________________________ + / | + / | + /INTB | 1 34 | /INTA + NC | 2 33 | SQW + NC | 3 32 | NC/A13 + /PFO | 4 31 | NC/A14 + Vcc | 5 30 | A12 + /WE | 6 29 | A11 + /OE | 7 28 | A10 + /CE | 8 27 | A9 + DQ7 | 9 26 | A8 + DQ6 | 10 25 | A7 + DQ5 | 11 24 | A6 + DQ4 | 12 23 | A5 + DQ3 | 13 22 | A4 + DQ2 | 14 X1 GND Vbat X2 21 | A3 + DQ1 | 15 ____ ____ ____ ____ 20 | A2 + DQ0 | 16 | | | | | | | | 19 | A1 + GND | 17 |____| |____| |____| |____| 18 | A0 + |____________________________________| + + DS1386 8k/32k x 8, 34-Pin PowerCap Module Board + +**********************************************************************/ + +#pragma once + +#ifndef DS1386_H +#define DS1386_H + +#include "emu.h" + +// handlers + +#define MCFG_DS1386_INTA_HANDLER(_devcb) \ + devcb = &ds1386_device::set_inta_cb(*device, DEVCB_##_devcb); + +#define MCFG_DS1386_INTB_HANDLER(_devcb) \ + devcb = &ds1386_device::set_inta_cb(*device, DEVCB_##_devcb); + +#define MCFG_DS1386_SQW_HANDLER(_devcb) \ + devcb = &ds1386_device::set_sqw_cb(*device, DEVCB_##_devcb); + +// devices + +#define MCFG_DS1386_8K_ADD(_tag, _clock) \ + MCFG_DEVICE_ADD(_tag, DS1386_8K, _clock) + +#define MCFG_DS1386_32K_ADD(_tag, _clock) \ + MCFG_DEVICE_ADD(_tag, DS1386_32K, _clock) + +class ds1386_device : public device_t, + public device_nvram_interface +{ +public: + ds1386_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, size_t size); + + DECLARE_WRITE8_MEMBER( data_w ); + DECLARE_READ8_MEMBER( data_r ); + + DECLARE_WRITE_LINE_MEMBER( ce_w ); + DECLARE_WRITE_LINE_MEMBER( oe_w ); + DECLARE_WRITE_LINE_MEMBER( we_w ); + + template<class _Object> static devcb_base &set_inta_cb(device_t &device, _Object object) { return downcast<ds1386_device &>(device).m_inta_cb.set_callback(object); } + template<class _Object> static devcb_base &set_intb_cb(device_t &device, _Object object) { return downcast<ds1386_device &>(device).m_intb_cb.set_callback(object); } + template<class _Object> static devcb_base &set_sqw_cb(device_t &device, _Object object) { return downcast<ds1386_device &>(device).m_sqw_cb.set_callback(object); } + +protected: + enum + { + REGISTER_HUNDREDTHS = 0, + REGISTER_SECONDS, + REGISTER_MINUTES, + REGISTER_MINUTE_ALARM, + REGISTER_HOURS, + REGISTER_HOUR_ALARM, + REGISTER_DAYS, + REGISTER_DAY_ALARM, + REGISTER_DATE, + REGISTER_MONTHS, + REGISTER_EN_OUTS = REGISTER_MONTHS, + REGISTER_YEARS, + REGISTER_COMMAND, + REGISTER_WATCHDOG_HUNDREDTHS, + REGISTER_WATCHDOG_SECONDS, + REGISTER_USER = 0xE, + }; + + enum + { + ALARM_DAYS_MATCH = 0x0, + ALARM_HOURS_MATCH = 0x1, + ALARM_MINUTES_MATCH = 0x3, + ALARM_PER_MINUTE = 0x7 + }; + + // device-level overrides + virtual void device_start() override; + virtual void device_reset() override; + virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; + + // device_nvram_interface overrides + virtual void nvram_default() override; + virtual void nvram_read(emu_file &file) override; + virtual void nvram_write(emu_file &file) override; + + static const device_timer_id CLOCK_TIMER = 0; + static const device_timer_id SQUAREWAVE_TIMER = 1; + static const device_timer_id WATCHDOG_TIMER = 2; + static const device_timer_id INTA_TIMER = 3; + static const device_timer_id INTB_TIMER = 4; + +protected: + void safe_inta_cb(int state); + void safe_intb_cb(int state); + void safe_sqw_cb(int state); + + void set_current_time(); + + void check_tod_alarm(); + void time_of_day_alarm(); + void watchdog_alarm(); + + void advance_hundredths(); + + void copy_ram_to_registers(); + void copy_registers_to_ram(); + + int m_tod_alarm; + int m_watchdog_alarm; + int m_square; + + // interfacing with other devices + devcb_write_line m_inta_cb; + devcb_write_line m_intb_cb; + devcb_write_line m_sqw_cb; + + // timers + emu_timer *m_clock_timer; + emu_timer *m_square_timer; + emu_timer *m_watchdog_timer; + emu_timer *m_inta_timer; + emu_timer *m_intb_timer; + + std::unique_ptr<UINT8[]> m_ram; + optional_region_ptr<UINT8> m_default_data; + + UINT8 m_hundredths; + UINT8 m_seconds; + UINT8 m_minutes; + UINT8 m_minutes_alarm; + UINT8 m_hours; + UINT8 m_hours_alarm; + UINT8 m_days; + UINT8 m_days_alarm; + UINT8 m_date; + UINT8 m_months_enables; + UINT8 m_years; + + const size_t m_ram_size; +}; + +class ds1386_8k_device : public ds1386_device +{ +public: + // construction/destruction + ds1386_8k_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); +}; + +class ds1386_32k_device : public ds1386_device +{ +public: + // construction/destruction + ds1386_32k_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); +}; + +// device type definition +extern const device_type DS1386_8K; +extern const device_type DS1386_32K; + +#endif diff --git a/src/devices/machine/mm58167.cpp b/src/devices/machine/mm58167.cpp index 75e9e799004..148d97260e8 100644 --- a/src/devices/machine/mm58167.cpp +++ b/src/devices/machine/mm58167.cpp @@ -9,6 +9,7 @@ **********************************************************************/ #include "mm58167.h" +#include "machine/timehelp.h" //************************************************************************** // LIVE DEVICE @@ -91,11 +92,6 @@ void mm58167_device::device_reset() } -static inline UINT8 make_bcd(UINT8 data) -{ - return ((data / 10) << 4) | (data % 10); -} - //------------------------------------------------- // device_timer - handler timer events //------------------------------------------------- @@ -124,8 +120,8 @@ void mm58167_device::device_timer(emu_timer &timer, device_timer_id id, int para if ((m_regs[R_CTL_IRQCONTROL] & 0x80) && m_regs[R_CNT_MONTH] != old_month) set_irq(7); // every month } - m_regs[R_CNT_MILLISECONDS] = make_bcd(m_milliseconds % 10); - m_regs[R_CNT_HUNDTENTHS] = make_bcd(m_milliseconds / 10); + m_regs[R_CNT_MILLISECONDS] = time_helper::make_bcd(m_milliseconds % 10); + m_regs[R_CNT_HUNDTENTHS] = time_helper::make_bcd(m_milliseconds / 10); // 10Hz IRQ if ((m_regs[R_CTL_IRQCONTROL] & 0x02) && (m_milliseconds % 100) == 0) @@ -158,12 +154,12 @@ void mm58167_device::device_timer(emu_timer &timer, device_timer_id id, int para void mm58167_device::rtc_clock_updated(int year, int month, int day, int day_of_week, int hour, int minute, int second) { - m_regs[R_CNT_SECONDS] = make_bcd(second); // seconds (BCD) - m_regs[R_CNT_MINUTES] = make_bcd(minute); // minutes (BCD) - m_regs[R_CNT_HOURS] = make_bcd(hour); // hour (BCD) - m_regs[R_CNT_DAYOFWEEK] = make_bcd(day_of_week); // day of the week (BCD) - m_regs[R_CNT_DAYOFMONTH] = make_bcd(day); // day of the month (BCD) - m_regs[R_CNT_MONTH] = make_bcd(month); // month (BCD) + m_regs[R_CNT_SECONDS] = time_helper::make_bcd(second); // seconds (BCD) + m_regs[R_CNT_MINUTES] = time_helper::make_bcd(minute); // minutes (BCD) + m_regs[R_CNT_HOURS] = time_helper::make_bcd(hour); // hour (BCD) + m_regs[R_CNT_DAYOFWEEK] = time_helper::make_bcd(day_of_week); // day of the week (BCD) + m_regs[R_CNT_DAYOFMONTH] = time_helper::make_bcd(day); // day of the month (BCD) + m_regs[R_CNT_MONTH] = time_helper::make_bcd(month); // month (BCD) } void mm58167_device::set_irq(int bit) diff --git a/src/devices/machine/pit8253.cpp b/src/devices/machine/pit8253.cpp index f542f3753b8..978cb6a50b5 100644 --- a/src/devices/machine/pit8253.cpp +++ b/src/devices/machine/pit8253.cpp @@ -317,7 +317,7 @@ void pit8253_device::simulate2(pit8253_timer *timer, INT64 elapsed_cycles) static const UINT32 CYCLES_NEVER = (0xffffffff); UINT32 cycles_to_output = 0; - LOG2(("pit8253: simulate2(): simulating %d cycles for %d in mode %d, bcd = %d, phase = %d, gate = %d, output %d, value = 0x%04x\n", + LOG2(("simulate2(): simulating %d cycles for %d in mode %d, bcd = %d, phase = %d, gate = %d, output %d, value = 0x%04x\n", (int)elapsed_cycles, timer->index, mode, bcd, timer->phase, timer->gate, timer->output, timer->value)); switch (mode) @@ -698,7 +698,7 @@ void pit8253_device::simulate2(pit8253_timer *timer, INT64 elapsed_cycles) timer->updatetimer->adjust(next_fire_time - machine().time(), timer->index); } - LOG2(("pit8253: simulate2(): simulating %d cycles for %d in mode %d, bcd = %d, phase = %d, gate = %d, output %d, value = 0x%04x, cycles_to_output = %04x\n", + LOG2(("simulate2(): simulating %d cycles for %d in mode %d, bcd = %d, phase = %d, gate = %d, output %d, value = 0x%04x, cycles_to_output = %04x\n", (int)elapsed_cycles, timer->index, mode, bcd, timer->phase, timer->gate, timer->output, timer->value, cycles_to_output)); } @@ -723,7 +723,7 @@ void pit8253_device::update(pit8253_timer *timer) attotime elapsed_time = now - timer->last_updated; INT64 elapsed_cycles = elapsed_time.as_double() * timer->clockin; - LOG1(("pit8253: update(): timer %d, %d elapsed_cycles\n", timer->index, elapsed_cycles)); + LOG1(("update(): timer %d, %d elapsed_cycles\n", timer->index, elapsed_cycles)); if (timer->clockin) timer->last_updated += elapsed_cycles * attotime::from_hz(timer->clockin); @@ -739,7 +739,7 @@ void pit8253_device::update(pit8253_timer *timer) mask this bit off. */ UINT16 pit8253_device::masked_value(pit8253_timer *timer) { - LOG2(("pit8253: masked_value\n")); + LOG2(("masked_value\n")); if (CTRL_MODE(timer->control) == 3) return timer->value & 0xfffe; return timer->value; @@ -756,7 +756,7 @@ READ8_MEMBER( pit8253_device::read ) UINT8 data; UINT16 value; - LOG2(("pit8253_r(): offset %d\n", offset)); + LOG2(("read(): offset %d\n", offset)); if (timer == nullptr) { @@ -816,7 +816,7 @@ READ8_MEMBER( pit8253_device::read ) } } - LOG2(("pit8253: read(): offset=%d data=0x%02x\n", offset, data)); + LOG2(("read(): offset=%d data=0x%02x\n", offset, data)); return data; } @@ -825,7 +825,7 @@ READ8_MEMBER( pit8253_device::read ) void pit8253_device::load_count(pit8253_timer *timer, UINT16 newcount) { int mode = CTRL_MODE(timer->control); - LOG1(("pit8253: load_count(): %04x\n", newcount)); + LOG1(("load_count(): %04x\n", newcount)); if (newcount == 1) { @@ -912,7 +912,7 @@ void pit8253_device::readback_command(UINT8 data) void pit8254_device::readback_command(UINT8 data) { - LOG1(("pit8253: write(): readback %02x\n", data & 0x3f)); + LOG1(("write(): readback %02x\n", data & 0x3f)); /* Bit 0 of data must be 0. Todo: find out what the hardware does if it isn't. */ int read_command = (data >> 4) & 3; @@ -933,7 +933,7 @@ WRITE8_MEMBER( pit8253_device::write ) { pit8253_timer *timer = get_timer(offset); - LOG2(("pit8253: write(): offset=%d data=0x%02x\n", offset, data)); + LOG2(("write(): offset=%d data=0x%02x\n", offset, data)); if (timer == nullptr) { @@ -949,7 +949,7 @@ WRITE8_MEMBER( pit8253_device::write ) if (CTRL_ACCESS(data) == 0) { - LOG1(("pit8253: write(): timer=%d readback\n", (data >> 6) & 3)); + LOG1(("write(): timer=%d readback\n", (data >> 6) & 3)); /* Latch current timer value */ /* Experimentally verified: this command does not affect the mode control register */ @@ -957,7 +957,7 @@ WRITE8_MEMBER( pit8253_device::write ) } else { - LOG1(("pit8253: write(): timer=%d bytes=%d mode=%d bcd=%d\n", (data >> 6) & 3, (data >> 4) & 3, (data >> 1) & 7, data & 1)); + LOG1(("write(): timer=%d bytes=%d mode=%d bcd=%d\n", (data >> 6) & 3, (data >> 4) & 3, (data >> 1) & 7, data & 1)); timer->control = (data & 0x3f); timer->null_count = 1; @@ -1045,7 +1045,7 @@ void pit8253_device::gate_w(int gate, int state) if (timer == nullptr) return; - LOG2(("pit8253 : gate_w(): gate=%d state=%d\n", gate, state)); + LOG2(("gate_w(): gate=%d state=%d\n", gate, state)); if (state != timer->gate) { @@ -1084,7 +1084,7 @@ void pit8253_device::set_clockin(int timerno, double new_clockin) pit8253_timer *timer = get_timer(timerno); assert(timer != nullptr); - LOG2(("pit8253_set_clockin(): PIT timer=%d, clockin = %f\n", timerno, new_clockin)); + LOG2(("set_clockin(): PIT timer=%d, clockin = %f\n", timerno, new_clockin)); update(timer); timer->clockin = new_clockin; @@ -1097,7 +1097,7 @@ void pit8253_device::set_clock_signal(int timerno, int state) pit8253_timer *timer = get_timer(timerno); assert(timer != nullptr); - LOG2(("pit8253_set_clock_signal(): PIT timer=%d, state = %d\n", timerno, state)); + LOG2(("set_clock_signal(): PIT timer=%d, state = %d\n", timerno, state)); /* Trigger on low to high transition */ if (!timer->clock && state) diff --git a/src/devices/machine/timehelp.h b/src/devices/machine/timehelp.h new file mode 100644 index 00000000000..38adfdee502 --- /dev/null +++ b/src/devices/machine/timehelp.h @@ -0,0 +1,51 @@ +// license:BSD-3-Clause +// copyright-holders:Aaron Giles,smf +/*************************************************************************** + + timehelp.h + + Assorted shared functionality between timekeeping chips and RTCs. + +***************************************************************************/ + +#pragma once + +#ifndef SRC_DEVICES_MACHINE_TIMEHELP_H +#define SRC_DEVICES_MACHINE_TIMEHELP_H + +class time_helper +{ +public: + static inline UINT8 make_bcd(UINT8 data) + { + return (((data / 10) % 10) << 4) + (data % 10); + } + + static inline UINT8 from_bcd(UINT8 data) + { + return (((data >> 4) & 15) * 10) + (data & 15); + } + + static int inc_bcd(UINT8 *data, int mask, int min, int max) + { + int bcd = (*data + 1) & mask; + int carry = 0; + + if ((bcd & 0x0f) > 9) + { + bcd &= 0xf0; + bcd += 0x10; + if (bcd > max) + { + bcd = min; + carry = 1; + } + } + + *data = (*data & ~mask) | (bcd & mask); + return carry; + } + +}; + +#endif // SRC_DEVICES_MACHINE_TIMEHELP_H
\ No newline at end of file diff --git a/src/devices/machine/timekpr.cpp b/src/devices/machine/timekpr.cpp index 4b87d43ff69..e11cd089b1c 100644 --- a/src/devices/machine/timekpr.cpp +++ b/src/devices/machine/timekpr.cpp @@ -16,7 +16,7 @@ #include "emu.h" #include "machine/timekpr.h" - +#include "machine/timehelp.h" // device type definition const device_type M48T02 = &device_creator<m48t02_device>; @@ -63,39 +63,6 @@ const device_type MK48T12 = &device_creator<mk48t12_device>; INLINE FUNCTIONS ***************************************************************************/ -static inline UINT8 make_bcd(UINT8 data) -{ - return ( ( ( data / 10 ) % 10 ) << 4 ) + ( data % 10 ); -} - -static inline UINT8 from_bcd( UINT8 data ) -{ - return ( ( ( data >> 4 ) & 15 ) * 10 ) + ( data & 15 ); -} - -static int inc_bcd( UINT8 *data, int mask, int min, int max ) -{ - int bcd; - int carry; - - bcd = ( *( data ) + 1 ) & mask; - carry = 0; - - if( ( bcd & 0x0f ) > 9 ) - { - bcd &= 0xf0; - bcd += 0x10; - if( bcd > max ) - { - bcd = min; - carry = 1; - } - } - - *( data ) = ( *( data ) & ~mask ) | ( bcd & mask ); - return carry; -} - static void counter_to_ram( UINT8 *data, int offset, int counter ) { if( offset >= 0 ) @@ -233,14 +200,14 @@ void timekeeper_device::device_start() machine().base_datetime(systime); m_control = 0; - m_seconds = make_bcd( systime.local_time.second ); - m_minutes = make_bcd( systime.local_time.minute ); - m_hours = make_bcd( systime.local_time.hour ); - m_day = make_bcd( systime.local_time.weekday + 1 ); - m_date = make_bcd( systime.local_time.mday ); - m_month = make_bcd( systime.local_time.month + 1 ); - m_year = make_bcd( systime.local_time.year % 100 ); - m_century = make_bcd( systime.local_time.year / 100 ); + m_seconds = time_helper::make_bcd( systime.local_time.second ); + m_minutes = time_helper::make_bcd( systime.local_time.minute ); + m_hours = time_helper::make_bcd( systime.local_time.hour ); + m_day = time_helper::make_bcd( systime.local_time.weekday + 1 ); + m_date = time_helper::make_bcd( systime.local_time.mday ); + m_month = time_helper::make_bcd( systime.local_time.month + 1 ); + m_year = time_helper::make_bcd( systime.local_time.year % 100 ); + m_century = time_helper::make_bcd( systime.local_time.year / 100 ); m_data.resize( m_size ); save_item( NAME(m_control) ); @@ -298,14 +265,14 @@ void timekeeper_device::device_timer(emu_timer &timer, device_timer_id id, int p return; } - int carry = inc_bcd( &m_seconds, MASK_SECONDS, 0x00, 0x59 ); + int carry = time_helper::inc_bcd( &m_seconds, MASK_SECONDS, 0x00, 0x59 ); if( carry ) { - carry = inc_bcd( &m_minutes, MASK_MINUTES, 0x00, 0x59 ); + carry = time_helper::inc_bcd( &m_minutes, MASK_MINUTES, 0x00, 0x59 ); } if( carry ) { - carry = inc_bcd( &m_hours, MASK_HOURS, 0x00, 0x23 ); + carry = time_helper::inc_bcd( &m_hours, MASK_HOURS, 0x00, 0x23 ); } if( carry ) @@ -313,10 +280,10 @@ void timekeeper_device::device_timer(emu_timer &timer, device_timer_id id, int p UINT8 maxdays; static const UINT8 daysinmonth[] = { 0x31, 0x28, 0x31, 0x30, 0x31, 0x30, 0x31, 0x31, 0x30, 0x31, 0x30, 0x31 }; - inc_bcd( &m_day, MASK_DAY, 0x01, 0x07 ); + time_helper::inc_bcd( &m_day, MASK_DAY, 0x01, 0x07 ); - UINT8 month = from_bcd( m_month ); - UINT8 year = from_bcd( m_year ); + UINT8 month = time_helper::from_bcd( m_month ); + UINT8 year = time_helper::from_bcd( m_year ); if( month == 2 && ( year % 4 ) == 0 ) { @@ -331,19 +298,19 @@ void timekeeper_device::device_timer(emu_timer &timer, device_timer_id id, int p maxdays = 0x31; } - carry = inc_bcd( &m_date, MASK_DATE, 0x01, maxdays ); + carry = time_helper::inc_bcd( &m_date, MASK_DATE, 0x01, maxdays ); } if( carry ) { - carry = inc_bcd( &m_month, MASK_MONTH, 0x01, 0x12 ); + carry = time_helper::inc_bcd( &m_month, MASK_MONTH, 0x01, 0x12 ); } if( carry ) { - carry = inc_bcd( &m_year, MASK_YEAR, 0x00, 0x99 ); + carry = time_helper::inc_bcd( &m_year, MASK_YEAR, 0x00, 0x99 ); } if( carry ) { - carry = inc_bcd( &m_century, MASK_CENTURY, 0x00, 0x99 ); + carry = time_helper::inc_bcd( &m_century, MASK_CENTURY, 0x00, 0x99 ); if( type() == M48T35 || type() == M48T58 ) diff --git a/src/devices/video/mc6845.cpp b/src/devices/video/mc6845.cpp index 04e7c967869..fb52c855ecc 100644 --- a/src/devices/video/mc6845.cpp +++ b/src/devices/video/mc6845.cpp @@ -441,6 +441,12 @@ READ_LINE_MEMBER( mc6845_device::cursor_r ) } +READ_LINE_MEMBER( mc6845_device::cursor_state_r ) +{ + return m_cursor_state; +} + + READ_LINE_MEMBER( mc6845_device::hsync_r ) { return m_hsync; diff --git a/src/devices/video/mc6845.h b/src/devices/video/mc6845.h index 9bad2348640..f530485b886 100644 --- a/src/devices/video/mc6845.h +++ b/src/devices/video/mc6845.h @@ -141,6 +141,7 @@ public: // read cursor line state DECLARE_READ_LINE_MEMBER( cursor_r ); + DECLARE_READ_LINE_MEMBER( cursor_state_r ); // read horizontal sync line state DECLARE_READ_LINE_MEMBER( hsync_r ); diff --git a/src/mame/drivers/amusco.cpp b/src/mame/drivers/amusco.cpp index a300b1cc485..ec0aeda20cf 100644 --- a/src/mame/drivers/amusco.cpp +++ b/src/mame/drivers/amusco.cpp @@ -7,12 +7,6 @@ Preliminary driver by Roberto Fresca. - TODO: - - i8259 and irqs - - understand how videoram works (tied to port $70?) - - inputs - - everything else; - ******************************************************************************* Hardware Notes: @@ -48,7 +42,8 @@ The program code reads from and writes to what must be a line printer and a RTC (probably a MSM5832), though neither is present on the main board. The I/O write patterns also suggest that each or both of these devices are accessed through an - unknown interface chip or gate array (not i8255-compatible). + unknown interface chip or gate array (not i8255-compatible). The printer appears to + use non-Epson control codes: ETB, DLE, DC4, DC2, SO, EM, DC1 and STX. ***************************************************************************************** @@ -67,8 +62,11 @@ TODO: - Proper tile colors. - - Hook PPI8255 devices. - - I/O. + - Determine PIT clocks for proper IRQ timing. + - Make the 6845 transparent videoram addressing actually transparent. + (IRQ1 changes the 6845 address twice but neither reads nor writes data?) + - Add NVRAM in a way that won't trigger POST error message (needs NMI on shutdown?) + - Identify outputs from first PPI (these include button lamps?) *******************************************************************************/ @@ -100,13 +98,17 @@ public: m_gfxdecode(*this, "gfxdecode"), m_pic(*this, "pic8259"), m_rtc(*this, "rtc"), - m_crtc(*this, "crtc") + m_crtc(*this, "crtc"), + m_screen(*this, "screen") { } required_shared_ptr<UINT8> m_videoram; tilemap_t *m_bg_tilemap; TILE_GET_INFO_MEMBER(get_bg_tile_info); virtual void video_start() override; + DECLARE_READ8_MEMBER(hack_coin1_r); + DECLARE_READ8_MEMBER(hack_coin2_r); + DECLARE_READ8_MEMBER(hack_908_r); DECLARE_READ8_MEMBER(mc6845_r); DECLARE_WRITE8_MEMBER(mc6845_w); DECLARE_WRITE8_MEMBER(output_a_w); @@ -118,13 +120,14 @@ public: DECLARE_READ8_MEMBER(rtc_r); DECLARE_WRITE8_MEMBER(rtc_w); MC6845_ON_UPDATE_ADDR_CHANGED(crtc_addr); + MC6845_UPDATE_ROW(update_row); - UINT32 screen_update_amusco(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); required_device<cpu_device> m_maincpu; required_device<gfxdecode_device> m_gfxdecode; required_device<pic8259_device> m_pic; required_device<msm5832_device> m_rtc; required_device<mc6845_device> m_crtc; + required_device<screen_device> m_screen; UINT8 m_mc6845_address; UINT16 m_video_update_address; }; @@ -143,11 +146,16 @@ TILE_GET_INFO_MEMBER(amusco_state::get_bg_tile_info) ---- ---- seems unused. */ int code = m_videoram[tile_index * 2] | (m_videoram[tile_index * 2 + 1] << 8); + int color = (code & 0x7000) >> 12; + + // 6845 cursor is only used for its blink state + if (BIT(code, 15) && !m_crtc->cursor_state_r()) + code = 0; SET_TILE_INFO_MEMBER( 0 /* bank */, code & 0x3ff, - 0 /* color */, + color, 0 ); } @@ -157,23 +165,37 @@ void amusco_state::video_start() m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(FUNC(amusco_state::get_bg_tile_info),this), TILEMAP_SCAN_ROWS, 8, 10, 74, 24); } -UINT32 amusco_state::screen_update_amusco(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) -{ - m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0); - return 0; -} - /************************** * Read / Write Handlers * **************************/ +READ8_MEMBER(amusco_state::hack_coin1_r) +{ + // actually set by IRQ4 + return BIT(ioport("IN2")->read(), 1) ? 1 : 0; +} + +READ8_MEMBER(amusco_state::hack_coin2_r) +{ + // actually set by IRQ4 + return BIT(ioport("IN2")->read(), 2) ? 1 : 0; +} + +READ8_MEMBER(amusco_state::hack_908_r) +{ + // IRQ4 and other routines wait for bits of this to be set by IRQ2 + return 0xff; +} /************************* * Memory Map Information * *************************/ static ADDRESS_MAP_START( amusco_mem_map, AS_PROGRAM, 8, amusco_state ) + AM_RANGE(0x006a6, 0x006a6) AM_READ(hack_coin1_r) + AM_RANGE(0x006a8, 0x006a8) AM_READ(hack_coin2_r) + AM_RANGE(0x00908, 0x00908) AM_READ(hack_908_r) AM_RANGE(0x00000, 0x0ffff) AM_RAM AM_RANGE(0xec000, 0xecfff) AM_RAM AM_SHARE("videoram") // placeholder AM_RANGE(0xf8000, 0xfffff) AM_ROM @@ -228,8 +250,19 @@ WRITE8_MEMBER(amusco_state::vram_w) READ8_MEMBER(amusco_state::lpt_r) { - logerror("Reading from printer port 28%dh\n", offset); - return 0; + switch (offset) + { + case 2: + // Bit 0 = busy + // Bit 1 = paper jam (inverted) + // Bit 3 = out of paper + // Bit 4 = low paper + return 2; + + default: + logerror("Reading from printer port 28%dh\n", offset); + return 0; + } } WRITE8_MEMBER(amusco_state::lpt_w) @@ -301,34 +334,29 @@ ADDRESS_MAP_END static INPUT_PORTS_START( amusco ) PORT_START("IN0") - PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_1) PORT_NAME("IN0-1") - PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_2) PORT_NAME("IN0-2") - PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_3) PORT_NAME("IN0-3") - PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_GAMBLE_BOOK ) PORT_CODE(KEYCODE_4) - PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_5) PORT_NAME("IN0-5") - PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_6) PORT_NAME("IN0-6") - PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_7) PORT_NAME("IN0-7") - PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_8) PORT_NAME("IN0-8") + PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_GAMBLE_BET ) PORT_NAME("Play Credit") + PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_START1 ) // actual name uncertain; next screen in service mode + PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_GAMBLE_PAYOUT ) // decrement in service mode + PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_GAMBLE_BOOK ) + PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_GAMBLE_DEAL ) PORT_NAME("Draw") // previous screen in service mode + PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_GAMBLE_STAND ) // actual name uncertain; increment in service mode + PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_POKER_HOLD1 ) // move left in service mode + PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_POKER_HOLD2 ) // move right in service mode PORT_START("IN1") PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_CODE(KEYCODE_Q) PORT_NAME("Cash Door") - PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_GAMBLE_SERVICE ) PORT_CODE(KEYCODE_W) - PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_E) PORT_NAME("IN1-3") - PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_R) PORT_NAME("IN1-4") + PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_GAMBLE_SERVICE ) + PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED ) + PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_CODE(KEYCODE_T) PORT_NAME("Logic Door") - PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_Y) PORT_NAME("IN1-6") - PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_U) PORT_NAME("IN1-7") - PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_I) PORT_NAME("IN1-8") + PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_POKER_HOLD5 ) + PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_POKER_HOLD4 ) // move down in service mode + PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_POKER_HOLD3 ) // move up in service mode PORT_START("IN2") - PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_A) PORT_NAME("IN2-1") - PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_S) PORT_NAME("IN2-2") - PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_D) PORT_NAME("IN2-3") - PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_F) PORT_NAME("IN2-4") - PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_G) PORT_NAME("IN2-5") - PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_H) PORT_NAME("IN2-6") - PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_J) PORT_NAME("IN2-7") - PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_K) PORT_NAME("IN2-8") + PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_COIN1 ) //PORT_WRITE_LINE_DEVICE_MEMBER("pic8259", pic8259_device, ir4_w) + PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_COIN2 ) //PORT_WRITE_LINE_DEVICE_MEMBER("pic8259", pic8259_device, ir4_w) + PORT_BIT( 0xf9, IP_ACTIVE_HIGH, IPT_UNUSED ) INPUT_PORTS_END @@ -353,7 +381,7 @@ static const gfx_layout charlayout = ******************************/ static GFXDECODE_START( amusco ) - GFXDECODE_ENTRY( "gfx1", 0, charlayout, 0, 8 ) + GFXDECODE_ENTRY( "gfx1", 0, charlayout, 0, /*8*/ 1 ) // current palette has only 8 colors... GFXDECODE_END @@ -366,6 +394,13 @@ MC6845_ON_UPDATE_ADDR_CHANGED(amusco_state::crtc_addr) // m_video_update_address = address; } +MC6845_UPDATE_ROW(amusco_state::update_row) +{ + const rectangle rowrect(0, 8 * x_count - 1, y, y); + m_bg_tilemap->mark_all_dirty(); + m_bg_tilemap->draw(*m_screen, bitmap, rowrect, 0, 0); +} + /************************* * Machine Drivers * *************************/ @@ -381,6 +416,10 @@ static MACHINE_CONFIG_START( amusco, amusco_state ) MCFG_PIC8259_ADD("pic8259", INPUTLINE("maincpu", 0), VCC, NOOP) MCFG_DEVICE_ADD("pit8253", PIT8253, 0) + //MCFG_PIT8253_CLK0(nnn) + //MCFG_PIT8253_OUT0_HANDLER(DEVWRITELINE("pic8259", pic8259_device, ir0_w)) + //MCFG_PIT8253_CLK1(nnn) + //MCFG_PIT8253_OUT1_HANDLER(DEVWRITELINE("pic8259", pic8259_device, ir2_w)) MCFG_DEVICE_ADD("ppi_outputs", I8255, 0) MCFG_I8255_OUT_PORTA_CB(WRITE8(amusco_state, output_a_w)) @@ -400,10 +439,10 @@ static MACHINE_CONFIG_START( amusco, amusco_state ) MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0)) MCFG_SCREEN_SIZE(88*8, 27*10) // screen size: 88*8 27*10 MCFG_SCREEN_VISIBLE_AREA(0*8, 74*8-1, 0*10, 24*10-1) // visible scr: 74*8 24*10 - MCFG_SCREEN_UPDATE_DRIVER(amusco_state, screen_update_amusco) + MCFG_SCREEN_UPDATE_DEVICE("crtc", mc6845_device, screen_update) - MCFG_SCREEN_PALETTE("palette") MCFG_GFXDECODE_ADD("gfxdecode", "palette", amusco) + MCFG_PALETTE_ADD_3BIT_GBR("palette") MCFG_MC6845_ADD("crtc", R6545_1, "screen", CRTC_CLOCK) /* guess */ @@ -412,6 +451,7 @@ static MACHINE_CONFIG_START( amusco, amusco_state ) MCFG_MC6845_ADDR_CHANGED_CB(amusco_state, crtc_addr) MCFG_MC6845_OUT_DE_CB(DEVWRITELINE("pic8259", pic8259_device, ir1_w)) // IRQ1 sets 0x918 bit 3 MCFG_MC6845_OUT_VSYNC_CB(DEVWRITELINE("pic8259", pic8259_device, ir0_w)) // IRQ0 sets 0x665 to 0xff + MCFG_MC6845_UPDATE_ROW_CB(amusco_state, update_row) /* sound hardware */ MCFG_SPEAKER_STANDARD_MONO("mono") @@ -449,4 +489,4 @@ ROM_END *************************/ /* YEAR NAME PARENT MACHINE INPUT STATE INIT ROT COMPANY FULLNAME FLAGS */ -GAME( 1987, amusco, 0, amusco, amusco, driver_device, 0, ROT0, "Amusco", "American Music Poker (V1.4)", MACHINE_NOT_WORKING ) +GAME( 1987, amusco, 0, amusco, amusco, driver_device, 0, ROT0, "Amusco", "American Music Poker (V1.4)", MACHINE_IMPERFECT_COLORS ) // runs much too fast; palette totally wrong diff --git a/src/mame/drivers/indy_indigo2.cpp b/src/mame/drivers/indy_indigo2.cpp index 2631d9f66fb..e913ee22045 100644 --- a/src/mame/drivers/indy_indigo2.cpp +++ b/src/mame/drivers/indy_indigo2.cpp @@ -50,43 +50,87 @@ #include "machine/pit8253.h" #include "video/newport.h" #include "sound/dac.h" -#include "machine/nvram.h" #include "bus/scsi/scsi.h" #include "bus/scsi/scsicd.h" #include "bus/scsi/scsihd.h" #include "machine/wd33c93.h" +#include "machine/ds1386.h" -struct RTC_t +#define MCFG_IOC2_ADD(_tag) \ + MCFG_DEVICE_ADD(_tag, SGI_IOC2, 0) + +class ioc2_device : public device_t { - UINT8 nRegs[0x80]; - UINT8 nUserRAM[0x200]; - UINT8 nRAM[0x800]; +public: + ioc2_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); + ioc2_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source); + + DECLARE_WRITE32_MEMBER( int3_write ); + DECLARE_READ32_MEMBER( int3_read ); + + void lower_local0_irq(UINT8 source_mask); + void raise_local0_irq(UINT8 source_mask); + void lower_local1_irq(UINT8 source_mask); + void raise_local1_irq(UINT8 source_mask); + +protected: + virtual void device_start() override; + virtual void device_reset() override; + + required_device<mips3_device> m_maincpu; + + UINT32 m_regs[0x40]; + UINT32 m_par_read_cnt; + UINT32 m_par_cntl; }; -struct HPC3_t +const device_type SGI_IOC2 = &device_creator<ioc2_device>; + +ioc2_device::ioc2_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : device_t(mconfig, SGI_IOC2, "SGI IOC2 I/O Controller", tag, owner, clock, "ioc2", __FILE__) + , m_maincpu(*this, "^maincpu") +{ +} + +void ioc2_device::device_start() +{ +} + +void ioc2_device::device_reset() +{ + m_par_read_cnt = 0; + m_par_cntl = 0; + memset(m_regs, 0, sizeof(UINT32) * 0x40); +} + +#define KBDC_TAG "kbdc" +#define IOC2_TAG "ioc2" +#define RTC_TAG "ds1386" + +struct hpc3_t { - UINT32 nenetr_nbdp; - UINT32 nenetr_cbp; - UINT32 nunk0; - UINT32 nunk1; - UINT32 nIC_Unk0; - UINT32 nSCSI0Descriptor; - UINT32 nSCSI0DMACtrl; + UINT32 m_enetr_nbdp; + UINT32 m_enetr_cbp; + UINT32 m_unk0; + UINT32 m_unk1; + UINT32 m_ic_unk0; + UINT32 m_scsi0_desc; + UINT32 m_scsi0_dma_ctrl; }; -struct HAL2_t +struct m_hal2 { - UINT32 nIAR; - UINT32 nIDR[4]; + UINT32 m_iar; + UINT32 m_idr[4]; }; -struct PBUS_DMA_t +struct pbus_dma_t { - UINT8 nActive; - UINT32 nCurPtr; - UINT32 nDescPtr; - UINT32 nNextPtr; - UINT32 nWordsLeft; + UINT8 m_active; + UINT32 m_cur_ptr; + UINT32 m_desc_ptr; + UINT32 m_next_ptr; + UINT32 m_words_left; }; class ip22_state : public driver_device @@ -94,45 +138,29 @@ class ip22_state : public driver_device public: enum { - TIMER_IP22_DMA, - TIMER_IP22_MSEC + TIMER_IP22_DMA }; - ip22_state(const machine_config &mconfig, device_type type, const char *tag) : - driver_device(mconfig, type, tag), - m_maincpu(*this, "maincpu"), - m_wd33c93(*this, "wd33c93"), - m_unkpbus0(*this, "unkpbus0"), - m_mainram(*this, "mainram"), - m_lpt0(*this, "lpt_0"), - m_pit(*this, "pit8254"), - m_sgi_mc(*this, "sgi_mc"), - m_newport(*this, "newport"), - m_dac(*this, "dac"), - m_kbdc8042(*this, "kbdc") + ip22_state(const machine_config &mconfig, device_type type, const char *tag) + : driver_device(mconfig, type, tag) + , m_maincpu(*this, "maincpu") + , m_wd33c93(*this, "wd33c93") + , m_unkpbus0(*this, "unkpbus0") + , m_mainram(*this, "mainram") + , m_lpt0(*this, "lpt_0") + , m_pit(*this, "pit8254") + , m_sgi_mc(*this, "sgi_mc") + , m_newport(*this, "newport") + , m_dac(*this, "dac") + , m_kbdc8042(*this, KBDC_TAG) + , m_ioc2(*this, IOC2_TAG) + , m_rtc(*this, RTC_TAG) { } - required_device<mips3_device> m_maincpu; - required_device<wd33c93_device> m_wd33c93; - required_shared_ptr<UINT32> m_unkpbus0; - required_shared_ptr<UINT32> m_mainram; - required_device<pc_lpt_device> m_lpt0; - required_device<pit8254_device> m_pit; - required_device<sgi_mc_device> m_sgi_mc; - required_device<newport_video_device> m_newport; - required_device<dac_device> m_dac; - required_device<kbdc8042_device> m_kbdc8042; + virtual void machine_start() override; + virtual void machine_reset() override; - RTC_t m_RTC; - UINT32 m_int3_regs[64]; - UINT32 m_nIOC_ParReadCnt; - /*UINT8 m_nIOC_ParCntl;*/ - HPC3_t m_HPC3; - HAL2_t m_HAL2; - PBUS_DMA_t m_PBUS_DMA; - UINT32 m_nIntCounter; - UINT8 m_dma_buffer[4096]; DECLARE_READ32_MEMBER(hpc3_pbus6_r); DECLARE_WRITE32_MEMBER(hpc3_pbus6_w); DECLARE_READ32_MEMBER(hpc3_hd_enet_r); @@ -141,30 +169,48 @@ public: DECLARE_WRITE32_MEMBER(hpc3_hd0_w); DECLARE_READ32_MEMBER(hpc3_pbus4_r); DECLARE_WRITE32_MEMBER(hpc3_pbus4_w); - DECLARE_READ32_MEMBER(rtc_r); - DECLARE_WRITE32_MEMBER(rtc_w); - DECLARE_WRITE32_MEMBER(ip22_write_ram); - DECLARE_READ32_MEMBER(hal2_r); - DECLARE_WRITE32_MEMBER(hal2_w); DECLARE_READ32_MEMBER(hpc3_pbusdma_r); DECLARE_WRITE32_MEMBER(hpc3_pbusdma_w); DECLARE_READ32_MEMBER(hpc3_unkpbus0_r); DECLARE_WRITE32_MEMBER(hpc3_unkpbus0_w); + + DECLARE_WRITE32_MEMBER(ip22_write_ram); + + DECLARE_READ32_MEMBER(hal2_r); + DECLARE_WRITE32_MEMBER(hal2_w); + DECLARE_WRITE_LINE_MEMBER(scsi_irq); + DECLARE_DRIVER_INIT(ip225015); - virtual void machine_start() override; - virtual void machine_reset() override; - INTERRUPT_GEN_MEMBER(ip22_vbl); + TIMER_CALLBACK_MEMBER(ip22_dma); - TIMER_CALLBACK_MEMBER(ip22_timer); - inline void ATTR_PRINTF(3,4) verboselog(int n_level, const char *s_fmt, ... ); - void int3_raise_local0_irq(UINT8 source_mask); - void int3_lower_local0_irq(UINT8 source_mask); - void dump_chain(address_space &space, UINT32 ch_base); - void rtc_update(); protected: virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; + + required_device<mips3_device> m_maincpu; + required_device<wd33c93_device> m_wd33c93; + required_shared_ptr<UINT32> m_unkpbus0; + required_shared_ptr<UINT32> m_mainram; + required_device<pc_lpt_device> m_lpt0; + required_device<pit8254_device> m_pit; + required_device<sgi_mc_device> m_sgi_mc; + required_device<newport_video_device> m_newport; + required_device<dac_device> m_dac; + required_device<kbdc8042_device> m_kbdc8042; + required_device<ioc2_device> m_ioc2; + required_device<ds1386_device> m_rtc; + + void dump_chain(address_space &space, UINT32 ch_base); + + hpc3_t m_hpc3; + + m_hal2 m_hal2; + + pbus_dma_t m_pbus_dma; + UINT8 m_dma_buffer[4096]; + + inline void ATTR_PRINTF(3,4) verboselog(int n_level, const char *s_fmt, ... ); }; @@ -185,12 +231,6 @@ inline void ATTR_PRINTF(3,4) ip22_state::verboselog(int n_level, const char *s_f } -#define RTC_DAY m_RTC.nRAM[0x09] -#define RTC_HOUR m_RTC.nRAM[0x08] -#define RTC_MINUTE m_RTC.nRAM[0x07] -#define RTC_SECOND m_RTC.nRAM[0x06] -#define RTC_HUNDREDTH m_RTC.nRAM[0x05] - // interrupt sources handled by INT3 #define INT3_LOCAL0_FIFO (0x01) #define INT3_LOCAL0_SCSI0 (0x02) @@ -210,41 +250,50 @@ inline void ATTR_PRINTF(3,4) ip22_state::verboselog(int n_level, const char *s_f #define INT3_LOCAL1_VSYNC (0x40) #define INT3_LOCAL1_RETRACE (0x80) -// raise a local0 interrupt -void ip22_state::int3_raise_local0_irq(UINT8 source_mask) +void ioc2_device::raise_local0_irq(UINT8 source_mask) { // signal the interrupt is pending - m_int3_regs[0] |= source_mask; + m_regs[0] |= source_mask; // if it's not masked, also assert it now at the CPU - if (m_int3_regs[1] & source_mask) + if (m_regs[1] & source_mask) m_maincpu->set_input_line(MIPS3_IRQ0, ASSERT_LINE); } -// lower a local0 interrupt -void ip22_state::int3_lower_local0_irq(UINT8 source_mask) +void ioc2_device::lower_local0_irq(UINT8 source_mask) { - m_int3_regs[0] &= ~source_mask; + m_regs[0] &= ~source_mask; } -#ifdef UNUSED_FUNCTION -// raise a local1 interrupt -void ip22_state::int3_raise_local1_irq(UINT8 source_mask) +void ioc2_device::raise_local1_irq(UINT8 source_mask) { // signal the interrupt is pending - m_int3_regs[2] |= source_mask; + m_regs[2] |= source_mask; // if it's not masked, also assert it now at the CPU - if (m_int3_regs[2] & source_mask) + if (m_regs[3] & source_mask) m_maincpu->set_input_line(MIPS3_IRQ1, ASSERT_LINE); } -// lower a local1 interrupt -void ip22_state::int3_lower_local1_irq(UINT8 source_mask) +void ioc2_device::lower_local1_irq(UINT8 source_mask) { - m_int3_regs[2] &= ~source_mask; + m_regs[2] &= ~source_mask; +} + +READ32_MEMBER( ioc2_device::int3_read ) +{ + return m_regs[offset]; +} + +WRITE32_MEMBER( ioc2_device::int3_write ) +{ + m_regs[offset] = data; + + for (int line = 0; line < 2; line++) + { + m_maincpu->set_input_line(MIPS3_IRQ0 + line, (m_regs[line*2] & m_regs[line*2+1]) != 0 ? ASSERT_LINE : CLEAR_LINE); + } } -#endif READ32_MEMBER(ip22_state::hpc3_pbus6_r) { @@ -293,8 +342,7 @@ READ32_MEMBER(ip22_state::hpc3_pbus6_r) case 0xa4/4: case 0xa8/4: case 0xac/4: -// osd_printf_info("INT3: r @ %x mask %08x (PC=%x)\n", offset*4, mem_mask, activecpu_get_pc()); - return m_int3_regs[offset-0x80/4]; + return m_ioc2->int3_read(space, offset-0x80/4, ~0); case 0xb0/4: ret8 = m_pit->read(space, 0); //verboselog(0, "HPC PBUS6 IOC4 Timer Counter 0 Register Read: 0x%02x (%08x)\n", ret8, mem_mask ); @@ -326,7 +374,7 @@ WRITE32_MEMBER(ip22_state::hpc3_pbus6_w) case 0x004/4: //verboselog(0, "Parallel Control Write: %08x\n", data ); m_lpt0->control_w(space, 0, data ^ 0x0d); - //m_nIOC_ParCntl = data; + //m_ioc_par_cntl = data; break; case 0x030/4: if( ( data & 0x000000ff ) >= 0x20 ) @@ -374,21 +422,7 @@ WRITE32_MEMBER(ip22_state::hpc3_pbus6_w) case 0x9c/4: case 0xa0/4: case 0xa4/4: -// osd_printf_info("INT3: w %x to %x (reg %d) mask %08x (PC=%x)\n", data, offset*4, offset-0x80/4, mem_mask, activecpu_get_pc()); - m_int3_regs[offset-0x80/4] = data; - - // if no local0 interrupts now, clear the input to the CPU - if ((m_int3_regs[0] & m_int3_regs[1]) == 0) - m_maincpu->set_input_line(MIPS3_IRQ0, CLEAR_LINE); - else - m_maincpu->set_input_line(MIPS3_IRQ0, ASSERT_LINE); - - // if no local1 interrupts now, clear the input to the CPU - if ((m_int3_regs[2] & m_int3_regs[3]) == 0) - m_maincpu->set_input_line(MIPS3_IRQ1, CLEAR_LINE); - else - m_maincpu->set_input_line(MIPS3_IRQ1, ASSERT_LINE); - + m_ioc2->int3_write(space, offset - 0x80/4, data, ~0); break; case 0xb0/4: //verboselog(0, "HPC PBUS6 IOC4 Timer Counter 0 Register Write: 0x%08x (%08x)\n", data, mem_mask ); @@ -417,17 +451,17 @@ READ32_MEMBER(ip22_state::hpc3_hd_enet_r) switch( offset ) { case 0x0004/4: - //verboselog((machine, 0, "HPC3 SCSI0DESC Read: %08x (%08x): %08x\n", 0x1fb90000 + ( offset << 2), mem_mask, m_HPC3.nSCSI0Descriptor ); - return m_HPC3.nSCSI0Descriptor; + //verboselog((machine, 0, "HPC3 SCSI0DESC Read: %08x (%08x): %08x\n", 0x1fb90000 + ( offset << 2), mem_mask, m_hpc3.m_scsi0_desc ); + return m_hpc3.m_scsi0_desc; case 0x1004/4: - //verboselog((machine, 0, "HPC3 SCSI0DMACTRL Read: %08x (%08x): %08x\n", 0x1fb90000 + ( offset << 2), mem_mask, m_HPC3.nSCSI0DMACtrl ); - return m_HPC3.nSCSI0DMACtrl; + //verboselog((machine, 0, "HPC3 SCSI0DMACTRL Read: %08x (%08x): %08x\n", 0x1fb90000 + ( offset << 2), mem_mask, m_hpc3.m_scsi0_dma_ctrl ); + return m_hpc3.m_scsi0_dma_ctrl; case 0x4000/4: - //verboselog((machine, 2, "HPC3 ENETR CBP Read: %08x (%08x): %08x\n", 0x1fb90000 + ( offset << 2), mem_mask, m_HPC3.nenetr_nbdp ); - return m_HPC3.nenetr_cbp; + //verboselog((machine, 2, "HPC3 ENETR CBP Read: %08x (%08x): %08x\n", 0x1fb90000 + ( offset << 2), mem_mask, m_hpc3.m_enetr_nbdp ); + return m_hpc3.m_enetr_cbp; case 0x4004/4: - //verboselog((machine, 2, "HPC3 ENETR NBDP Read: %08x (%08x): %08x\n", 0x1fb90000 + ( offset << 2), mem_mask, m_HPC3.nenetr_nbdp ); - return m_HPC3.nenetr_nbdp; + //verboselog((machine, 2, "HPC3 ENETR NBDP Read: %08x (%08x): %08x\n", 0x1fb90000 + ( offset << 2), mem_mask, m_hpc3.m_enetr_nbdp ); + return m_hpc3.m_enetr_nbdp; default: //verboselog((machine, 0, "Unknown HPC3 ENET/HDx Read: %08x (%08x)\n", 0x1fb90000 + ( offset << 2 ), mem_mask ); return 0; @@ -440,19 +474,19 @@ WRITE32_MEMBER(ip22_state::hpc3_hd_enet_w) { case 0x0004/4: //verboselog((machine, 2, "HPC3 SCSI0DESC Write: %08x\n", data ); - m_HPC3.nSCSI0Descriptor = data; + m_hpc3.m_scsi0_desc = data; break; case 0x1004/4: //verboselog((machine, 2, "HPC3 SCSI0DMACTRL Write: %08x\n", data ); - m_HPC3.nSCSI0DMACtrl = data; + m_hpc3.m_scsi0_dma_ctrl = data; break; case 0x4000/4: //verboselog((machine, 2, "HPC3 ENETR CBP Write: %08x\n", data ); - m_HPC3.nenetr_cbp = data; + m_hpc3.m_enetr_cbp = data; break; case 0x4004/4: //verboselog((machine, 2, "HPC3 ENETR NBDP Write: %08x\n", data ); - m_HPC3.nenetr_nbdp = data; + m_hpc3.m_enetr_nbdp = data; break; default: //verboselog((machine, 0, "Unknown HPC3 ENET/HDx write: %08x (%08x): %08x\n", 0x1fb90000 + ( offset << 2 ), mem_mask, data ); @@ -524,14 +558,14 @@ READ32_MEMBER(ip22_state::hpc3_pbus4_r) switch( offset ) { case 0x0004/4: - //verboselog((machine, 2, "HPC3 PBUS4 Unknown 0 Read: (%08x): %08x\n", mem_mask, m_HPC3.nunk0 ); - return m_HPC3.nunk0; + //verboselog((machine, 2, "HPC3 PBUS4 Unknown 0 Read: (%08x): %08x\n", mem_mask, m_hpc3.m_unk0 ); + return m_hpc3.m_unk0; case 0x000c/4: - //verboselog((machine, 2, "Interrupt Controller(?) Read: (%08x): %08x\n", mem_mask, m_HPC3.nIC_Unk0 ); - return m_HPC3.nIC_Unk0; + //verboselog((machine, 2, "Interrupt Controller(?) Read: (%08x): %08x\n", mem_mask, m_hpc3.m_ic_unk0 ); + return m_hpc3.m_ic_unk0; case 0x0014/4: - //verboselog((machine, 2, "HPC3 PBUS4 Unknown 1 Read: (%08x): %08x\n", mem_mask, m_HPC3.nunk1 ); - return m_HPC3.nunk1; + //verboselog((machine, 2, "HPC3 PBUS4 Unknown 1 Read: (%08x): %08x\n", mem_mask, m_hpc3.m_unk1 ); + return m_hpc3.m_unk1; default: //verboselog((machine, 0, "Unknown HPC3 PBUS4 Read: %08x (%08x)\n", 0x1fbd9000 + ( offset << 2 ), mem_mask ); return 0; @@ -544,15 +578,15 @@ WRITE32_MEMBER(ip22_state::hpc3_pbus4_w) { case 0x0004/4: //verboselog((machine, 2, "HPC3 PBUS4 Unknown 0 Write: %08x (%08x)\n", data, mem_mask ); - m_HPC3.nunk0 = data; + m_hpc3.m_unk0 = data; break; case 0x000c/4: //verboselog((machine, 2, "Interrupt Controller(?) Write: (%08x): %08x\n", mem_mask, data ); - m_HPC3.nIC_Unk0 = data; + m_hpc3.m_ic_unk0 = data; break; case 0x0014/4: //verboselog((machine, 2, "HPC3 PBUS4 Unknown 1 Write: %08x (%08x)\n", data, mem_mask ); - m_HPC3.nunk1 = data; + m_hpc3.m_unk1 = data; break; default: //verboselog((machine, 0, "Unknown HPC3 PBUS4 Write: %08x (%08x): %08x\n", 0x1fbd9000 + ( offset << 2 ), mem_mask, data ); @@ -560,308 +594,6 @@ WRITE32_MEMBER(ip22_state::hpc3_pbus4_w) } } -#define RTC_SECONDS m_RTC.nRegs[0x00] -#define RTC_SECONDS_A m_RTC.nRegs[0x01] -#define RTC_MINUTES m_RTC.nRegs[0x02] -#define RTC_MINUTES_A m_RTC.nRegs[0x03] -#define RTC_HOURS m_RTC.nRegs[0x04] -#define RTC_HOURS_A m_RTC.nRegs[0x05] -#define RTC_DAYOFWEEK m_RTC.nRegs[0x06] -#define RTC_DAYOFMONTH m_RTC.nRegs[0x07] -#define RTC_MONTH m_RTC.nRegs[0x08] -#define RTC_YEAR m_RTC.nRegs[0x09] -#define RTC_REGISTERA m_RTC.nRegs[0x0a] -#define RTC_REGISTERB m_RTC.nRegs[0x0b] -#define RTC_REGISTERC m_RTC.nRegs[0x0c] -#define RTC_REGISTERD m_RTC.nRegs[0x0d] -#define RTC_MODELBYTE m_RTC.nRegs[0x40] -#define RTC_SERBYTE0 m_RTC.nRegs[0x41] -#define RTC_SERBYTE1 m_RTC.nRegs[0x42] -#define RTC_SERBYTE2 m_RTC.nRegs[0x43] -#define RTC_SERBYTE3 m_RTC.nRegs[0x44] -#define RTC_SERBYTE4 m_RTC.nRegs[0x45] -#define RTC_SERBYTE5 m_RTC.nRegs[0x46] -#define RTC_CRC m_RTC.nRegs[0x47] -#define RTC_CENTURY m_RTC.nRegs[0x48] -#define RTC_DAYOFMONTH_A m_RTC.nRegs[0x49] -#define RTC_EXTCTRL0 m_RTC.nRegs[0x4a] -#define RTC_EXTCTRL1 m_RTC.nRegs[0x4b] -#define RTC_RTCADDR2 m_RTC.nRegs[0x4e] -#define RTC_RTCADDR3 m_RTC.nRegs[0x4f] -#define RTC_RAMLSB m_RTC.nRegs[0x50] -#define RTC_RAMMSB m_RTC.nRegs[0x51] -#define RTC_WRITECNT m_RTC.nRegs[0x5e] - -READ32_MEMBER(ip22_state::rtc_r) -{ - if( offset <= 0x0d ) - { - switch( offset ) - { - case 0x0000: -// //verboselog((machine, 2, "RTC Seconds Read: %d \n", RTC_SECONDS ); - return RTC_SECONDS; - case 0x0001: -// //verboselog((machine, 2, "RTC Seconds Alarm Read: %d \n", RTC_SECONDS_A ); - return RTC_SECONDS_A; - case 0x0002: - //verboselog((machine, 3, "RTC Minutes Read: %d \n", RTC_MINUTES ); - return RTC_MINUTES; - case 0x0003: - //verboselog((machine, 3, "RTC Minutes Alarm Read: %d \n", RTC_MINUTES_A ); - return RTC_MINUTES_A; - case 0x0004: - //verboselog((machine, 3, "RTC Hours Read: %d \n", RTC_HOURS ); - return RTC_HOURS; - case 0x0005: - //verboselog((machine, 3, "RTC Hours Alarm Read: %d \n", RTC_HOURS_A ); - return RTC_HOURS_A; - case 0x0006: - //verboselog((machine, 3, "RTC Day of Week Read: %d \n", RTC_DAYOFWEEK ); - return RTC_DAYOFWEEK; - case 0x0007: - //verboselog((machine, 3, "RTC Day of Month Read: %d \n", RTC_DAYOFMONTH ); - return RTC_DAYOFMONTH; - case 0x0008: - //verboselog((machine, 3, "RTC Month Read: %d \n", RTC_MONTH ); - return RTC_MONTH; - case 0x0009: - //verboselog((machine, 3, "RTC Year Read: %d \n", RTC_YEAR ); - return RTC_YEAR; - case 0x000a: - //verboselog((machine, 3, "RTC Register A Read: %02x \n", RTC_REGISTERA ); - return RTC_REGISTERA; - case 0x000b: - //verboselog((machine, 3, "RTC Register B Read: %02x \n", RTC_REGISTERB ); - return RTC_REGISTERB; - case 0x000c: - //verboselog((machine, 3, "RTC Register C Read: %02x \n", RTC_REGISTERC ); - return RTC_REGISTERC; - case 0x000d: - //verboselog((machine, 3, "RTC Register D Read: %02x \n", RTC_REGISTERD ); - return RTC_REGISTERD; - default: - //verboselog((machine, 3, "Unknown RTC Read: %08x (%08x)\n", 0x1fbe0000 + ( offset << 2 ), mem_mask ); - return 0; - } - } - - if( offset >= 0x0e && offset < 0x40 ) - return m_RTC.nRegs[offset]; - - if( offset >= 0x40 && offset < 0x80 && !( RTC_REGISTERA & 0x10 ) ) - return m_RTC.nUserRAM[offset - 0x40]; - - if( offset >= 0x40 && offset < 0x80 && ( RTC_REGISTERA & 0x10 ) ) - { - switch( offset ) - { - case 0x0040: - //verboselog((machine, 3, "RTC Model Byte Read: %02x\n", RTC_MODELBYTE ); - return RTC_MODELBYTE; - case 0x0041: - //verboselog((machine, 3, "RTC Serial Byte 0 Read: %02x\n", RTC_SERBYTE0 ); - return RTC_SERBYTE0; - case 0x0042: - //verboselog((machine, 3, "RTC Serial Byte 1 Read: %02x\n", RTC_SERBYTE1 ); - return RTC_SERBYTE1; - case 0x0043: - //verboselog((machine, 3, "RTC Serial Byte 2 Read: %02x\n", RTC_SERBYTE2 ); - return RTC_SERBYTE2; - case 0x0044: - //verboselog((machine, 3, "RTC Serial Byte 3 Read: %02x\n", RTC_SERBYTE3 ); - return RTC_SERBYTE3; - case 0x0045: - //verboselog((machine, 3, "RTC Serial Byte 4 Read: %02x\n", RTC_SERBYTE4 ); - return RTC_SERBYTE4; - case 0x0046: - //verboselog((machine, 3, "RTC Serial Byte 5 Read: %02x\n", RTC_SERBYTE5 ); - return RTC_SERBYTE5; - case 0x0047: - //verboselog((machine, 3, "RTC CRC Read: %02x\n", RTC_CRC ); - return RTC_CRC; - case 0x0048: - //verboselog((machine, 3, "RTC Century Read: %02x\n", RTC_CENTURY ); - return RTC_CENTURY; - case 0x0049: - //verboselog((machine, 3, "RTC Day of Month Alarm Read: %02x \n", RTC_DAYOFMONTH_A ); - return RTC_DAYOFMONTH_A; - case 0x004a: - //verboselog((machine, 3, "RTC Extended Control 0 Read: %02x \n", RTC_EXTCTRL0 ); - return RTC_EXTCTRL0; - case 0x004b: - //verboselog((machine, 3, "RTC Extended Control 1 Read: %02x \n", RTC_EXTCTRL1 ); - return RTC_EXTCTRL1; - case 0x004e: - //verboselog((machine, 3, "RTC SMI Recovery Address 2 Read: %02x \n", RTC_RTCADDR2 ); - return RTC_RTCADDR2; - case 0x004f: - //verboselog((machine, 3, "RTC SMI Recovery Address 3 Read: %02x \n", RTC_RTCADDR3 ); - return RTC_RTCADDR3; - case 0x0050: - //verboselog((machine, 3, "RTC RAM LSB Read: %02x \n", RTC_RAMLSB ); - return RTC_RAMLSB; - case 0x0051: - //verboselog((machine, 3, "RTC RAM MSB Read: %02x \n", RTC_RAMMSB ); - return RTC_RAMMSB; - case 0x0053: - return m_RTC.nRAM[ (( RTC_RAMMSB << 8 ) | RTC_RAMLSB) & 0x7ff ]; - case 0x005e: - return RTC_WRITECNT; - default: - //verboselog((machine, 3, "Unknown RTC Ext. Reg. Read: %02x\n", offset ); - return 0; - } - } - - if( offset >= 0x80 ) - return m_RTC.nUserRAM[ offset - 0x80 ]; - - return 0; -} - -WRITE32_MEMBER(ip22_state::rtc_w) -{ - RTC_WRITECNT++; - -// osd_printf_info("RTC_W: offset %x => %x (PC=%x)\n", data, offset, space.device().safe_pc()); - - if( offset <= 0x0d ) - { - switch( offset ) - { - case 0x0000: - //verboselog((machine, 3, "RTC Seconds Write: %02x \n", data ); - RTC_SECONDS = data; - break; - case 0x0001: - //verboselog((machine, 3, "RTC Seconds Alarm Write: %02x \n", data ); - RTC_SECONDS_A = data; - break; - case 0x0002: - //verboselog((machine, 3, "RTC Minutes Write: %02x \n", data ); - RTC_MINUTES = data; - break; - case 0x0003: - //verboselog((machine, 3, "RTC Minutes Alarm Write: %02x \n", data ); - RTC_MINUTES_A = data; - break; - case 0x0004: - //verboselog((machine, 3, "RTC Hours Write: %02x \n", data ); - RTC_HOURS = data; - break; - case 0x0005: - //verboselog((machine, 3, "RTC Hours Alarm Write: %02x \n", data ); - RTC_HOURS_A = data; - break; - case 0x0006: - //verboselog((machine, 3, "RTC Day of Week Write: %02x \n", data ); - RTC_DAYOFWEEK = data; - break; - case 0x0007: - //verboselog((machine, 3, "RTC Day of Month Write: %02x \n", data ); - RTC_DAYOFMONTH = data; - break; - case 0x0008: - //verboselog((machine, 3, "RTC Month Write: %02x \n", data ); - RTC_MONTH = data; - break; - case 0x0009: - //verboselog((machine, 3, "RTC Year Write: %02x \n", data ); - RTC_YEAR = data; - break; - case 0x000a: - //verboselog((machine, 3, "RTC Register A Write (Bit 7 Ignored): %02x \n", data ); - RTC_REGISTERA = data & 0x0000007f; - break; - case 0x000b: - //verboselog((machine, 3, "RTC Register B Write: %02x \n", data ); - RTC_REGISTERB = data; - break; - case 0x000c: - //verboselog((machine, 3, "RTC Register C Write (Ignored): %02x \n", data ); - break; - case 0x000d: - //verboselog((machine, 3, "RTC Register D Write (Ignored): %02x \n", data ); - break; - default: - //verboselog((machine, 3, "Unknown RTC Write: %08x (%08x): %08x\n", 0x1fbe0000 + ( offset << 2 ), mem_mask, data ); - break; - } - } - if( offset >= 0x0e && offset < 0x40 ) - { - m_RTC.nRegs[offset] = data; - return; - } - if( offset >= 0x40 && offset < 0x80 && !( RTC_REGISTERA & 0x10 ) ) - { - m_RTC.nUserRAM[offset - 0x40] = data; - return; - } - if( offset >= 0x40 && offset < 0x80 && ( RTC_REGISTERA & 0x10 ) ) - { - switch( offset ) - { - case 0x0040: - case 0x0041: - case 0x0042: - case 0x0043: - case 0x0044: - case 0x0045: - case 0x0046: - //verboselog((machine, 3, "Invalid write to RTC serial number byte %d: %02x\n", offset - 0x0040, data ); - break; - case 0x0047: - //verboselog((machine, 3, "RTC Century Write: %02x \n", data ); - RTC_CENTURY = data; - break; - case 0x0048: - //verboselog((machine, 3, "RTC Century Write: %02x \n", data ); - RTC_CENTURY = data; - break; - case 0x0049: - //verboselog((machine, 3, "RTC Day of Month Alarm Write: %02x \n", data ); - RTC_DAYOFMONTH_A = data; - break; - case 0x004a: - //verboselog((machine, 3, "RTC Extended Control 0 Write: %02x \n", data ); - RTC_EXTCTRL0 = data; - break; - case 0x004b: - //verboselog((machine, 3, "RTC Extended Control 1 Write: %02x \n", data ); - RTC_EXTCTRL1 = data; - break; - case 0x004e: - //verboselog((machine, 3, "RTC SMI Recovery Address 2 Write: %02x \n", data ); - RTC_RTCADDR2 = data; - break; - case 0x004f: - //verboselog((machine, 3, "RTC SMI Recovery Address 3 Write: %02x \n", data ); - RTC_RTCADDR3 = data; - break; - case 0x0050: - //verboselog((machine, 3, "RTC RAM LSB Write: %02x \n", data ); - RTC_RAMLSB = data; - break; - case 0x0051: - //verboselog((machine, 3, "RTC RAM MSB Write: %02x \n", data ); - RTC_RAMMSB = data; - break; - case 0x0053: - m_RTC.nRAM[ (( RTC_RAMMSB << 8 ) | RTC_RAMLSB) & 0x7ff ] = data; - break; - default: - //verboselog((machine, 3, "Unknown RTC Ext. Reg. Write: %02x: %02x\n", offset, data ); - break; - } - } - if( offset >= 0x80 ) - { - m_RTC.nUserRAM[ offset - 0x80 ] = data; - } -} - // a bit hackish, but makes the memory detection work properly and allows a big cleanup of the mapping WRITE32_MEMBER(ip22_state::ip22_write_ram) { @@ -926,7 +658,7 @@ WRITE32_MEMBER(ip22_state::hal2_w) break; case 0x0030/4: //verboselog((machine, 0, "HAL2 Indirect Address Register Write: 0x%08x (%08x)\n", data, mem_mask ); - m_HAL2.nIAR = data; + m_hal2.m_iar = data; switch( data & H2_IAR_TYPE ) { case 0x1000: @@ -1003,19 +735,19 @@ WRITE32_MEMBER(ip22_state::hal2_w) //break; case 0x0040/4: //verboselog((machine, 0, "HAL2 Indirect Data Register 0 Write: 0x%08x (%08x)\n", data, mem_mask ); - m_HAL2.nIDR[0] = data; + m_hal2.m_idr[0] = data; return; case 0x0050/4: //verboselog((machine, 0, "HAL2 Indirect Data Register 1 Write: 0x%08x (%08x)\n", data, mem_mask ); - m_HAL2.nIDR[1] = data; + m_hal2.m_idr[1] = data; return; case 0x0060/4: //verboselog((machine, 0, "HAL2 Indirect Data Register 2 Write: 0x%08x (%08x)\n", data, mem_mask ); - m_HAL2.nIDR[2] = data; + m_hal2.m_idr[2] = data; return; case 0x0070/4: //verboselog((machine, 0, "HAL2 Indirect Data Register 3 Write: 0x%08x (%08x)\n", data, mem_mask ); - m_HAL2.nIDR[3] = data; + m_hal2.m_idr[3] = data; return; } //verboselog((machine, 0, "Unknown HAL2 write: 0x%08x: 0x%08x (%08x)\n", 0x1fbd8000 + offset*4, data, mem_mask ); @@ -1046,9 +778,6 @@ void ip22_state::device_timer(emu_timer &timer, device_timer_id id, int param, v case TIMER_IP22_DMA: ip22_dma(ptr, param); break; - case TIMER_IP22_MSEC: - ip22_timer(ptr, param); - break; default: assert_always(FALSE, "Unknown id in ip22_state::device_timer"); } @@ -1058,28 +787,28 @@ TIMER_CALLBACK_MEMBER(ip22_state::ip22_dma) { timer_set(attotime::never, TIMER_IP22_DMA); #if 0 - if( m_PBUS_DMA.nActive ) + if( m_pbus_dma.m_active ) { - UINT16 temp16 = ( m_mainram[(m_PBUS_DMA.nCurPtr - 0x08000000)/4] & 0xffff0000 ) >> 16; + UINT16 temp16 = ( m_mainram[(m_pbus_dma.m_cur_ptr - 0x08000000)/4] & 0xffff0000 ) >> 16; INT16 stemp16 = (INT16)((temp16 >> 8) | (temp16 << 8)); m_dac->write_signed16(stemp16 ^ 0x8000); - m_PBUS_DMA.nCurPtr += 4; + m_pbus_dma.m_cur_ptr += 4; - m_PBUS_DMA.nWordsLeft -= 4; - if( m_PBUS_DMA.nWordsLeft == 0 ) + m_pbus_dma.m_words_left -= 4; + if( m_pbus_dma.m_words_left == 0 ) { - if( m_PBUS_DMA.nNextPtr != 0 ) + if( m_pbus_dma.m_next_ptr != 0 ) { - m_PBUS_DMA.nDescPtr = m_PBUS_DMA.nNextPtr; - m_PBUS_DMA.nCurPtr = m_mainram[(m_PBUS_DMA.nDescPtr - 0x08000000)/4]; - m_PBUS_DMA.nWordsLeft = m_mainram[(m_PBUS_DMA.nDescPtr - 0x08000000)/4+1]; - m_PBUS_DMA.nNextPtr = m_mainram[(m_PBUS_DMA.nDescPtr - 0x08000000)/4+2]; + m_pbus_dma.m_desc_ptr = m_pbus_dma.m_next_ptr; + m_pbus_dma.m_cur_ptr = m_mainram[(m_pbus_dma.m_desc_ptr - 0x08000000)/4]; + m_pbus_dma.m_words_left = m_mainram[(m_pbus_dma.m_desc_ptr - 0x08000000)/4+1]; + m_pbus_dma.m_next_ptr = m_mainram[(m_pbus_dma.m_desc_ptr - 0x08000000)/4+2]; } else { - m_PBUS_DMA.nActive = 0; + m_pbus_dma.m_active = 0; return; } } @@ -1108,14 +837,14 @@ WRITE32_MEMBER(ip22_state::hpc3_pbusdma_w) //verboselog((machine, 0, "PBUS DMA Channel %d Descriptor Pointer Write: 0x%08x\n", channel, data ); if( channel == 1 ) { - m_PBUS_DMA.nDescPtr = data; - m_PBUS_DMA.nCurPtr = m_mainram[(m_PBUS_DMA.nDescPtr - 0x08000000)/4]; - m_PBUS_DMA.nWordsLeft = m_mainram[(m_PBUS_DMA.nDescPtr - 0x08000000)/4+1]; - m_PBUS_DMA.nNextPtr = m_mainram[(m_PBUS_DMA.nDescPtr - 0x08000000)/4+2]; - //verboselog((machine, 0, "nPBUS_DMA_DescPtr = %08x\n", m_PBUS_DMA.nDescPtr ); - //verboselog((machine, 0, "nPBUS_DMA_CurPtr = %08x\n", m_PBUS_DMA.nCurPtr ); - //verboselog((machine, 0, "nPBUS_DMA_WordsLeft = %08x\n", m_PBUS_DMA.nWordsLeft ); - //verboselog((machine, 0, "nPBUS_DMA_NextPtr = %08x\n", m_PBUS_DMA.nNextPtr ); + m_pbus_dma.m_desc_ptr = data; + m_pbus_dma.m_cur_ptr = m_mainram[(m_pbus_dma.m_desc_ptr - 0x08000000)/4]; + m_pbus_dma.m_words_left = m_mainram[(m_pbus_dma.m_desc_ptr - 0x08000000)/4+1]; + m_pbus_dma.m_next_ptr = m_mainram[(m_pbus_dma.m_desc_ptr - 0x08000000)/4+2]; + //verboselog((machine, 0, "nPBUS_DMA_DescPtr = %08x\n", m_pbus_dma.m_desc_ptr ); + //verboselog((machine, 0, "nPBUS_DMA_CurPtr = %08x\n", m_pbus_dma.m_cur_ptr ); + //verboselog((machine, 0, "nPBUS_DMA_WordsLeft = %08x\n", m_pbus_dma.m_words_left ); + //verboselog((machine, 0, "nPBUS_DMA_NextPtr = %08x\n", m_pbus_dma.m_next_ptr ); } return; case 0x1000/4: @@ -1154,7 +883,7 @@ WRITE32_MEMBER(ip22_state::hpc3_pbusdma_w) if( ( data & PBUS_CTRL_DMASTART ) || ( data & PBUS_CTRL_LOAD_EN ) ) { timer_set(attotime::from_hz(44100), TIMER_IP22_DMA); - m_PBUS_DMA.nActive = 1; + m_pbus_dma.m_active = 1; } return; } @@ -1190,31 +919,21 @@ static ADDRESS_MAP_START( ip225015_map, AS_PROGRAM, 32, ip22_state ) AM_RANGE( 0x1fbd9800, 0x1fbd9bff ) AM_READWRITE(hpc3_pbus6_r, hpc3_pbus6_w ) AM_RANGE( 0x1fbdc000, 0x1fbdc7ff ) AM_RAM AM_RANGE( 0x1fbdd000, 0x1fbdd3ff ) AM_RAM - AM_RANGE( 0x1fbe0000, 0x1fbe04ff ) AM_READWRITE(rtc_r, rtc_w ) + AM_RANGE( 0x1fbe0000, 0x1fbe04ff ) AM_DEVREADWRITE8(RTC_TAG, ds1386_device, data_r, data_w, 0x000000ff) AM_RANGE( 0x1fc00000, 0x1fc7ffff ) AM_ROM AM_REGION( "user1", 0 ) AM_RANGE( 0x20000000, 0x27ffffff ) AM_SHARE("mainram") AM_RAM_WRITE(ip22_write_ram) ADDRESS_MAP_END -TIMER_CALLBACK_MEMBER(ip22_state::ip22_timer) -{ - timer_set(attotime::from_msec(1), TIMER_IP22_MSEC); -} - void ip22_state::machine_reset() { - m_HPC3.nenetr_nbdp = 0x80000000; - m_HPC3.nenetr_cbp = 0x80000000; - m_nIntCounter = 0; - RTC_REGISTERB = 0x08; - RTC_REGISTERD = 0x80; - - timer_set(attotime::from_msec(1), TIMER_IP22_MSEC); + m_hpc3.m_enetr_nbdp = 0x80000000; + m_hpc3.m_enetr_cbp = 0x80000000; // set up low RAM mirror membank("bank1")->set_base(m_mainram); - m_PBUS_DMA.nActive = 0; + m_pbus_dma.m_active = 0; m_maincpu->mips3drc_set_options(MIPS3DRC_COMPATIBLE_OPTIONS | MIPS3DRC_CHECK_OVERFLOWS); } @@ -1245,13 +964,13 @@ WRITE_LINE_MEMBER(ip22_state::scsi_irq) if (m_wd33c93->get_dma_count()) { printf("m_wd33c93->get_dma_count() is %d\n", m_wd33c93->get_dma_count() ); - if (m_HPC3.nSCSI0DMACtrl & HPC3_DMACTRL_ENABLE) + if (m_hpc3.m_scsi0_dma_ctrl & HPC3_DMACTRL_ENABLE) { - if (m_HPC3.nSCSI0DMACtrl & HPC3_DMACTRL_IRQ) logerror("IP22: Unhandled SCSI DMA IRQ\n"); + if (m_hpc3.m_scsi0_dma_ctrl & HPC3_DMACTRL_IRQ) logerror("IP22: Unhandled SCSI DMA IRQ\n"); } // HPC3 DMA: host to device - if ((m_HPC3.nSCSI0DMACtrl & HPC3_DMACTRL_ENABLE) && (m_HPC3.nSCSI0DMACtrl & HPC3_DMACTRL_DIR)) + if ((m_hpc3.m_scsi0_dma_ctrl & HPC3_DMACTRL_ENABLE) && (m_hpc3.m_scsi0_dma_ctrl & HPC3_DMACTRL_DIR)) { UINT32 wptr, tmpword; int words, dptr, twords; @@ -1259,13 +978,13 @@ WRITE_LINE_MEMBER(ip22_state::scsi_irq) words = m_wd33c93->get_dma_count(); words /= 4; - wptr = space.read_dword(m_HPC3.nSCSI0Descriptor); - m_HPC3.nSCSI0Descriptor += words*4; + wptr = space.read_dword(m_hpc3.m_scsi0_desc); + m_hpc3.m_scsi0_desc += words*4; dptr = 0; printf("DMA to device: %d words @ %x\n", words, wptr); - dump_chain(space, m_HPC3.nSCSI0Descriptor); + dump_chain(space, m_hpc3.m_scsi0_desc); if (words <= (512/4)) { @@ -1276,7 +995,7 @@ WRITE_LINE_MEMBER(ip22_state::scsi_irq) { tmpword = space.read_dword(wptr); - if (m_HPC3.nSCSI0DMACtrl & HPC3_DMACTRL_ENDIAN) + if (m_hpc3.m_scsi0_dma_ctrl & HPC3_DMACTRL_ENDIAN) { m_dma_buffer[dptr+3] = (tmpword>>24)&0xff; m_dma_buffer[dptr+2] = (tmpword>>16)&0xff; @@ -1305,14 +1024,14 @@ WRITE_LINE_MEMBER(ip22_state::scsi_irq) { //m_wd33c93->dma_read_data(512, m_dma_buffer); twords = 512/4; - m_HPC3.nSCSI0Descriptor += 512; + m_hpc3.m_scsi0_desc += 512; dptr = 0; while (twords) { tmpword = space.read_dword(wptr); - if (m_HPC3.nSCSI0DMACtrl & HPC3_DMACTRL_ENDIAN) + if (m_hpc3.m_scsi0_dma_ctrl & HPC3_DMACTRL_ENDIAN) { m_dma_buffer[dptr+3] = (tmpword>>24)&0xff; m_dma_buffer[dptr+2] = (tmpword>>16)&0xff; @@ -1342,13 +1061,13 @@ WRITE_LINE_MEMBER(ip22_state::scsi_irq) m_wd33c93->clear_dma(); #if 0 UINT32 dptr, tmpword; - UINT32 bc = space.read_dword(m_HPC3.nSCSI0Descriptor + 4); - UINT32 rptr = space.read_dword(m_HPC3.nSCSI0Descriptor); + UINT32 bc = space.read_dword(m_hpc3.m_scsi0_desc + 4); + UINT32 rptr = space.read_dword(m_hpc3.m_scsi0_desc); int length = bc & 0x3fff; int xie = (bc & 0x20000000) ? 1 : 0; int eox = (bc & 0x80000000) ? 1 : 0; - dump_chain(space, m_HPC3.nSCSI0Descriptor); + dump_chain(space, m_hpc3.m_scsi0_desc); printf("PC is %08x\n", machine.device("maincpu")->safe_pc()); printf("DMA to device: length %x xie %d eox %d\n", length, xie, eox); @@ -1359,7 +1078,7 @@ WRITE_LINE_MEMBER(ip22_state::scsi_irq) while (length > 0) { tmpword = space.read_dword(rptr); - if (m_HPC3.nSCSI0DMACtrl & HPC3_DMACTRL_ENDIAN) + if (m_hpc3.m_scsi0_dma_ctrl & HPC3_DMACTRL_ENDIAN) { m_dma_buffer[dptr+3] = (tmpword>>24)&0xff; m_dma_buffer[dptr+2] = (tmpword>>16)&0xff; @@ -1379,7 +1098,7 @@ WRITE_LINE_MEMBER(ip22_state::scsi_irq) length -= 4; } - length = space.read_dword(m_HPC3.nSCSI0Descriptor+4) & 0x3fff; + length = space.read_dword(m_hpc3.m_scsi0_desc+4) & 0x3fff; m_wd33c93->write_data(length, m_dma_buffer); // clear DMA on the controller too @@ -1393,7 +1112,7 @@ WRITE_LINE_MEMBER(ip22_state::scsi_irq) } // HPC3 DMA: device to host - if ((m_HPC3.nSCSI0DMACtrl & HPC3_DMACTRL_ENABLE) && !(m_HPC3.nSCSI0DMACtrl & HPC3_DMACTRL_DIR)) + if ((m_hpc3.m_scsi0_dma_ctrl & HPC3_DMACTRL_ENABLE) && !(m_hpc3.m_scsi0_dma_ctrl & HPC3_DMACTRL_DIR)) { UINT32 wptr, tmpword; int words, sptr, twords; @@ -1401,12 +1120,12 @@ WRITE_LINE_MEMBER(ip22_state::scsi_irq) words = m_wd33c93->get_dma_count(); words /= 4; - wptr = space.read_dword(m_HPC3.nSCSI0Descriptor); + wptr = space.read_dword(m_hpc3.m_scsi0_desc); sptr = 0; // osd_printf_info("DMA from device: %d words @ %x\n", words, wptr); - dump_chain(space, m_HPC3.nSCSI0Descriptor); + dump_chain(space, m_hpc3.m_scsi0_desc); if (words <= (1024/4)) { @@ -1415,7 +1134,7 @@ WRITE_LINE_MEMBER(ip22_state::scsi_irq) while (words) { - if (m_HPC3.nSCSI0DMACtrl & HPC3_DMACTRL_ENDIAN) + if (m_hpc3.m_scsi0_dma_ctrl & HPC3_DMACTRL_ENDIAN) { tmpword = m_dma_buffer[sptr+3]<<24 | m_dma_buffer[sptr+2]<<16 | m_dma_buffer[sptr+1]<<8 | m_dma_buffer[sptr]; } @@ -1440,7 +1159,7 @@ WRITE_LINE_MEMBER(ip22_state::scsi_irq) while (twords) { - if (m_HPC3.nSCSI0DMACtrl & HPC3_DMACTRL_ENDIAN) + if (m_hpc3.m_scsi0_dma_ctrl & HPC3_DMACTRL_ENDIAN) { tmpword = m_dma_buffer[sptr+3]<<24 | m_dma_buffer[sptr+2]<<16 | m_dma_buffer[sptr+1]<<8 | m_dma_buffer[sptr]; } @@ -1465,29 +1184,25 @@ WRITE_LINE_MEMBER(ip22_state::scsi_irq) } // clear HPC3 DMA active flag - m_HPC3.nSCSI0DMACtrl &= ~HPC3_DMACTRL_ENABLE; + m_hpc3.m_scsi0_dma_ctrl &= ~HPC3_DMACTRL_ENABLE; // set the interrupt - int3_raise_local0_irq(INT3_LOCAL0_SCSI0); + m_ioc2->raise_local0_irq(INT3_LOCAL0_SCSI0); } else { - int3_lower_local0_irq(INT3_LOCAL0_SCSI0); + m_ioc2->lower_local0_irq(INT3_LOCAL0_SCSI0); } } void ip22_state::machine_start() { - // SCSI init - machine().device<nvram_device>("nvram_user")->set_base(m_RTC.nUserRAM, 0x200); - machine().device<nvram_device>("nvram")->set_base(m_RTC.nRAM, 0x200); } -DRIVER_INIT_MEMBER(ip22_state,ip225015) +DRIVER_INIT_MEMBER(ip22_state, ip225015) { // IP22 uses 2 pieces of PC-compatible hardware: the 8042 PS/2 keyboard/mouse // interface and the 8254 PIT. Both are licensed cores embedded in the IOC custom chip. - m_nIOC_ParReadCnt = 0; } static INPUT_PORTS_START( ip225015 ) @@ -1498,80 +1213,6 @@ static INPUT_PORTS_START( ip225015 ) PORT_INCLUDE( at_keyboard ) /* IN4 - IN11 */ INPUT_PORTS_END -void ip22_state::rtc_update() -{ - RTC_SECONDS++; - - switch( RTC_REGISTERB & 0x04 ) - { - case 0x00: /* Non-BCD */ - if( RTC_SECONDS == 60 ) - { - RTC_SECONDS = 0; - RTC_MINUTES++; - } - if( RTC_MINUTES == 60 ) - { - RTC_MINUTES = 0; - RTC_HOURS++; - } - if( RTC_HOURS == 24 ) - { - RTC_HOURS = 0; - RTC_DAYOFMONTH++; - } - RTC_SECONDS_A = RTC_SECONDS; - RTC_MINUTES_A = RTC_MINUTES; - RTC_HOURS_A = RTC_HOURS; - break; - case 0x04: /* BCD */ - if( ( RTC_SECONDS & 0x0f ) == 0x0a ) - { - RTC_SECONDS -= 0x0a; - RTC_SECONDS += 0x10; - } - if( ( RTC_SECONDS & 0xf0 ) == 0x60 ) - { - RTC_SECONDS -= 0x60; - RTC_MINUTES++; - } - if( ( RTC_MINUTES & 0x0f ) == 0x0a ) - { - RTC_MINUTES -= 0x0a; - RTC_MINUTES += 0x10; - } - if( ( RTC_MINUTES & 0xf0 ) == 0x60 ) - { - RTC_MINUTES -= 0x60; - RTC_HOURS++; - } - if( ( RTC_HOURS & 0x0f ) == 0x0a ) - { - RTC_HOURS -= 0x0a; - RTC_HOURS += 0x10; - } - if( RTC_HOURS == 0x24 ) - { - RTC_HOURS = 0; - RTC_DAYOFMONTH++; - } - RTC_SECONDS_A = RTC_SECONDS; - RTC_MINUTES_A = RTC_MINUTES; - RTC_HOURS_A = RTC_HOURS; - break; - } -} - -INTERRUPT_GEN_MEMBER(ip22_state::ip22_vbl) -{ - m_nIntCounter++; -// if( m_nIntCounter == 60 ) - { - m_nIntCounter = 0; - rtc_update(); - } -} - static MACHINE_CONFIG_FRAGMENT( cdrom_config ) MCFG_DEVICE_MODIFY( "cdda" ) MCFG_SOUND_ROUTE( 0, "^^^^lspeaker", 1.0 ) @@ -1583,11 +1224,6 @@ static MACHINE_CONFIG_START( ip225015, ip22_state ) //MCFG_MIPS3_ICACHE_SIZE(32768) //MCFG_MIPS3_DCACHE_SIZE(32768) MCFG_CPU_PROGRAM_MAP( ip225015_map) - MCFG_CPU_VBLANK_INT_DRIVER("screen", ip22_state, ip22_vbl) - - - MCFG_NVRAM_ADD_0FILL("nvram") - MCFG_NVRAM_ADD_0FILL("nvram_user") MCFG_DEVICE_ADD("pit8254", PIT8254, 0) MCFG_PIT8253_CLK0(1000000) @@ -1628,6 +1264,10 @@ static MACHINE_CONFIG_START( ip225015, ip22_state ) MCFG_DEVICE_ADD("kbdc", KBDC8042, 0) MCFG_KBDC8042_KEYBOARD_TYPE(KBDC8042_STANDARD) MCFG_KBDC8042_SYSTEM_RESET_CB(INPUTLINE("maincpu", INPUT_LINE_RESET)) + + MCFG_IOC2_ADD(IOC2_TAG) + + MCFG_DS1386_8K_ADD(RTC_TAG, 32768) MACHINE_CONFIG_END static MACHINE_CONFIG_DERIVED( ip224613, ip225015 ) @@ -1635,7 +1275,6 @@ static MACHINE_CONFIG_DERIVED( ip224613, ip225015 ) //MCFG_MIPS3_ICACHE_SIZE(32768) //MCFG_MIPS3_DCACHE_SIZE(32768) MCFG_CPU_PROGRAM_MAP( ip225015_map) - MCFG_CPU_VBLANK_INT_DRIVER("screen", ip22_state, ip22_vbl) MACHINE_CONFIG_END static MACHINE_CONFIG_DERIVED( ip244415, ip225015 ) @@ -1643,7 +1282,6 @@ static MACHINE_CONFIG_DERIVED( ip244415, ip225015 ) //MCFG_MIPS3_ICACHE_SIZE(32768) //MCFG_MIPS3_DCACHE_SIZE(32768) MCFG_CPU_PROGRAM_MAP( ip225015_map) - MCFG_CPU_VBLANK_INT_DRIVER("screen", ip22_state, ip22_vbl) MACHINE_CONFIG_END ROM_START( ip225015 ) diff --git a/src/tools/imgtool/iflopimg.cpp b/src/tools/imgtool/iflopimg.cpp index 9b819a7bdb1..4863fd130a3 100644 --- a/src/tools/imgtool/iflopimg.cpp +++ b/src/tools/imgtool/iflopimg.cpp @@ -102,10 +102,11 @@ struct imgtool_floppy_image -static imgtoolerr_t imgtool_floppy_open_internal(imgtool::image *image, imgtool::stream &f, int noclose) +static imgtoolerr_t imgtool_floppy_open_internal(imgtool::image *image, imgtool::stream::ptr &&stream, int noclose) { floperr_t ferr; - imgtoolerr_t err; + imgtoolerr_t err = IMGTOOLERR_SUCCESS; + imgtool::stream *f = nullptr; struct imgtool_floppy_image *fimg; const imgtool_class *imgclass; const struct FloppyFormat *format; @@ -116,38 +117,46 @@ static imgtoolerr_t imgtool_floppy_open_internal(imgtool::image *image, imgtool: format = (const struct FloppyFormat *) imgclass->derived_param; open = (imgtoolerr_t (*)(imgtool::image *, imgtool::stream *)) imgtool_get_info_ptr(imgclass, IMGTOOLINFO_PTR_FLOPPY_OPEN); - /* open up the floppy */ - ferr = floppy_open(&f, noclose ? &imgtool_noclose_ioprocs : &imgtool_ioprocs, + // extract the pointer + f = stream.release(); + + // open up the floppy + ferr = floppy_open(f, noclose ? &imgtool_noclose_ioprocs : &imgtool_ioprocs, "", format, FLOPPY_FLAGS_READWRITE, &fimg->floppy); if (ferr) { err = imgtool_floppy_error(ferr); - return err; + goto done; } + f = nullptr; // the floppy object has the stream now if (open) { err = open(image, nullptr); if (err) - return err; + goto done; } - return IMGTOOLERR_SUCCESS; +done: + if (f) + delete f; + return err; } -static imgtoolerr_t imgtool_floppy_open(imgtool::image *image, imgtool::stream &f) +static imgtoolerr_t imgtool_floppy_open(imgtool::image *image, imgtool::stream::ptr &&stream) { - return imgtool_floppy_open_internal(image, f, FALSE); + return imgtool_floppy_open_internal(image, std::move(stream), FALSE); } -static imgtoolerr_t imgtool_floppy_create(imgtool::image *image, imgtool::stream &f, util::option_resolution *opts) +static imgtoolerr_t imgtool_floppy_create(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *opts) { floperr_t ferr; imgtoolerr_t err = IMGTOOLERR_SUCCESS; + imgtool::stream *f = nullptr; struct imgtool_floppy_image *fimg; const imgtool_class *imgclass; const struct FloppyFormat *format; @@ -160,15 +169,19 @@ static imgtoolerr_t imgtool_floppy_create(imgtool::image *image, imgtool::stream create = (imgtoolerr_t (*)(imgtool::image *, imgtool::stream *, util::option_resolution *)) imgtool_get_info_ptr(imgclass, IMGTOOLINFO_PTR_FLOPPY_CREATE); open = (imgtoolerr_t (*)(imgtool::image *, imgtool::stream *)) imgtool_get_info_ptr(imgclass, IMGTOOLINFO_PTR_FLOPPY_OPEN); - /* open up the floppy */ - ferr = floppy_create(&f, &imgtool_ioprocs, format, opts, &fimg->floppy); + // extract the pointer + f = stream.release(); + + // open up the floppy + ferr = floppy_create(f, &imgtool_ioprocs, format, opts, &fimg->floppy); if (ferr) { err = imgtool_floppy_error(ferr); goto done; } + f = nullptr; // the floppy object has the stream now - /* do we have to do extra stuff when creating the image? */ + // do we have to do extra stuff when creating the image? if (create) { err = create(image, nullptr, opts); @@ -176,7 +189,7 @@ static imgtoolerr_t imgtool_floppy_create(imgtool::image *image, imgtool::stream goto done; } - /* do we have to do extra stuff when opening the image? */ + // do we have to do extra stuff when opening the image? if (open) { err = open(image, nullptr); @@ -185,6 +198,8 @@ static imgtoolerr_t imgtool_floppy_create(imgtool::image *image, imgtool::stream } done: + if (f) + delete f; return err; } diff --git a/src/tools/imgtool/imghd.cpp b/src/tools/imgtool/imghd.cpp index e21c6fbbfdd..8c3e759a53b 100644 --- a/src/tools/imgtool/imghd.cpp +++ b/src/tools/imgtool/imghd.cpp @@ -218,7 +218,7 @@ const hard_disk_info *imghd_get_header(struct mess_hard_disk_file *disk) } -static imgtoolerr_t mess_hd_image_create(imgtool::image *image, imgtool::stream &f, util::option_resolution *createoptions); +static imgtoolerr_t mess_hd_image_create(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *createoptions); enum { @@ -257,7 +257,7 @@ void hd_get_info(const imgtool_class *imgclass, UINT32 state, union imgtoolinfo -static imgtoolerr_t mess_hd_image_create(imgtool::image *image, imgtool::stream &f, util::option_resolution *createoptions) +static imgtoolerr_t mess_hd_image_create(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *createoptions) { UINT32 blocksize, cylinders, heads, sectors, seclen; @@ -268,5 +268,5 @@ static imgtoolerr_t mess_hd_image_create(imgtool::image *image, imgtool::stream sectors = createoptions->lookup_int(mess_hd_createopts_sectors); seclen = createoptions->lookup_int(mess_hd_createopts_seclen); - return imghd_create(f, blocksize, cylinders, heads, sectors, seclen); + return imghd_create(*stream.get(), blocksize, cylinders, heads, sectors, seclen); } diff --git a/src/tools/imgtool/imgtool.cpp b/src/tools/imgtool/imgtool.cpp index 2a45d48434d..03f2eaed6e7 100644 --- a/src/tools/imgtool/imgtool.cpp +++ b/src/tools/imgtool/imgtool.cpp @@ -896,7 +896,7 @@ imgtoolerr_t imgtool::image::internal_open(const imgtool_module *module, const c int read_or_write, util::option_resolution *createopts, imgtool::image::ptr &outimg) { imgtoolerr_t err; - imgtool::stream *f = nullptr; + imgtool::stream::ptr stream; imgtool::image::ptr image; object_pool *pool = nullptr; void *extra_bytes = nullptr; @@ -919,8 +919,8 @@ imgtoolerr_t imgtool::image::internal_open(const imgtool_module *module, const c } // open the stream - f = imgtool::stream::open(fname, read_or_write); - if (!f) + stream = imgtool::stream::ptr(imgtool::stream::open(fname, read_or_write)); + if (!stream) { err = (imgtoolerr_t)(IMGTOOLERR_FILENOTFOUND | IMGTOOLERR_SRC_IMAGEFILE); goto done; @@ -951,8 +951,8 @@ imgtoolerr_t imgtool::image::internal_open(const imgtool_module *module, const c // actually call create or open err = (read_or_write == OSD_FOPEN_RW_CREATE) - ? module->create(image.get(), f, createopts) - : module->open(image.get(), f); + ? module->create(image.get(), std::move(stream), createopts) + : module->open(image.get(), std::move(stream)); if (err) { err = markerrorsource(err); @@ -965,9 +965,6 @@ imgtoolerr_t imgtool::image::internal_open(const imgtool_module *module, const c outimg = std::move(image); done: - if (err && f) - delete f; - if (pool) pool_free_lib(pool); return err; diff --git a/src/tools/imgtool/imgtool.h b/src/tools/imgtool/imgtool.h index db51ea75e16..809fdd5b187 100644 --- a/src/tools/imgtool/imgtool.h +++ b/src/tools/imgtool/imgtool.h @@ -14,6 +14,7 @@ #include <stdlib.h> #include <stdio.h> #include <assert.h> +#include <functional> #include "corestr.h" #include "formats/flopimg.h" @@ -202,23 +203,23 @@ namespace imgtool unsigned int m_supports_lastmodified_time : 1; unsigned int m_supports_bootblock : 1; /* this module supports loading/storing the boot block */ - imgtoolerr_t(*m_begin_enum) (imgtool::directory *enumeration, const char *path); - imgtoolerr_t(*m_next_enum) (imgtool::directory *enumeration, imgtool_dirent *ent); - void(*m_close_enum) (imgtool::directory *enumeration); - imgtoolerr_t(*m_free_space) (imgtool::partition *partition, UINT64 *size); - imgtoolerr_t(*m_read_file) (imgtool::partition *partition, const char *filename, const char *fork, imgtool::stream &destf); - imgtoolerr_t(*m_write_file) (imgtool::partition *partition, const char *filename, const char *fork, imgtool::stream &sourcef, util::option_resolution *opts); - imgtoolerr_t(*m_delete_file) (imgtool::partition *partition, const char *filename); - imgtoolerr_t(*m_list_forks) (imgtool::partition *partition, const char *path, imgtool_forkent *ents, size_t len); - imgtoolerr_t(*m_create_dir) (imgtool::partition *partition, const char *path); - imgtoolerr_t(*m_delete_dir) (imgtool::partition *partition, const char *path); - imgtoolerr_t(*m_list_attrs) (imgtool::partition *partition, const char *path, UINT32 *attrs, size_t len); - imgtoolerr_t(*m_get_attrs) (imgtool::partition *partition, const char *path, const UINT32 *attrs, imgtool_attribute *values); - imgtoolerr_t(*m_set_attrs) (imgtool::partition *partition, const char *path, const UINT32 *attrs, const imgtool_attribute *values); - imgtoolerr_t(*m_attr_name) (UINT32 attribute, const imgtool_attribute *attr, char *buffer, size_t buffer_len); - imgtoolerr_t(*m_get_iconinfo) (imgtool::partition *partition, const char *path, imgtool_iconinfo *iconinfo); - imgtoolerr_t(*m_suggest_transfer)(imgtool::partition *partition, const char *path, imgtool_transfer_suggestion *suggestions, size_t suggestions_length); - imgtoolerr_t(*m_get_chain) (imgtool::partition *partition, const char *path, imgtool_chainent *chain, size_t chain_size); + std::function<imgtoolerr_t(imgtool::directory *enumeration, const char *path)> m_begin_enum; + std::function<imgtoolerr_t(imgtool::directory *enumeration, imgtool_dirent *ent)> m_next_enum; + std::function<void(imgtool::directory *enumeration)> m_close_enum; + std::function<imgtoolerr_t(imgtool::partition *partition, UINT64 *size)> m_free_space; + std::function<imgtoolerr_t(imgtool::partition *partition, const char *filename, const char *fork, imgtool::stream &destf)> m_read_file; + std::function<imgtoolerr_t(imgtool::partition *partition, const char *filename, const char *fork, imgtool::stream &sourcef, util::option_resolution *opts)> m_write_file; + std::function<imgtoolerr_t(imgtool::partition *partition, const char *filename)> m_delete_file; + std::function<imgtoolerr_t(imgtool::partition *partition, const char *path, imgtool_forkent *ents, size_t len)> m_list_forks; + std::function<imgtoolerr_t(imgtool::partition *partition, const char *path)> m_create_dir; + std::function<imgtoolerr_t(imgtool::partition *partition, const char *path)> m_delete_dir; + std::function<imgtoolerr_t(imgtool::partition *partition, const char *path, UINT32 *attrs, size_t len)> m_list_attrs; + std::function<imgtoolerr_t(imgtool::partition *partition, const char *path, const UINT32 *attrs, imgtool_attribute *values)> m_get_attrs; + std::function<imgtoolerr_t(imgtool::partition *partition, const char *path, const UINT32 *attrs, const imgtool_attribute *values)> m_set_attrs; + std::function<imgtoolerr_t(UINT32 attribute, const imgtool_attribute *attr, char *buffer, size_t buffer_len)> m_attr_name; + std::function<imgtoolerr_t(imgtool::partition *partition, const char *path, imgtool_iconinfo *iconinfo)> m_get_iconinfo; + std::function<imgtoolerr_t(imgtool::partition *partition, const char *path, imgtool_transfer_suggestion *suggestions, size_t suggestions_length)> m_suggest_transfer; + std::function<imgtoolerr_t(imgtool::partition *partition, const char *path, imgtool_chainent *chain, size_t chain_size)> m_get_chain; const util::option_guide *m_writefile_optguide; std::string m_writefile_optspec; diff --git a/src/tools/imgtool/library.cpp b/src/tools/imgtool/library.cpp index 760025843ca..64e14722d68 100644 --- a/src/tools/imgtool/library.cpp +++ b/src/tools/imgtool/library.cpp @@ -69,8 +69,8 @@ void library::add_class(const imgtool_class *imgclass) module->tracks_are_called_cylinders = imgtool_get_info_int(imgclass, IMGTOOLINFO_INT_TRACKS_ARE_CALLED_CYLINDERS) ? 1 : 0; module->writing_untested = imgtool_get_info_int(imgclass, IMGTOOLINFO_INT_WRITING_UNTESTED) ? 1 : 0; module->creation_untested = imgtool_get_info_int(imgclass, IMGTOOLINFO_INT_CREATION_UNTESTED) ? 1 : 0; - module->open = (imgtoolerr_t (*)(imgtool::image *, imgtool::stream *)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_OPEN); - module->create = (imgtoolerr_t (*)(imgtool::image *, imgtool::stream *, util::option_resolution *)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_CREATE); + module->open = (imgtoolerr_t (*)(imgtool::image *, imgtool::stream::ptr &&)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_OPEN); + module->create = (imgtoolerr_t (*)(imgtool::image *, imgtool::stream::ptr &&, util::option_resolution *)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_CREATE); module->close = (void (*)(imgtool::image *)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_CLOSE); module->info = (void (*)(imgtool::image *, char *, size_t)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_INFO); module->read_sector = (imgtoolerr_t (*)(imgtool::image *, UINT32, UINT32, UINT32, std::vector<UINT8> &)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_READ_SECTOR); diff --git a/src/tools/imgtool/library.h b/src/tools/imgtool/library.h index 7403dc59db3..c4bfa48e4f7 100644 --- a/src/tools/imgtool/library.h +++ b/src/tools/imgtool/library.h @@ -254,9 +254,9 @@ union imgtoolinfo void * f; /* generic function pointers */ char * s; /* generic strings */ - imgtoolerr_t (*open) (imgtool::image *image, imgtool::stream &stream); + imgtoolerr_t (*open) (imgtool::image *image, imgtool::stream::ptr &&stream); void (*close) (imgtool::image *image); - imgtoolerr_t (*create) (imgtool::image *image, imgtool::stream &stream, util::option_resolution *opts); + imgtoolerr_t (*create) (imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *opts); imgtoolerr_t (*create_partition) (imgtool::image *image, UINT64 first_block, UINT64 block_count); void (*info) (imgtool::image *image, char *string, size_t len); imgtoolerr_t (*begin_enum) (imgtool::directory *enumeration, const char *path); @@ -347,10 +347,10 @@ struct imgtool_module unsigned int writing_untested : 1; /* used when we support writing, but not in main build */ unsigned int creation_untested : 1; /* used when we support creation, but not in main build */ - imgtoolerr_t (*open) (imgtool::image *image, imgtool::stream *f); + imgtoolerr_t (*open) (imgtool::image *image, imgtool::stream::ptr &&stream); void (*close) (imgtool::image *image); void (*info) (imgtool::image *image, char *string, size_t len); - imgtoolerr_t (*create) (imgtool::image *image, imgtool::stream *f, util::option_resolution *opts); + imgtoolerr_t (*create) (imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *opts); imgtoolerr_t (*get_geometry) (imgtool::image *image, UINT32 *track, UINT32 *heads, UINT32 *sectors); imgtoolerr_t (*read_sector) (imgtool::image *image, UINT32 track, UINT32 head, UINT32 sector, std::vector<UINT8> &buffer); imgtoolerr_t (*write_sector) (imgtool::image *image, UINT32 track, UINT32 head, UINT32 sector, const void *buffer, size_t len); diff --git a/src/tools/imgtool/modules/amiga.cpp b/src/tools/imgtool/modules/amiga.cpp index 3efd76e9117..ed2080bb994 100644 --- a/src/tools/imgtool/modules/amiga.cpp +++ b/src/tools/imgtool/modules/amiga.cpp @@ -1742,12 +1742,11 @@ static imgtoolerr_t update_disk_alteration_date(imgtool::image *img) *****************************************************************************/ -static imgtoolerr_t amiga_image_open(imgtool::image *img, imgtool::stream &stream) +static imgtoolerr_t amiga_image_open(imgtool::image *img, imgtool::stream::ptr &&stream) { amiga_floppy *f = (amiga_floppy *) img->extra_bytes(); - UINT64 size = stream.size(); + UINT64 size = stream->size(); - f->stream = &stream; f->sectors = size/BSIZE/80/2; if (f->sectors != 11 && f->sectors != 22) @@ -1755,12 +1754,16 @@ static imgtoolerr_t amiga_image_open(imgtool::image *img, imgtool::stream &strea return IMGTOOLERR_CORRUPTIMAGE; } + f->stream = stream.release(); return IMGTOOLERR_SUCCESS; } static void amiga_image_exit(imgtool::image *img) { + amiga_floppy *f = (amiga_floppy *)img->extra_bytes(); + if (f->stream) + delete f->stream; } @@ -2195,7 +2198,7 @@ static imgtoolerr_t amiga_image_writefile(imgtool::partition *partition, const c } -static imgtoolerr_t amiga_image_create(imgtool::image *img, imgtool::stream &stream, util::option_resolution *opts) +static imgtoolerr_t amiga_image_create(imgtool::image *img, imgtool::stream::ptr &&stream, util::option_resolution *opts) { amiga_floppy *f = (amiga_floppy *) img->extra_bytes(); const std::string &dskname = opts->lookup_string('N'); @@ -2206,7 +2209,7 @@ static imgtoolerr_t amiga_image_create(imgtool::image *img, imgtool::stream &str time_t now; int blocks; - f->stream = &stream; + f->stream = stream.get(); switch (opts->lookup_int('S')) { @@ -2296,6 +2299,7 @@ static imgtoolerr_t amiga_image_create(imgtool::image *img, imgtool::stream &str ret = write_block(img, blocks - 1, buffer); if (ret) return ret; + f->stream = stream.release(); return IMGTOOLERR_SUCCESS; } diff --git a/src/tools/imgtool/modules/bml3.cpp b/src/tools/imgtool/modules/bml3.cpp index 62f6940dea3..853b771896a 100644 --- a/src/tools/imgtool/modules/bml3.cpp +++ b/src/tools/imgtool/modules/bml3.cpp @@ -498,7 +498,7 @@ static imgtoolerr_t prepare_dirent(UINT8 variant, struct bml3_dirent *ent, const -static imgtoolerr_t bml3_diskimage_open(imgtool::image *image, imgtool::stream &stream) +static imgtoolerr_t bml3_diskimage_open(imgtool::image *image, imgtool::stream::ptr &&dummy) { // imgtoolerr_t err; floperr_t ferr; diff --git a/src/tools/imgtool/modules/concept.cpp b/src/tools/imgtool/modules/concept.cpp index 6a285903a7f..7d5d65f1914 100644 --- a/src/tools/imgtool/modules/concept.cpp +++ b/src/tools/imgtool/modules/concept.cpp @@ -126,7 +126,7 @@ struct concept_iterator }; -static imgtoolerr_t concept_image_init(imgtool::image *img, imgtool::stream &f); +static imgtoolerr_t concept_image_init(imgtool::image *img, imgtool::stream::ptr &&stream); static void concept_image_exit(imgtool::image *img); static void concept_image_info(imgtool::image *img, char *string, size_t len); static imgtoolerr_t concept_image_beginenum(imgtool::directory *enumeration, const char *path); @@ -260,19 +260,17 @@ static int get_catalog_entry(concept_image *image, const unsigned char *filename /* Open a file as a concept_image. */ -static imgtoolerr_t concept_image_init(imgtool::image *img, imgtool::stream &f) +static imgtoolerr_t concept_image_init(imgtool::image *img, imgtool::stream::ptr &&stream) { concept_image *image = (concept_image *) img->extra_bytes(); int reply; int i; unsigned totphysrecs; - image->file_handle = &f; - /* read device directory */ for (i=0; i<4; i++) { - reply = read_physical_record(f, i+2, ((char *) & image->dev_dir)+i*512); + reply = read_physical_record(*stream, i+2, ((char *) & image->dev_dir)+i*512); if (reply) return IMGTOOLERR_READERROR; } @@ -289,6 +287,7 @@ static imgtoolerr_t concept_image_init(imgtool::image *img, imgtool::stream &f) return IMGTOOLERR_CORRUPTIMAGE; } + image->file_handle = stream.release(); return IMGTOOLERR_SUCCESS; } diff --git a/src/tools/imgtool/modules/cybiko.cpp b/src/tools/imgtool/modules/cybiko.cpp index f6e213fe6a2..b72816ff92e 100644 --- a/src/tools/imgtool/modules/cybiko.cpp +++ b/src/tools/imgtool/modules/cybiko.cpp @@ -265,9 +265,9 @@ static int cfs_verify(cybiko_file_system &cfs) return TRUE; } -static int cfs_init(cybiko_file_system &cfs, imgtool::stream &stream, int flash_type) +static int cfs_init(cybiko_file_system &cfs, imgtool::stream::ptr &&stream, int flash_type) { - cfs.stream = &stream; + cfs.stream = stream.release(); switch (flash_type) { case FLASH_TYPE_AT45DB041 : cfs.page_count = 2048; cfs.page_size = 264; break; @@ -345,13 +345,13 @@ static int flash_option_to_flash_type( int option) } } -static imgtoolerr_t cybiko_image_open(imgtool::image *image, imgtool::stream &stream) +static imgtoolerr_t cybiko_image_open(imgtool::image *image, imgtool::stream::ptr &&stream) { cybiko_file_system *cfs = (cybiko_file_system*)image->extra_bytes(); int flash_type; // init - flash_type = flash_size_to_flash_type(stream.size()); - if (!cfs_init(*cfs, stream, flash_type)) return IMGTOOLERR_CORRUPTIMAGE; + flash_type = flash_size_to_flash_type(stream->size()); + if (!cfs_init(*cfs, std::move(stream), flash_type)) return IMGTOOLERR_CORRUPTIMAGE; // verify if (!cfs_verify(*cfs)) return IMGTOOLERR_CORRUPTIMAGE; // ok @@ -364,13 +364,13 @@ static void cybiko_image_close( imgtool::image *image) delete cfs->stream; } -static imgtoolerr_t cybiko_image_create( imgtool::image *image, imgtool::stream &stream, util::option_resolution *opts) +static imgtoolerr_t cybiko_image_create( imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *opts) { cybiko_file_system *cfs = (cybiko_file_system*)image->extra_bytes(); int flash_type; // init flash_type = flash_option_to_flash_type(opts->lookup_int('F')); - if (!cfs_init(*cfs, stream, flash_type)) return IMGTOOLERR_CORRUPTIMAGE; + if (!cfs_init(*cfs, std::move(stream), flash_type)) return IMGTOOLERR_CORRUPTIMAGE; // format if (!cfs_format(cfs)) return IMGTOOLERR_CORRUPTIMAGE; // ok diff --git a/src/tools/imgtool/modules/cybikoxt.cpp b/src/tools/imgtool/modules/cybikoxt.cpp index 6c43472011f..475d0449136 100644 --- a/src/tools/imgtool/modules/cybikoxt.cpp +++ b/src/tools/imgtool/modules/cybikoxt.cpp @@ -260,9 +260,9 @@ static bool cfs_verify(cybiko_file_system &cfs) return true; } -static bool cfs_init(cybiko_file_system &cfs, imgtool::stream &stream) +static bool cfs_init(cybiko_file_system &cfs, imgtool::stream::ptr &&stream) { - cfs.stream = &stream; + cfs.stream = stream.release(); cfs.page_count = 2005; cfs.page_size = 258; cfs.block_count_boot = 5; @@ -319,11 +319,11 @@ static UINT32 cfs_calc_free_space( cybiko_file_system *cfs, UINT16 blocks) return free_space; } -static imgtoolerr_t cybiko_image_open(imgtool::image *image, imgtool::stream &stream) +static imgtoolerr_t cybiko_image_open(imgtool::image *image, imgtool::stream::ptr &&stream) { cybiko_file_system *cfs = (cybiko_file_system*)image->extra_bytes(); // init - if (!cfs_init(*cfs, stream)) return IMGTOOLERR_CORRUPTIMAGE; + if (!cfs_init(*cfs, std::move(stream))) return IMGTOOLERR_CORRUPTIMAGE; // verify if (!cfs_verify(*cfs)) return IMGTOOLERR_CORRUPTIMAGE; // ok @@ -336,11 +336,11 @@ static void cybiko_image_close(imgtool::image *image) delete cfs->stream; } -static imgtoolerr_t cybiko_image_create(imgtool::image *image, imgtool::stream &stream, util::option_resolution *opts) +static imgtoolerr_t cybiko_image_create(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *opts) { cybiko_file_system *cfs = (cybiko_file_system*)image->extra_bytes(); // init - if (!cfs_init(*cfs, stream)) return IMGTOOLERR_CORRUPTIMAGE; + if (!cfs_init(*cfs, std::move(stream))) return IMGTOOLERR_CORRUPTIMAGE; // format if (!cfs_format(cfs)) return IMGTOOLERR_CORRUPTIMAGE; // ok diff --git a/src/tools/imgtool/modules/hp48.cpp b/src/tools/imgtool/modules/hp48.cpp index 1556e1ffb74..e6929f2e967 100644 --- a/src/tools/imgtool/modules/hp48.cpp +++ b/src/tools/imgtool/modules/hp48.cpp @@ -327,10 +327,10 @@ static UINT16 crc(UINT8* data, int len) *****************************************************************************/ -static imgtoolerr_t hp48_open(imgtool::image *img, imgtool::stream &stream) +static imgtoolerr_t hp48_open(imgtool::image *img, imgtool::stream::ptr &&stream) { hp48_card* c = (hp48_card*) img->extra_bytes(); - int size = stream.size(); + int size = stream->size(); /* check that size is a power of 2 between 32 KB and 4 MG */ if ( (size < 32 * 1024) || @@ -341,30 +341,31 @@ static imgtoolerr_t hp48_open(imgtool::image *img, imgtool::stream &stream) } /* store info */ - c->stream = &stream; + c->stream = stream.get(); c->modified = 0; c->size = size; c->data = (UINT8*) malloc( 2 * size ); if ( !c->data ) { - return IMGTOOLERR_READERROR; + return IMGTOOLERR_READERROR; } /* fully load image */ - stream.seek(0, SEEK_SET); - if (stream.read(c->data, size) < size) + c->stream->seek(0, SEEK_SET); + if (c->stream->read(c->data, size) < size) { - return IMGTOOLERR_READERROR; + return IMGTOOLERR_READERROR; } unpack( c->data, c->data, 2 * size ); + c->stream = stream.release(); return IMGTOOLERR_SUCCESS; } static imgtoolerr_t hp48_create(imgtool::image* img, - imgtool::stream &stream, + imgtool::stream::ptr &&stream, util::option_resolution *opts) { hp48_card* c = (hp48_card*) img->extra_bytes(); @@ -372,7 +373,7 @@ static imgtoolerr_t hp48_create(imgtool::image* img, size = opts->lookup_int('S'); - c->stream = &stream; + c->stream = stream.get(); c->modified = 1; c->size = size * 1024; c->data = (UINT8*) malloc( 2 * c->size ); @@ -384,6 +385,7 @@ static imgtoolerr_t hp48_create(imgtool::image* img, /* zeroing the image seems fine */ memset( c->data, 0, 2 * c->size ); + c->stream = stream.release(); return IMGTOOLERR_SUCCESS; } diff --git a/src/tools/imgtool/modules/hp9845_tape.cpp b/src/tools/imgtool/modules/hp9845_tape.cpp index 23eb78afe30..807c250ff13 100644 --- a/src/tools/imgtool/modules/hp9845_tape.cpp +++ b/src/tools/imgtool/modules/hp9845_tape.cpp @@ -1042,22 +1042,27 @@ static tape_image_t& get_tape_image(tape_state_t& ts) /******************************************************************************** * Imgtool functions ********************************************************************************/ -static imgtoolerr_t hp9845_tape_open(imgtool::image *image, imgtool::stream &stream) +static imgtoolerr_t hp9845_tape_open(imgtool::image *image, imgtool::stream::ptr &&stream) { tape_state_t& state = get_tape_state(image); - state.stream = &stream; + state.stream = stream.get(); tape_image_t& tape_image = get_tape_image(state); - return tape_image.load_from_file(&stream); + imgtoolerr_t err = tape_image.load_from_file(state.stream); + if (err) + return err; + + state.stream = stream.release(); + return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t hp9845_tape_create(imgtool::image *image, imgtool::stream &stream, util::option_resolution *opts) +static imgtoolerr_t hp9845_tape_create(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *opts) { tape_state_t& state = get_tape_state(image); - state.stream = &stream; + state.stream = stream.release(); tape_image_t& tape_image = get_tape_image(state); diff --git a/src/tools/imgtool/modules/mac.cpp b/src/tools/imgtool/modules/mac.cpp index d51a3cf3539..6310fe34f2f 100644 --- a/src/tools/imgtool/modules/mac.cpp +++ b/src/tools/imgtool/modules/mac.cpp @@ -1542,7 +1542,7 @@ struct mfs_dirref -static imgtoolerr_t mfs_image_create(imgtool::image *image, imgtool::stream &stream, util::option_resolution *opts) +static imgtoolerr_t mfs_image_create(imgtool::image *image, imgtool::stream::ptr &&dummy, util::option_resolution *opts) { imgtoolerr_t err; UINT8 buffer[512]; @@ -1606,7 +1606,7 @@ static imgtoolerr_t mfs_image_create(imgtool::image *image, imgtool::stream &str Return imgtool error code */ -static imgtoolerr_t mfs_image_open(imgtool::image *image, imgtool::stream &stream) +static imgtoolerr_t mfs_image_open(imgtool::image *image, imgtool::stream::ptr &&dummy) { imgtoolerr_t err; struct mac_l2_imgref *l2_img; @@ -3033,7 +3033,7 @@ static int hfs_catKey_compare(const void *p1, const void *p2) Return imgtool error code */ -static imgtoolerr_t hfs_image_open(imgtool::image *image, imgtool::stream &stream) +static imgtoolerr_t hfs_image_open(imgtool::image *image, imgtool::stream::ptr &&stream) { imgtoolerr_t err; struct mac_l2_imgref *l2_img; diff --git a/src/tools/imgtool/modules/os9.cpp b/src/tools/imgtool/modules/os9.cpp index f27a751f50a..aa3f994b6cd 100644 --- a/src/tools/imgtool/modules/os9.cpp +++ b/src/tools/imgtool/modules/os9.cpp @@ -622,7 +622,7 @@ done: -static imgtoolerr_t os9_diskimage_open(imgtool::image *image, imgtool::stream &stream) +static imgtoolerr_t os9_diskimage_open(imgtool::image *image, imgtool::stream::ptr &&dummy) { imgtoolerr_t err; floperr_t ferr; @@ -710,7 +710,7 @@ static imgtoolerr_t os9_diskimage_open(imgtool::image *image, imgtool::stream &s -static imgtoolerr_t os9_diskimage_create(imgtool::image *img, imgtool::stream &stream, util::option_resolution *opts) +static imgtoolerr_t os9_diskimage_create(imgtool::image *img, imgtool::stream::ptr &&stream, util::option_resolution *opts) { imgtoolerr_t err; dynamic_buffer header; diff --git a/src/tools/imgtool/modules/pc_flop.cpp b/src/tools/imgtool/modules/pc_flop.cpp index 5826a0b3747..e44347465a4 100644 --- a/src/tools/imgtool/modules/pc_flop.cpp +++ b/src/tools/imgtool/modules/pc_flop.cpp @@ -17,7 +17,7 @@ #define FAT_SECLEN 512 -static imgtoolerr_t fat_image_create(imgtool::image *image, imgtool::stream &stream, util::option_resolution *opts) +static imgtoolerr_t fat_image_create(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *opts) { imgtoolerr_t err; UINT32 tracks, heads, sectors; diff --git a/src/tools/imgtool/modules/pc_hard.cpp b/src/tools/imgtool/modules/pc_hard.cpp index d195f8a7dcc..13287b204e2 100644 --- a/src/tools/imgtool/modules/pc_hard.cpp +++ b/src/tools/imgtool/modules/pc_hard.cpp @@ -232,7 +232,7 @@ static imgtoolerr_t pc_chd_read_partition_header(imgtool::image &image) -static imgtoolerr_t pc_chd_image_create(imgtool::image *image, imgtool::stream &f, util::option_resolution *opts) +static imgtoolerr_t pc_chd_image_create(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *opts) { imgtoolerr_t err; UINT32 cylinders, heads, sectors; @@ -246,11 +246,11 @@ static imgtoolerr_t pc_chd_image_create(imgtool::image *image, imgtool::stream & info = pc_chd_get_image_info(*image); /* create the hard disk image */ - err = imghd_create(f, 0, cylinders, heads, sectors, FAT_SECLEN); + err = imghd_create(*stream, 0, cylinders, heads, sectors, FAT_SECLEN); if (err) goto done; - err = imghd_open(f, &info->hard_disk); + err = imghd_open(*stream, &info->hard_disk); if (err) goto done; @@ -278,7 +278,7 @@ done: -static imgtoolerr_t pc_chd_image_open(imgtool::image *image, imgtool::stream &stream) +static imgtoolerr_t pc_chd_image_open(imgtool::image *image, imgtool::stream::ptr &&stream) { imgtoolerr_t err; pc_chd_image_info *info; @@ -286,7 +286,7 @@ static imgtoolerr_t pc_chd_image_open(imgtool::image *image, imgtool::stream &st info = pc_chd_get_image_info(*image); /* open the hard drive */ - err = imghd_open(stream, &info->hard_disk); + err = imghd_open(*stream, &info->hard_disk); if (err) return err; diff --git a/src/tools/imgtool/modules/prodos.cpp b/src/tools/imgtool/modules/prodos.cpp index e52986ee473..584c5623d2f 100644 --- a/src/tools/imgtool/modules/prodos.cpp +++ b/src/tools/imgtool/modules/prodos.cpp @@ -502,7 +502,7 @@ static imgtoolerr_t prodos_diskimage_open(imgtool::image *image) -static imgtoolerr_t prodos_diskimage_open_525(imgtool::image *image, imgtool::stream &stream) +static imgtoolerr_t prodos_diskimage_open_525(imgtool::image *image, imgtool::stream::ptr &&dummy) { prodos_setprocs_525(image); return prodos_diskimage_open(image); @@ -510,7 +510,7 @@ static imgtoolerr_t prodos_diskimage_open_525(imgtool::image *image, imgtool::st -static imgtoolerr_t prodos_diskimage_open_35(imgtool::image *image, imgtool::stream &stream) +static imgtoolerr_t prodos_diskimage_open_35(imgtool::image *image, imgtool::stream::ptr &&dummy) { prodos_setprocs_35(image); return prodos_diskimage_open(image); @@ -702,7 +702,7 @@ static imgtoolerr_t prodos_diskimage_create(imgtool::image *image, util::option_ -static imgtoolerr_t prodos_diskimage_create_525(imgtool::image *image, imgtool::stream &stream, util::option_resolution *opts) +static imgtoolerr_t prodos_diskimage_create_525(imgtool::image *image, imgtool::stream::ptr &&dummy, util::option_resolution *opts) { prodos_setprocs_525(image); return prodos_diskimage_create(image, opts); @@ -710,7 +710,7 @@ static imgtoolerr_t prodos_diskimage_create_525(imgtool::image *image, imgtool:: -static imgtoolerr_t prodos_diskimage_create_35(imgtool::image *image, imgtool::stream &stream, util::option_resolution *opts) +static imgtoolerr_t prodos_diskimage_create_35(imgtool::image *image, imgtool::stream::ptr &&dummy, util::option_resolution *opts) { prodos_setprocs_35(image); return prodos_diskimage_create(image, opts); diff --git a/src/tools/imgtool/modules/psion.cpp b/src/tools/imgtool/modules/psion.cpp index 524c4c550ab..81ad35653bd 100644 --- a/src/tools/imgtool/modules/psion.cpp +++ b/src/tools/imgtool/modules/psion.cpp @@ -385,25 +385,30 @@ UINT16 get_ob3(imgtool::stream &instream, imgtool::stream &outstream, UINT8 type return size; } -static imgtoolerr_t datapack_open(imgtool::image *image, imgtool::stream &stream) +static imgtoolerr_t datapack_open(imgtool::image *image, imgtool::stream::ptr &&stream) { psion_pack *pack = (psion_pack*)image->extra_bytes(); char opk_magic[4]; - stream.read(opk_magic, 4); + stream->read(opk_magic, 4); if(strcmp(opk_magic, "OPK\0")) return IMGTOOLERR_UNEXPECTED; - pack->stream = &stream; + pack->stream = stream.get(); if (update_pack_index(pack)) + { + pack->stream = stream.release(); return IMGTOOLERR_SUCCESS; + } else + { return IMGTOOLERR_CORRUPTIMAGE; + } } -static imgtoolerr_t datapack_create(imgtool::image *image, imgtool::stream &stream, util::option_resolution *opts) +static imgtoolerr_t datapack_create(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *opts) { psion_pack *pack = (psion_pack*)image->extra_bytes(); static const UINT8 opk_magic[4] = {'O', 'P', 'K', 0x00}; @@ -419,25 +424,30 @@ static imgtoolerr_t datapack_create(imgtool::image *image, imgtool::stream &stre checksum = head_checksum(pack_head); - stream.write(opk_magic, 4); - stream.fill(0x00, 2); - stream.write(pack_head, 8); + stream->write(opk_magic, 4); + stream->fill(0x00, 2); + stream->write(pack_head, 8); - stream.putc((checksum>>8) & 0xff); - stream.putc(checksum & 0xff); + stream->putc((checksum>>8) & 0xff); + stream->putc(checksum & 0xff); - put_name_record(stream, "MAIN", 0x81, 0x90); + put_name_record(*stream, "MAIN", 0x81, 0x90); - stream.fill(0xff, 2); + stream->fill(0xff, 2); - update_opk_head(stream); + update_opk_head(*stream); - pack->stream = &stream; + pack->stream = stream.get(); if (update_pack_index(pack)) + { + pack->stream = stream.release(); return IMGTOOLERR_SUCCESS; + } else + { return IMGTOOLERR_CORRUPTIMAGE; + } } static void datapack_close( imgtool::image *image) diff --git a/src/tools/imgtool/modules/thomson.cpp b/src/tools/imgtool/modules/thomson.cpp index 1acc7592a3e..343f128c2bf 100644 --- a/src/tools/imgtool/modules/thomson.cpp +++ b/src/tools/imgtool/modules/thomson.cpp @@ -177,71 +177,72 @@ static UINT8* thom_get_sector(thom_floppy* f, unsigned head, (.fd have 40 or 80 tracks, .qd have 25 tracks) and the file size. */ -static imgtoolerr_t thom_open_fd_qd(imgtool::image *img, imgtool::stream &stream) +static imgtoolerr_t thom_open_fd_qd(imgtool::image *img, imgtool::stream::ptr &&stream) { thom_floppy* f = (thom_floppy*) img->extra_bytes(); - int size = stream.size(); + int size = stream->size(); - f->stream = &stream; + f->stream = stream.get(); f->modified = 0; /* guess format */ switch ( size ) { case 81920: - f->tracks = 40; - f->sector_size = 128; - f->sectuse_size = 128; - f->heads = 1; - break; + f->tracks = 40; + f->sector_size = 128; + f->sectuse_size = 128; + f->heads = 1; + break; case 163840: - f->tracks = 40; - f->sector_size = 256; - f->sectuse_size = 255; - f->heads = 1; - /* could also be: sector_size=128, heads=2 */ - /* maight even be: tracks=80, sector_size=128 */ - break; + f->tracks = 40; + f->sector_size = 256; + f->sectuse_size = 255; + f->heads = 1; + /* could also be: sector_size=128, heads=2 */ + /* maight even be: tracks=80, sector_size=128 */ + break; case 327680: - f->tracks = 80; - f->sector_size = 256; - f->sectuse_size = 255; - f->heads = 1; - /* could also be: tracks=40, heads=2 */ - break; + f->tracks = 80; + f->sector_size = 256; + f->sectuse_size = 255; + f->heads = 1; + /* could also be: tracks=40, heads=2 */ + break; case 655360: - f->tracks = 80; - f->sector_size = 256; - f->sectuse_size = 255; - f->heads = 2; - break; + f->tracks = 80; + f->sector_size = 256; + f->sectuse_size = 255; + f->heads = 2; + break; case 51200: - f->tracks = 25; - f->sector_size = 128; - f->sectuse_size = 128; - f->heads = 1; - break; + f->tracks = 25; + f->sector_size = 128; + f->sectuse_size = 128; + f->heads = 1; + break; case 62400: - f->tracks = 25; - f->sector_size = 128; - f->sectuse_size = 128; - f->heads = 2; - break; + f->tracks = 25; + f->sector_size = 128; + f->sectuse_size = 128; + f->heads = 2; + break; default: - return IMGTOOLERR_CORRUPTIMAGE; + return IMGTOOLERR_CORRUPTIMAGE; } assert( size == f->heads * f->tracks * 16 * f->sector_size ); - stream.seek(0, SEEK_SET); - if ( stream.read(f->data, size ) < size ) - return IMGTOOLERR_READERROR; + f->stream->seek(0, SEEK_SET); + if (f->stream->read(f->data, size ) < size) + return IMGTOOLERR_READERROR; + f->stream = stream.release(); return IMGTOOLERR_SUCCESS; } @@ -308,47 +309,49 @@ static UINT16 thom_sap_crc( UINT8* data, int size ) return crc; } -static imgtoolerr_t thom_open_sap(imgtool::image *img, imgtool::stream &stream) +static imgtoolerr_t thom_open_sap(imgtool::image *img, imgtool::stream::ptr &&stream) { thom_floppy* f = (thom_floppy*) img->extra_bytes(); UINT8 buf[262]; - f->stream = &stream; + f->stream = stream.get(); f->modified = 0; - /* check image header */ - stream.seek(0, SEEK_SET); - stream.read(buf, 66 ); + // check image header + f->stream->seek(0, SEEK_SET); + f->stream->read(buf, 66 ); if ( memcmp( buf+1, sap_header+1, 65 ) ) return IMGTOOLERR_CORRUPTIMAGE; /* guess format */ - stream.read(buf, 1 ); - switch ( buf[0] ) { + f->stream->read(buf, 1 ); + switch ( buf[0] ) + { case 1: case 3: - f->heads = 1; - f->tracks = 40; - f->sector_size = 128; - f->sectuse_size = 128; - break; + f->heads = 1; + f->tracks = 40; + f->sector_size = 128; + f->sectuse_size = 128; + break; case 0: case 2: case 4: - f->heads = 1; - f->tracks = 80; - f->sector_size = 256; - f->sectuse_size = 255; - break; - default: return IMGTOOLERR_CORRUPTIMAGE; + f->heads = 1; + f->tracks = 80; + f->sector_size = 256; + f->sectuse_size = 255; + break; + default: + return IMGTOOLERR_CORRUPTIMAGE; } - stream.seek(66, SEEK_SET); + f->stream->seek(66, SEEK_SET); while ( 1) { int i, sector, track; UINT16 crc; /* load sector */ - if ( stream.read(buf, 6 + f->sector_size ) < 6 + f->sector_size ) + if (f->stream->read(buf, 6 + f->sector_size ) < 6 + f->sector_size ) break; /* parse sector header */ @@ -368,6 +371,7 @@ static imgtoolerr_t thom_open_sap(imgtool::image *img, imgtool::stream &stream) return IMGTOOLERR_CORRUPTIMAGE; } + f->stream = stream.release(); return IMGTOOLERR_SUCCESS; } @@ -1113,7 +1117,7 @@ static imgtoolerr_t thom_suggest_transfer(imgtool::partition *part, } static imgtoolerr_t thom_create(imgtool::image* img, - imgtool::stream &stream, + imgtool::stream::ptr &&stream, util::option_resolution *opts) { thom_floppy* f = (thom_floppy*) img->extra_bytes(); @@ -1121,7 +1125,7 @@ static imgtoolerr_t thom_create(imgtool::image* img, UINT8* buf; const char* name; - f->stream = &stream; + f->stream = stream.get(); f->modified = 0; /* get parameters */ @@ -1167,6 +1171,7 @@ static imgtoolerr_t thom_create(imgtool::image* img, f->modified = 1; + f->stream = stream.release(); return IMGTOOLERR_SUCCESS; } diff --git a/src/tools/imgtool/modules/ti99.cpp b/src/tools/imgtool/modules/ti99.cpp index 1682712ec15..bb3a17356fc 100644 --- a/src/tools/imgtool/modules/ti99.cpp +++ b/src/tools/imgtool/modules/ti99.cpp @@ -966,21 +966,19 @@ static int read_image_vib_no_geometry(imgtool::stream &file_handle, ti99_img_for Return imgtool error code */ -static imgtoolerr_t open_image_lvl1(imgtool::stream &file_handle, ti99_img_format img_format, ti99_lvl1_imgref *l1_img, dsk_vib *vib) +static imgtoolerr_t open_image_lvl1(imgtool::stream::ptr &&file_handle, ti99_img_format img_format, ti99_lvl1_imgref *l1_img, dsk_vib *vib) { imgtoolerr_t err; int reply; UINT16 totphysrecs; - l1_img->img_format = img_format; - l1_img->file_handle = &file_handle; if (img_format == if_harddisk) { const hard_disk_info *info; - err = imghd_open(file_handle, &l1_img->harddisk_handle); + err = imghd_open(*file_handle, &l1_img->harddisk_handle); if (err) return err; @@ -1004,7 +1002,7 @@ static imgtoolerr_t open_image_lvl1(imgtool::stream &file_handle, ti99_img_forma else { /* read vib */ - reply = read_image_vib_no_geometry(file_handle, img_format, vib); + reply = read_image_vib_no_geometry(*file_handle, img_format, vib); if (reply) return (imgtoolerr_t)reply; @@ -1032,7 +1030,7 @@ static imgtoolerr_t open_image_lvl1(imgtool::stream &file_handle, ti99_img_forma || (totphysrecs < 2) || memcmp(vib->id, "DSK", 3) || (! strchr(" P", vib->protection)) || (((img_format == if_mess) || (img_format == if_v9t9)) - && (file_handle.size() != totphysrecs*256U))) + && (file_handle->size() != totphysrecs*256U))) return (imgtoolerr_t)IMGTOOLERR_CORRUPTIMAGE; if ((img_format == if_pc99_fm) || (img_format == if_pc99_mfm)) @@ -1040,7 +1038,7 @@ static imgtoolerr_t open_image_lvl1(imgtool::stream &file_handle, ti99_img_forma l1_img->pc99_data_offset_array = (UINT32*)malloc(sizeof(*l1_img->pc99_data_offset_array)*totphysrecs); if (! l1_img->pc99_data_offset_array) return IMGTOOLERR_OUTOFMEMORY; - reply = parse_pc99_image(file_handle, img_format == if_pc99_fm, 1, NULL, & l1_img->geometry, l1_img->pc99_data_offset_array, &l1_img->pc99_track_len); + reply = parse_pc99_image(*file_handle, img_format == if_pc99_fm, 1, NULL, & l1_img->geometry, l1_img->pc99_data_offset_array, &l1_img->pc99_track_len); if (reply) { free(l1_img->pc99_data_offset_array); @@ -1049,6 +1047,8 @@ static imgtoolerr_t open_image_lvl1(imgtool::stream &file_handle, ti99_img_forma } } + l1_img->file_handle = file_handle.release(); // we can only do this when we're sure we're successful + return (imgtoolerr_t)0; } @@ -3848,11 +3848,11 @@ struct win_iterator }; -static imgtoolerr_t dsk_image_init_mess(imgtool::image *image, imgtool::stream &f); -static imgtoolerr_t dsk_image_init_v9t9(imgtool::image *image, imgtool::stream &f); -static imgtoolerr_t dsk_image_init_pc99_fm(imgtool::image *image, imgtool::stream &f); -static imgtoolerr_t dsk_image_init_pc99_mfm(imgtool::image *image, imgtool::stream &f); -static imgtoolerr_t win_image_init(imgtool::image *image, imgtool::stream &f); +static imgtoolerr_t dsk_image_init_mess(imgtool::image *image, imgtool::stream::ptr &&stream); +static imgtoolerr_t dsk_image_init_v9t9(imgtool::image *image, imgtool::stream::ptr &&stream); +static imgtoolerr_t dsk_image_init_pc99_fm(imgtool::image *image, imgtool::stream::ptr &&stream); +static imgtoolerr_t dsk_image_init_pc99_mfm(imgtool::image *image, imgtool::stream::ptr &&stream); +static imgtoolerr_t win_image_init(imgtool::image *image, imgtool::stream::ptr &&stream); static void ti99_image_exit(imgtool::image *img); static void ti99_image_info(imgtool::image *img, char *string, size_t len); static imgtoolerr_t dsk_image_beginenum(imgtool::directory *enumeration, const char *path); @@ -3864,8 +3864,8 @@ static imgtoolerr_t ti99_image_readfile(imgtool::partition *partition, const cha static imgtoolerr_t ti99_image_writefile(imgtool::partition *partition, const char *fpath, const char *fork, imgtool::stream &sourcef, util::option_resolution *writeoptions); static imgtoolerr_t dsk_image_deletefile(imgtool::partition *partition, const char *fpath); static imgtoolerr_t win_image_deletefile(imgtool::partition *partition, const char *fpath); -static imgtoolerr_t dsk_image_create_mess(imgtool::image *image, imgtool::stream &f, util::option_resolution *createoptions); -static imgtoolerr_t dsk_image_create_v9t9(imgtool::image *image, imgtool::stream &f, util::option_resolution *createoptions); +static imgtoolerr_t dsk_image_create_mess(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *createoptions); +static imgtoolerr_t dsk_image_create_v9t9(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *createoptions); enum { @@ -3995,17 +3995,17 @@ void ti99_ti99hd_get_info(const imgtool_class *imgclass, UINT32 state, union img /* Open a file as a ti99_image (common code). */ -static int dsk_image_init(imgtool::image *img, imgtool::stream &f, ti99_img_format img_format) +static imgtoolerr_t dsk_image_init(imgtool::image *img, imgtool::stream::ptr &&stream, ti99_img_format img_format) { struct ti99_lvl2_imgref *image = (struct ti99_lvl2_imgref *) img->extra_bytes(); dsk_vib vib; - int reply; + imgtoolerr_t reply; int totphysrecs; unsigned fdir_aphysrec; int i; /* open disk image at level 1 */ - reply = open_image_lvl1(f, img_format, &image->l1_img, &vib); + reply = open_image_lvl1(std::move(stream), img_format, &image->l1_img, &vib); if (reply) return reply; @@ -4029,7 +4029,7 @@ static int dsk_image_init(imgtool::image *img, imgtool::stream &f, ti99_img_form image->dsk.totphysrecs = get_UINT16BE(vib.totphysrecs); /* read and check main volume catalog */ - reply = dsk_read_catalog(image, 1, &image->dsk.catalogs[0]); + reply = (imgtoolerr_t)dsk_read_catalog(image, 1, &image->dsk.catalogs[0]); if (reply) return reply; @@ -4072,7 +4072,7 @@ static int dsk_image_init(imgtool::image *img, imgtool::stream &f, ti99_img_form image->dsk.fdir_aphysrec[image->dsk.catalogs[0].num_subdirs+1] = fdir_aphysrec; /*image->dsk.catalogs[0].subdirs[image->dsk.catalogs[0].num_subdirs].dir_ptr = fdir_aphysrec;*/ memcpy(image->dsk.catalogs[0].subdirs[image->dsk.catalogs[0].num_subdirs].name, vib.subdir[i].name, 10); - reply = dsk_read_catalog(image, fdir_aphysrec, &image->dsk.catalogs[image->dsk.catalogs[0].num_subdirs+1]); + reply = (imgtoolerr_t) dsk_read_catalog(image, fdir_aphysrec, &image->dsk.catalogs[image->dsk.catalogs[0].num_subdirs+1]); if (reply) { /* error: invalid fdir */ @@ -4090,45 +4090,45 @@ static int dsk_image_init(imgtool::image *img, imgtool::stream &f, ti99_img_form /* initialize default data_offset */ image->data_offset = 32+2; - return 0; + return (imgtoolerr_t)0; } /* Open a file as a ti99_image (MESS format). */ -static imgtoolerr_t dsk_image_init_mess(imgtool::image *image, imgtool::stream &f) +static imgtoolerr_t dsk_image_init_mess(imgtool::image *image, imgtool::stream::ptr &&stream) { - return (imgtoolerr_t)dsk_image_init(image, f, if_mess); + return dsk_image_init(image, std::move(stream), if_mess); } /* Open a file as a ti99_image (V9T9 format). */ -static imgtoolerr_t dsk_image_init_v9t9(imgtool::image *image, imgtool::stream &f) +static imgtoolerr_t dsk_image_init_v9t9(imgtool::image *image, imgtool::stream::ptr &&stream) { - return (imgtoolerr_t)dsk_image_init(image, f, if_v9t9); + return dsk_image_init(image, std::move(stream), if_v9t9); } /* Open a file as a ti99_image (PC99 FM format). */ -static imgtoolerr_t dsk_image_init_pc99_fm(imgtool::image *image, imgtool::stream &f) +static imgtoolerr_t dsk_image_init_pc99_fm(imgtool::image *image, imgtool::stream::ptr &&stream) { - return (imgtoolerr_t)dsk_image_init(image, f, if_pc99_fm); + return dsk_image_init(image, std::move(stream), if_pc99_fm); } /* Open a file as a ti99_image (PC99 MFM format). */ -static imgtoolerr_t dsk_image_init_pc99_mfm(imgtool::image *image, imgtool::stream &f) +static imgtoolerr_t dsk_image_init_pc99_mfm(imgtool::image *image, imgtool::stream::ptr &&stream) { - return (imgtoolerr_t)dsk_image_init(image, f, if_pc99_mfm); + return dsk_image_init(image, std::move(stream), if_pc99_mfm); } /* Open a file as a ti99_image (harddisk format). */ -static imgtoolerr_t win_image_init(imgtool::image *img, imgtool::stream &f) +static imgtoolerr_t win_image_init(imgtool::image *img, imgtool::stream::ptr &&stream) { struct ti99_lvl2_imgref *image = (struct ti99_lvl2_imgref *) img->extra_bytes(); win_vib_ddr vib; @@ -4136,7 +4136,7 @@ static imgtoolerr_t win_image_init(imgtool::image *img, imgtool::stream &f) int i; /* open disk image at level 1 */ - reply = open_image_lvl1(f, if_harddisk, & image->l1_img, NULL); + reply = open_image_lvl1(std::move(stream), if_harddisk, & image->l1_img, NULL); if (reply) return (imgtoolerr_t)reply; @@ -5226,7 +5226,7 @@ static imgtoolerr_t win_image_deletefile(imgtool::partition *partition, const ch Supports MESS and V9T9 formats only */ -static imgtoolerr_t dsk_image_create(imgtool::image *image, imgtool::stream &f, util::option_resolution *createoptions, ti99_img_format img_format) +static imgtoolerr_t dsk_image_create(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *createoptions, ti99_img_format img_format) { const char *volname; int density; @@ -5241,7 +5241,7 @@ static imgtoolerr_t dsk_image_create(imgtool::image *image, imgtool::stream &f, int i; l1_img.img_format = img_format; - l1_img.file_handle = &f; + l1_img.file_handle = stream.get(); // can't release here /* read options */ volname = createoptions->lookup_string(dsk_createopts_volname).c_str(); @@ -5328,7 +5328,7 @@ static imgtoolerr_t dsk_image_create(imgtool::image *image, imgtool::stream &f, vib.abm[0] |= (physrecsperAU == 1) ? 3 : 1; /* write aphysrec 0 */ - if (write_absolute_physrec(& l1_img, 0, &vib)) + if (write_absolute_physrec(&l1_img, 0, &vib)) return IMGTOOLERR_WRITEERROR; @@ -5340,21 +5340,21 @@ static imgtoolerr_t dsk_image_create(imgtool::image *image, imgtool::stream &f, return IMGTOOLERR_WRITEERROR; - return (imgtoolerr_t)dsk_image_init(image, f, img_format); + return dsk_image_init(image, std::move(stream), img_format); } /* Create a blank ti99_image (MESS format). */ -static imgtoolerr_t dsk_image_create_mess(imgtool::image *image, imgtool::stream &f, util::option_resolution *createoptions) +static imgtoolerr_t dsk_image_create_mess(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *createoptions) { - return dsk_image_create(image, f, createoptions, if_mess); + return dsk_image_create(image, std::move(stream), createoptions, if_mess); } /* Create a blank ti99_image (V9T9 format). */ -static imgtoolerr_t dsk_image_create_v9t9(imgtool::image *image, imgtool::stream &f, util::option_resolution *createoptions) +static imgtoolerr_t dsk_image_create_v9t9(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *createoptions) { - return dsk_image_create(image, f, createoptions, if_v9t9); + return dsk_image_create(image, std::move(stream), createoptions, if_v9t9); } diff --git a/src/tools/imgtool/modules/ti990hd.cpp b/src/tools/imgtool/modules/ti990hd.cpp index d711a1b7eee..fc768e268e4 100644 --- a/src/tools/imgtool/modules/ti990hd.cpp +++ b/src/tools/imgtool/modules/ti990hd.cpp @@ -386,7 +386,7 @@ struct ti990_iterator }; -static imgtoolerr_t ti990_image_init(imgtool::image *img, imgtool::stream &f); +static imgtoolerr_t ti990_image_init(imgtool::image *img, imgtool::stream::ptr &&stream); static void ti990_image_exit(imgtool::image *img); static void ti990_image_info(imgtool::image *img, char *string, size_t len); static imgtoolerr_t ti990_image_beginenum(imgtool::directory *enumeration, const char *path); @@ -398,7 +398,7 @@ static imgtoolerr_t ti990_image_readfile(imgtool::partition *partition, const ch static imgtoolerr_t ti990_image_writefile(imgtool::partition *partition, const char *fpath, imgtool::stream *sourcef, util::option_resolution *writeoptions); static imgtoolerr_t ti990_image_deletefile(imgtool::partition *partition, const char *fpath); #endif -static imgtoolerr_t ti990_image_create(imgtool::image *image, imgtool::stream &f, util::option_resolution *createoptions); +static imgtoolerr_t ti990_image_create(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *createoptions); enum { @@ -1106,15 +1106,15 @@ static int qsort_catalog_compare(const void *p1, const void *p2) /* Open a file as a ti990_image. */ -static imgtoolerr_t ti990_image_init(imgtool::image *img, imgtool::stream &f) +static imgtoolerr_t ti990_image_init(imgtool::image *img, imgtool::stream::ptr &&stream) { ti990_image *image = (ti990_image *) img->extra_bytes(); disk_image_header header; int reply; unsigned totsecs; - image->file_handle = &f; - reply = f.read(&header, sizeof(header)); + image->file_handle = stream.get(); + reply = image->file_handle->read(&header, sizeof(header)); if (reply != sizeof(header)) return IMGTOOLERR_READERROR; @@ -1131,14 +1131,14 @@ static imgtoolerr_t ti990_image_init(imgtool::image *img, imgtool::stream &f) || (image->geometry.heads > MAX_HEADS) || (image->geometry.cylinders > MAX_CYLINDERS) || (totsecs < 1) - || (f.size() != header_len + totsecs*image->geometry.bytes_per_sector)) + || (image->file_handle->size() != header_len + totsecs*image->geometry.bytes_per_sector)) { return IMGTOOLERR_CORRUPTIMAGE; } { ti990_phys_sec_address address = { 0, 0, 0 }; - reply = read_sector_physical_len(f, &address, &image->geometry, & image->sec0, sizeof(image->sec0)); + reply = read_sector_physical_len(*image->file_handle, &address, &image->geometry, & image->sec0, sizeof(image->sec0)); } if (reply) { @@ -1156,6 +1156,7 @@ static imgtoolerr_t ti990_image_init(imgtool::image *img, imgtool::stream &f) return IMGTOOLERR_CORRUPTIMAGE; } + image->file_handle = stream.release(); return IMGTOOLERR_SUCCESS; } @@ -1764,7 +1765,7 @@ static imgtoolerr_t ti990_image_deletefile(imgtool::partition *partition, const /* Create a blank ti990_image. */ -static imgtoolerr_t ti990_image_create(imgtool::image *image, imgtool::stream &f, util::option_resolution *createoptions) +static imgtoolerr_t ti990_image_create(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *createoptions) { //const char *volname; ti990_geometry geometry; @@ -1790,7 +1791,7 @@ static imgtoolerr_t ti990_image_create(imgtool::image *image, imgtool::stream &f set_UINT32BE(& header.sectors_per_track, geometry.sectors_per_track); set_UINT32BE(& header.bytes_per_sector, geometry.bytes_per_sector); - reply = f.write(&header, sizeof(header)); + reply = stream->write(&header, sizeof(header)); if (reply != sizeof(header)) { return IMGTOOLERR_WRITEERROR; @@ -1803,7 +1804,7 @@ static imgtoolerr_t ti990_image_create(imgtool::image *image, imgtool::stream &f /* write sector 0 */ - if (write_sector_logical(f, 0, & geometry, &sec0)) + if (write_sector_logical(*stream, 0, & geometry, &sec0)) return IMGTOOLERR_WRITEERROR; @@ -1811,7 +1812,7 @@ static imgtoolerr_t ti990_image_create(imgtool::image *image, imgtool::stream &f memset(empty_sec, 0, geometry.bytes_per_sector); for (i=1; i<totsecs; i++) - if (write_sector_logical(f, i, & geometry, empty_sec)) + if (write_sector_logical(*stream, i, & geometry, empty_sec)) return IMGTOOLERR_WRITEERROR; return (imgtoolerr_t)0; diff --git a/src/tools/imgtool/modules/vzdos.cpp b/src/tools/imgtool/modules/vzdos.cpp index ccd4248370f..612c5ebe8fc 100644 --- a/src/tools/imgtool/modules/vzdos.cpp +++ b/src/tools/imgtool/modules/vzdos.cpp @@ -789,7 +789,7 @@ static imgtoolerr_t vzdos_diskimage_suggesttransfer(imgtool::partition *partitio return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t vzdos_diskimage_create(imgtool::image *img, imgtool::stream &stream, util::option_resolution *opts) +static imgtoolerr_t vzdos_diskimage_create(imgtool::image *img, imgtool::stream::ptr &&dummy, util::option_resolution *opts) { imgtoolerr_t ret; int track, sector; |