summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/cpu/psx/dma.h
blob: 5d47dcdea771d3329c73015617d90978b2dd74b8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// license:MAME
// copyright-holders:smf
/*
 * PlayStation DMA emulator
 *
 * Copyright 2003-2011 smf
 *
 */

#pragma once

#ifndef __PSXDMA_H__
#define __PSXDMA_H__

#include "emu.h"

extern const device_type PSX_DMA;

#define MCFG_PSX_DMA_IRQ_HANDLER(_devcb) \
	devcb = &psxdma_device::set_irq_handler(*device, DEVCB_##_devcb);

typedef delegate<void (UINT32 *, UINT32, INT32)> psx_dma_read_delegate;
typedef delegate<void (UINT32 *, UINT32, INT32)> psx_dma_write_delegate;

struct psx_dma_channel
{
	UINT32 n_base;
	UINT32 n_blockcontrol;
	UINT32 n_channelcontrol;
	emu_timer *timer;
	psx_dma_read_delegate fn_read;
	psx_dma_write_delegate fn_write;
	UINT32 n_ticks;
	UINT32 b_running;
};

class psxdma_device : public device_t
{
public:
	psxdma_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);

	// static configuration helpers
	template<class _Object> static devcb_base &set_irq_handler(device_t &device, _Object object) { return downcast<psxdma_device &>(device).m_irq_handler.set_callback(object); }

	void install_read_handler( int n_channel, psx_dma_read_delegate p_fn_dma_read );
	void install_write_handler( int n_channel, psx_dma_read_delegate p_fn_dma_write );

	DECLARE_WRITE32_MEMBER( write );
	DECLARE_READ32_MEMBER( read );

	UINT32 *m_ram;
	size_t m_ramsize;

protected:
	virtual void device_start();
	virtual void device_reset();
	virtual void device_post_load();
	virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);

private:
	void dma_start_timer( int n_channel, UINT32 n_ticks );
	void dma_stop_timer( int n_channel );
	void dma_timer_adjust( int n_channel );
	void dma_interrupt_update();
	void dma_finished( int n_channel );
	void write( offs_t offset, UINT32 data, UINT32 mem_mask );
	UINT32 read( offs_t offset, UINT32 mem_mask );

	psx_dma_channel m_channel[7];
	UINT32 m_dpcp;
	UINT32 m_dicr;

	devcb_write_line m_irq_handler;
};

#endif