Amiga: Make Akiko independent from driver state

This commit is contained in:
Dirk Best 2017-02-10 02:40:08 +01:00
parent b06c8c8d15
commit a126b26264
5 changed files with 87 additions and 53 deletions

View File

@ -14,7 +14,6 @@
***************************************************************************/
#include "akiko.h"
#include "includes/amiga.h"
#include "imagedev/chd_cd.h"
#include "coreutil.h"
@ -81,9 +80,8 @@ akiko_device::akiko_device(const machine_config &mconfig, const char *tag, devic
m_dma_timer(nullptr),
m_frame_timer(nullptr),
m_cdrom_is_device(0),
m_scl_w(*this),
m_sda_r(*this),
m_sda_w(*this)
m_mem_r(*this), m_mem_w(*this), m_int_w(*this),
m_scl_w(*this), m_sda_r(*this), m_sda_w(*this)
{
for (int i = 0; i < 8; i++)
{
@ -98,18 +96,6 @@ akiko_device::akiko_device(const machine_config &mconfig, const char *tag, devic
}
}
//-------------------------------------------------
// set_cputag - set cpu tag for cpu we working on
//-------------------------------------------------
void akiko_device::set_cputag(device_t &device, const char *tag)
{
akiko_device &akiko = downcast<akiko_device &>(device);
akiko.m_cputag = tag;
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
@ -117,6 +103,9 @@ void akiko_device::set_cputag(device_t &device, const char *tag)
void akiko_device::device_start()
{
// resolve callbacks
m_mem_r.resolve_safe(0xffff);
m_mem_w.resolve_safe();
m_int_w.resolve_safe();
m_scl_w.resolve_safe();
m_sda_r.resolve_safe(1);
m_sda_w.resolve_safe();
@ -144,9 +133,6 @@ void akiko_device::device_start()
m_cdrom_cmd_end = 0;
m_cdrom_cmd_resp = 0;
device_t *cpu = machine().device(m_cputag);
m_space = &cpu->memory().space(AS_PROGRAM);
m_cdrom_toc = nullptr;
m_dma_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(akiko_device::dma_proc), this));
m_frame_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(akiko_device::frame_proc), this));
@ -270,6 +256,19 @@ uint32_t akiko_device::nvram_read()
return v;
}
uint8_t akiko_device::mem_r8(offs_t offset)
{
int shift = (offset & 1) ? 0 : 8;
return m_mem_r(offset, 0xff << shift) >> shift;
}
void akiko_device::mem_w8(offs_t offset, uint8_t data)
{
int shift = (offset & 1) ? 0 : 8;
m_mem_w(offset, data << shift, 0xff << shift);
}
/*************************************
*
* Akiko Chunky to Planar converter
@ -413,8 +412,6 @@ uint8_t akiko_device::cdda_getstatus(uint32_t *lba)
void akiko_device::set_cd_status(uint32_t status)
{
amiga_state *amiga = machine().driver_data<amiga_state>();
m_cdrom_status[0] |= status;
if ( m_cdrom_status[0] & m_cdrom_status[1] )
@ -422,7 +419,7 @@ void akiko_device::set_cd_status(uint32_t status)
if (LOG_AKIKO_CD)
logerror("Akiko CD IRQ\n");
amiga->custom_chip_w(REG_INTREQ, INTENA_SETCLR | INTENA_PORTS);
m_int_w(1);
}
}
@ -469,11 +466,9 @@ TIMER_CALLBACK_MEMBER(akiko_device::dma_proc)
if ( m_cdrom_readreqmask & ( 1 << index ) )
{
amiga_state *amiga = machine().driver_data<amiga_state>();
uint32_t track = cdrom_get_track( m_cdrom, m_cdrom_lba_cur );
uint32_t datasize;// = cdrom_get_toc(m_cdrom)->tracks[track].datasize;
uint32_t subsize = cdrom_get_toc( m_cdrom )->tracks[track].subsize;
int i;
uint32_t curmsf = lba_to_msf( m_cdrom_lba_cur );
memset( buf, 0, 16 );
@ -504,16 +499,11 @@ TIMER_CALLBACK_MEMBER(akiko_device::dma_proc)
if (LOG_AKIKO_CD) logerror( "DMA: sector %d - address %08x\n", m_cdrom_lba_cur, m_cdrom_address[0] + (index*4096) );
for( i = 0; i < 2352; i += 2 )
{
uint16_t data;
printf( "DMA: sector %d - address %08x\n", m_cdrom_lba_cur, m_cdrom_address[0] + (index*4096) );
data = buf[i];
data <<= 8;
data |= buf[i+1];
amiga->chip_ram_w(m_cdrom_address[0] + (index*4096) + i, data );
}
// write sector data to host memory
for (int i = 0; i < 2352; i++)
mem_w8(m_cdrom_address[0] + (index*4096) + i, buf[i]);
m_cdrom_readmask |= ( 1 << index );
m_cdrom_readreqmask &= ~( 1 << index );
@ -561,7 +551,8 @@ void akiko_device::setup_response( int len, uint8_t *r1 )
for( i = 0; i < len; i++ )
{
m_space->write_byte( resp_addr + ((m_cdrom_cmd_resp + i) & 0xff), resp_buffer[i] );
offs_t addr = resp_addr + ((m_cdrom_cmd_resp + i) & 0xff);
mem_w8(addr, resp_buffer[i]);
}
m_cdrom_cmd_resp = (m_cdrom_cmd_resp+len) & 0xff;
@ -620,7 +611,7 @@ void akiko_device::update_cdrom()
while ( m_cdrom_cmd_start != m_cdrom_cmd_end )
{
uint32_t cmd_addr = m_cdrom_address[1] + 0x200 + m_cdrom_cmd_start;
int cmd = m_space->read_byte( cmd_addr );
uint8_t cmd = mem_r8(cmd_addr);
memset( resp, 0, sizeof( resp ) );
resp[0] = cmd;
@ -662,7 +653,7 @@ void akiko_device::update_cdrom()
for( i = 0; i < 13; i++ )
{
cmdbuf[i] = m_space->read_byte( cmd_addr );
cmdbuf[i] = mem_r8(cmd_addr);
cmd_addr &= 0xffffff00;
cmd_addr += ( m_cdrom_cmd_start + i + 1 ) & 0xff;
}
@ -795,7 +786,7 @@ READ32_MEMBER( akiko_device::read )
if ( LOG_AKIKO && offset < (0x30/4) )
{
logerror( "Reading AKIKO reg %0x [%s] at PC=%06x\n", offset, get_akiko_reg_name(offset), m_space->device().safe_pc() );
logerror( "Reading AKIKO reg %0x [%s] at %s\n", offset, get_akiko_reg_name(offset), machine().describe_context());
}
switch( offset )
@ -855,7 +846,7 @@ WRITE32_MEMBER( akiko_device::write )
{
if ( LOG_AKIKO && offset < (0x30/4) )
{
logerror( "Writing AKIKO reg %0x [%s] with %08x at PC=%06x\n", offset, get_akiko_reg_name(offset), data, m_space->device().safe_pc() );
logerror( "Writing AKIKO reg %0x [%s] with %08x at %s\n", offset, get_akiko_reg_name(offset), data, machine().describe_context());
}
switch( offset )

View File

@ -26,9 +26,17 @@
// INTERFACE CONFIGURATION MACROS
//**************************************************************************
#define MCFG_AKIKO_ADD(_tag, _cputag) \
MCFG_DEVICE_ADD(_tag, AKIKO, 0) \
akiko_device::set_cputag(*device, _cputag);
#define MCFG_AKIKO_ADD(_tag) \
MCFG_DEVICE_ADD(_tag, AKIKO, 0)
#define MCFG_AKIKO_MEM_READ_CB(_devcb) \
devcb = &akiko_device::set_mem_r_callback(*device, DEVCB_##_devcb);
#define MCFG_AKIKO_MEM_WRITE_CB(_devcb) \
devcb = &akiko_device::set_mem_w_callback(*device, DEVCB_##_devcb);
#define MCFG_AKIKO_INT_CB(_devcb) \
devcb = &akiko_device::set_int_w_callback(*device, DEVCB_##_devcb);
#define MCFG_AKIKO_SCL_HANDLER(_devcb) \
devcb = &akiko_device::set_scl_handler(*device, DEVCB_##_devcb);
@ -53,6 +61,15 @@ public:
~akiko_device() {}
// callbacks
template<class _Object> static devcb_base &set_mem_r_callback(device_t &device, _Object object)
{ return downcast<akiko_device &>(device).m_mem_r.set_callback(object); }
template<class _Object> static devcb_base &set_mem_w_callback(device_t &device, _Object object)
{ return downcast<akiko_device &>(device).m_mem_w.set_callback(object); }
template<class _Object> static devcb_base &set_int_w_callback(device_t &device, _Object object)
{ return downcast<akiko_device &>(device).m_int_w.set_callback(object); }
template<class _Object> static devcb_base &set_scl_handler(device_t &device, _Object object)
{ return downcast<akiko_device &>(device).m_scl_w.set_callback(object); }
@ -65,9 +82,6 @@ public:
DECLARE_READ32_MEMBER( read );
DECLARE_WRITE32_MEMBER( write );
// inline configuration
static void set_cputag(device_t &device, const char *tag);
protected:
// device-level overrides
virtual void device_start() override;
@ -79,9 +93,6 @@ private:
// 1X CDROM sector time in msec (300KBps)
static const int CD_SECTOR_TIME = (1000/((150*1024)/2048));
// internal state
address_space *m_space;
// chunky to planar converter
uint32_t m_c2p_input_buffer[8];
uint32_t m_c2p_output_buffer[8];
@ -123,6 +134,9 @@ private:
void nvram_write(uint32_t data);
uint32_t nvram_read();
uint8_t mem_r8(offs_t offset);
void mem_w8(offs_t offset, uint8_t data);
void c2p_write(uint32_t data);
uint32_t c2p_read();
@ -141,12 +155,13 @@ private:
TIMER_CALLBACK_MEMBER( cd_delayed_cmd );
void update_cdrom();
// i2c interface
// interface
devcb_read16 m_mem_r;
devcb_write16 m_mem_w;
devcb_write_line m_int_w;
devcb_write_line m_scl_w;
devcb_read_line m_sda_r;
devcb_write_line m_sda_w;
const char *m_cputag;
};
// device type definition

View File

@ -314,6 +314,7 @@ public:
m_cdda(*this, "cdda")
{ }
DECLARE_WRITE_LINE_MEMBER( akiko_int_w );
DECLARE_WRITE8_MEMBER( akiko_cia_0_port_a_write );
void handle_joystick_cia(uint8_t pra, uint8_t dra);
@ -825,6 +826,11 @@ WRITE32_MEMBER( a4000_state::motherboard_w )
logerror("motherboard_w(%06x): %08x & %08x\n", offset, data, mem_mask);
}
WRITE_LINE_MEMBER( cd32_state::akiko_int_w )
{
set_interrupt(INTENA_SETCLR | INTENA_PORTS);
}
void cd32_state::potgo_w(uint16_t data)
{
int i;
@ -1813,7 +1819,10 @@ static MACHINE_CONFIG_DERIVED_CLASS( cd32, amiga_base, cd32_state )
MCFG_I2CMEM_PAGE_SIZE(16)
MCFG_I2CMEM_DATA_SIZE(1024)
MCFG_AKIKO_ADD("akiko", "maincpu")
MCFG_AKIKO_ADD("akiko")
MCFG_AKIKO_MEM_READ_CB(READ16(amiga_state, chip_ram_r))
MCFG_AKIKO_MEM_WRITE_CB(WRITE16(amiga_state, chip_ram_w))
MCFG_AKIKO_INT_CB(WRITELINE(cd32_state, akiko_int_w))
MCFG_AKIKO_SCL_HANDLER(DEVWRITELINE("i2cmem", i2cmem_device, write_scl))
MCFG_AKIKO_SDA_READ_HANDLER(DEVREADLINE("i2cmem", i2cmem_device, read_sda))
MCFG_AKIKO_SDA_WRITE_HANDLER(DEVWRITELINE("i2cmem", i2cmem_device, write_sda))

View File

@ -337,6 +337,7 @@ public:
DECLARE_CUSTOM_INPUT_MEMBER(cubo_input);
DECLARE_CUSTOM_INPUT_MEMBER(cd32_sel_mirror_input);
DECLARE_WRITE_LINE_MEMBER( akiko_int_w );
DECLARE_WRITE8_MEMBER( akiko_cia_0_port_a_write );
DECLARE_DRIVER_INIT(cubo);
@ -376,6 +377,12 @@ private:
};
WRITE_LINE_MEMBER( cubo_state::akiko_int_w )
{
set_interrupt(INTENA_SETCLR | INTENA_PORTS);
}
/*************************************
*
* CIA-A port A access:
@ -1033,7 +1040,10 @@ static MACHINE_CONFIG_START( cubo, cubo_state )
MCFG_I2CMEM_PAGE_SIZE(16)
MCFG_I2CMEM_DATA_SIZE(1024)
MCFG_AKIKO_ADD("akiko", "maincpu")
MCFG_AKIKO_ADD("akiko")
MCFG_AKIKO_MEM_READ_CB(READ16(amiga_state, chip_ram_r))
MCFG_AKIKO_MEM_WRITE_CB(WRITE16(amiga_state, chip_ram_w))
MCFG_AKIKO_INT_CB(WRITELINE(cubo_state, akiko_int_w))
MCFG_AKIKO_SCL_HANDLER(DEVWRITELINE("i2cmem", i2cmem_device, write_scl))
MCFG_AKIKO_SDA_READ_HANDLER(DEVREADLINE("i2cmem", i2cmem_device, read_sda))
MCFG_AKIKO_SDA_WRITE_HANDLER(DEVWRITELINE("i2cmem", i2cmem_device, write_sda))

View File

@ -385,7 +385,16 @@ public:
m_chip_ram.write(byteoffs >> 1, data);
}
DECLARE_READ16_MEMBER(chip_ram_r) { return chip_ram_r(offset); }
DECLARE_READ16_MEMBER(chip_ram_r)
{
return chip_ram_r(offset & ~1) & mem_mask;
}
DECLARE_WRITE16_MEMBER(chip_ram_w)
{
uint16_t val = chip_ram_r(offset & ~1) & ~mem_mask;
chip_ram_w(offset & ~1, val | data);
}
/* sprite states */
uint8_t m_sprite_comparitor_enable_mask;