Skip to content

Commit

Permalink
cpu/apexc: Replace single-location tape I/O space with callbacks (nw)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajrhacker committed Jan 14, 2018
1 parent 3f90200 commit 183b56a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
14 changes: 8 additions & 6 deletions src/devices/cpu/apexc/apexc.cpp
Expand Up @@ -341,7 +341,8 @@ DEFINE_DEVICE_TYPE(APEXC, apexc_cpu_device, "apexc_cpu", "APEXC")
apexc_cpu_device::apexc_cpu_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: cpu_device(mconfig, APEXC, tag, owner, clock)
, m_program_config("program", ENDIANNESS_BIG, 32, 15, 0)
, m_io_config("io", ENDIANNESS_BIG, 8, 1, 0)
, m_tape_read_cb(*this)
, m_tape_punch_cb(*this)
, m_a(0)
, m_r(0)
, m_cr(0)
Expand All @@ -355,8 +356,7 @@ apexc_cpu_device::apexc_cpu_device(const machine_config &mconfig, const char *ta
device_memory_interface::space_config_vector apexc_cpu_device::memory_space_config() const
{
return space_config_vector {
std::make_pair(AS_PROGRAM, &m_program_config),
std::make_pair(AS_IO, &m_io_config)
std::make_pair(AS_PROGRAM, &m_program_config)
};
}

Expand Down Expand Up @@ -440,12 +440,12 @@ void apexc_cpu_device::word_write(uint32_t address, uint32_t data, uint32_t mask

uint8_t apexc_cpu_device::papertape_read()
{
return m_io->read_byte(0) & 0x1f;
return m_tape_read_cb() & 0x1f;
}

void apexc_cpu_device::papertape_punch(uint8_t data)
{
m_io->write_byte(0, data);
m_tape_punch_cb(data);
}

/*
Expand Down Expand Up @@ -764,8 +764,10 @@ void apexc_cpu_device::execute()

void apexc_cpu_device::device_start()
{
m_tape_read_cb.resolve_safe(0);
m_tape_punch_cb.resolve_safe();

m_program = &space(AS_PROGRAM);
m_io = &space(AS_IO);

save_item(NAME(m_a));
save_item(NAME(m_r));
Expand Down
23 changes: 21 additions & 2 deletions src/devices/cpu/apexc/apexc.h
Expand Up @@ -6,6 +6,12 @@

#pragma once

#define MCFG_APEXC_TAPE_READ_CB(_devcb) \
devcb = &apexc_cpu_device::set_tape_read_cb(*device, DEVCB_##_devcb);

#define MCFG_APEXC_TAPE_PUNCH_CB(_devcb) \
devcb = &apexc_cpu_device::set_tape_punch_cb(*device, DEVCB_##_devcb);

enum
{
APEXC_CR =1, /* control register */
Expand All @@ -22,6 +28,18 @@ class apexc_cpu_device : public cpu_device
// construction/destruction
apexc_cpu_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);

// static configuration
template<class Object>
static devcb_base &set_tape_read_cb(device_t &device, Object &&object)
{
return downcast<apexc_cpu_device &>(device).m_tape_read_cb.set_callback(std::forward<Object>(object));
}
template<class Object>
static devcb_base &set_tape_punch_cb(device_t &device, Object &&object)
{
return downcast<apexc_cpu_device &>(device).m_tape_punch_cb.set_callback(std::forward<Object>(object));
}

protected:
// device-level overrides
virtual void device_start() override;
Expand Down Expand Up @@ -56,7 +74,9 @@ class apexc_cpu_device : public cpu_device
void execute();

address_space_config m_program_config;
address_space_config m_io_config;

devcb_read8 m_tape_read_cb;
devcb_write8 m_tape_punch_cb;

uint32_t m_a; /* accumulator */
uint32_t m_r; /* register */
Expand All @@ -70,7 +90,6 @@ class apexc_cpu_device : public cpu_device
uint32_t m_pc; /* address of next instruction for the disassembler */

address_space *m_program;
address_space *m_io;
int m_icount;

// For state
Expand Down
8 changes: 2 additions & 6 deletions src/mame/drivers/apexc.cpp
Expand Up @@ -852,19 +852,15 @@ static ADDRESS_MAP_START(apexc_mem_map, AS_PROGRAM, 32, apexc_state )
#endif
ADDRESS_MAP_END

static ADDRESS_MAP_START(apexc_io_map, AS_IO, 8, apexc_state )
AM_RANGE(0x00, 0x00) AM_READ(tape_read)
AM_RANGE(0x00, 0x00) AM_WRITE(tape_write)
ADDRESS_MAP_END


static MACHINE_CONFIG_START( apexc )

/* basic machine hardware */
/* APEXC CPU @ 2.0 kHz (memory word clock frequency) */
MCFG_CPU_ADD("maincpu", APEXC, 2000)
MCFG_CPU_PROGRAM_MAP(apexc_mem_map)
MCFG_CPU_IO_MAP(apexc_io_map)
MCFG_APEXC_TAPE_READ_CB(READ8(apexc_state, tape_read))
MCFG_APEXC_TAPE_PUNCH_CB(WRITE8(apexc_state, tape_write))
/* dummy interrupt: handles the control panel */
MCFG_CPU_VBLANK_INT_DRIVER("screen", apexc_state, apexc_interrupt)

Expand Down

0 comments on commit 183b56a

Please sign in to comment.