1 // license:BSD-3-Clause
2 // copyright-holders:Curt Coder
3 /**********************************************************************
4 
5     Commodore 64 Expansion Port emulation
6 
7 **********************************************************************
8 
9                     GND       1      A       GND
10                     +5V       2      B       _ROMH
11                     +5V       3      C       _RESET
12                    _IRQ       4      D       _NMI
13                   _CR/W       5      E       Sphi2
14                  DOTCLK       6      F       CA15
15                   _I/O1       7      H       CA14
16                   _GAME       8      J       CA13
17                  _EXROM       9      K       CA12
18                   _I/O2      10      L       CA11
19                   _ROML      11      M       CA10
20                      BA      12      N       CA9
21                    _DMA      13      P       CA8
22                     CD7      14      R       CA7
23                     CD6      15      S       CA6
24                     CD5      16      T       CA5
25                     CD4      17      U       CA4
26                     CD3      18      V       CA3
27                     CD2      19      W       CA2
28                     CD1      20      X       CA1
29                     CD0      21      Y       CA0
30                     GND      22      Z       GND
31 
32 **********************************************************************/
33 
34 #ifndef MAME_BUS_C64_EXP_H
35 #define MAME_BUS_C64_EXP_H
36 
37 #pragma once
38 
39 #include "softlist_dev.h"
40 #include "formats/cbm_crt.h"
41 
42 
43 
44 //**************************************************************************
45 //  TYPE DEFINITIONS
46 //**************************************************************************
47 
48 // ======================> c64_expansion_slot_device
49 
50 class device_c64_expansion_card_interface;
51 
52 class c64_expansion_slot_device : public device_t,
53 									public device_single_card_slot_interface<device_c64_expansion_card_interface>,
54 									public device_image_interface
55 {
56 public:
57 	// construction/destruction
58 	template <typename T>
c64_expansion_slot_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock,T && opts,const char * dflt)59 	c64_expansion_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock, T &&opts, const char *dflt)
60 		: c64_expansion_slot_device(mconfig, tag, owner, clock)
61 	{
62 		option_reset();
63 		opts(*this);
64 		set_default_option(dflt);
65 		set_fixed(false);
66 	}
67 
68 	c64_expansion_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
69 
irq_callback()70 	auto irq_callback() { return m_write_irq.bind(); }
nmi_callback()71 	auto nmi_callback() { return m_write_nmi.bind(); }
reset_callback()72 	auto reset_callback() { return m_write_reset.bind(); }
cd_input_callback()73 	auto cd_input_callback() { return m_read_dma_cd.bind(); }
cd_output_callback()74 	auto cd_output_callback() { return m_write_dma_cd.bind(); }
dma_callback()75 	auto dma_callback() { return m_write_dma.bind(); }
76 
77 	// computer interface
78 	uint8_t cd_r(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2);
79 	void cd_w(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2);
80 	int game_r(offs_t offset, int sphi2, int ba, int rw, int loram, int hiram);
81 	int exrom_r(offs_t offset, int sphi2, int ba, int rw, int loram, int hiram);
82 
83 	// cartridge interface
dma_cd_r(offs_t offset)84 	uint8_t dma_cd_r(offs_t offset) { return m_read_dma_cd(offset); }
dma_cd_w(offs_t offset,uint8_t data)85 	void dma_cd_w(offs_t offset, uint8_t data) { m_write_dma_cd(offset, data); }
DECLARE_WRITE_LINE_MEMBER(irq_w)86 	DECLARE_WRITE_LINE_MEMBER( irq_w ) { m_write_irq(state); }
DECLARE_WRITE_LINE_MEMBER(nmi_w)87 	DECLARE_WRITE_LINE_MEMBER( nmi_w ) { m_write_nmi(state); }
DECLARE_WRITE_LINE_MEMBER(dma_w)88 	DECLARE_WRITE_LINE_MEMBER( dma_w ) { m_write_dma(state); }
DECLARE_WRITE_LINE_MEMBER(reset_w)89 	DECLARE_WRITE_LINE_MEMBER( reset_w ) { m_write_reset(state); }
phi2()90 	int phi2() { return clock(); }
dotclock()91 	int dotclock() { return phi2() * 8; }
hiram()92 	int hiram() { return m_hiram; }
loram()93 	int loram() { return m_loram; }
94 
95 	void set_passthrough();
96 
97 protected:
98 	// device-level overrides
99 	virtual void device_start() override;
100 	virtual void device_reset() override;
101 
102 	// image-level overrides
103 	virtual image_init_result call_load() override;
get_software_list_loader()104 	virtual const software_list_loader &get_software_list_loader() const override { return rom_software_list_loader::instance(); }
105 
image_type()106 	virtual iodevice_t image_type() const noexcept override { return IO_CARTSLOT; }
107 
is_readable()108 	virtual bool is_readable()  const noexcept override { return true; }
is_writeable()109 	virtual bool is_writeable() const noexcept override { return false; }
is_creatable()110 	virtual bool is_creatable() const noexcept override { return false; }
must_be_loaded()111 	virtual bool must_be_loaded() const noexcept override { return false; }
is_reset_on_load()112 	virtual bool is_reset_on_load() const noexcept override { return true; }
image_interface()113 	virtual const char *image_interface() const noexcept override { return "c64_cart,vic10_cart"; }
file_extensions()114 	virtual const char *file_extensions() const noexcept override { return "80,a0,e0,crt"; }
115 
116 	// slot interface overrides
117 	virtual std::string get_default_card_software(get_default_card_software_hook &hook) const override;
118 
119 	devcb_read8        m_read_dma_cd;
120 	devcb_write8       m_write_dma_cd;
121 	devcb_write_line   m_write_irq;
122 	devcb_write_line   m_write_nmi;
123 	devcb_write_line   m_write_dma;
124 	devcb_write_line   m_write_reset;
125 
126 	device_c64_expansion_card_interface *m_card;
127 
128 	int m_hiram;
129 	int m_loram;
130 };
131 
132 
133 // ======================> device_c64_expansion_card_interface
134 
135 class device_c64_expansion_card_interface : public device_interface
136 {
137 	friend class c64_expansion_slot_device;
138 
139 public:
140 	// construction/destruction
141 	virtual ~device_c64_expansion_card_interface();
142 
c64_cd_r(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)143 	virtual uint8_t c64_cd_r(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2) { return data; };
c64_cd_w(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)144 	virtual void c64_cd_w(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2) { };
c64_game_r(offs_t offset,int sphi2,int ba,int rw)145 	virtual int c64_game_r(offs_t offset, int sphi2, int ba, int rw) { return m_game; }
c64_exrom_r(offs_t offset,int sphi2,int ba,int rw)146 	virtual int c64_exrom_r(offs_t offset, int sphi2, int ba, int rw) { return m_exrom; }
147 
148 protected:
149 	device_c64_expansion_card_interface(const machine_config &mconfig, device_t &device);
150 
151 	optional_shared_ptr<uint8_t> m_roml;
152 	optional_shared_ptr<uint8_t> m_romh;
153 	optional_shared_ptr<uint8_t> m_romx;
154 	optional_shared_ptr<uint8_t> m_nvram;
155 
156 	int m_game;
157 	int m_exrom;
158 
159 	c64_expansion_slot_device *m_slot;
160 };
161 
162 
163 // device type definition
164 DECLARE_DEVICE_TYPE(C64_EXPANSION_SLOT, c64_expansion_slot_device)
165 
166 void c64_expansion_cards(device_slot_interface &device);
167 
168 #endif
169