summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/electron/cart/slot.h
blob: e0fc2666136ba3bd0b9512f897d4c6c292eae3d1 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// license:BSD-3-Clause
// copyright-holders:Nigel Barnes
/**********************************************************************

        Electron Cartridge slot emulation

**********************************************************************

    Pinout:
              A  B
        +5V   1  1   +5
        nOE   2  2   A10
       nRST   3  3   D3
         RW   4  4   A11
         A8   5  5   A9
        A13   6  6   D7
        A12   7  7   D6
       PHI2   8  8   D5
        -5V   9  9   D4
         NC  10  10  nOE2
      READY  11  11  BA7
       nNMI  12  12  BA6
       nIRQ  13  13  BA5
      nINFC  14  14  BA4
      nINFD  15  15  BA3
      ROMQA  16  16  BA2
      16MHz  17  17  BA1
    nROMSTB  18  18  BA0
      ADOUT  19  19  D0
       AGND  20  20  D2
         NC  21  21  D1
         0V  22  22  0V

    Signal Definitions:

    SIDE 'A'
    1     +5V - Power supply. This is the system logic supply rail.
    2     n0E - Output Enable : Input with CMOS levels. This is an active low signal during the PH12
                period of the system clock.
    3    nRST - System Reset : Input with CMOS levels. This signal is active low during system reset.
    4      RW - Read/Write : Input with CMOS levels. This pin is the CPU read/write line.
    5      A8 - Address line 8 : Input with TTL levels
    6     A13 - Address line 13 : Input with TTL levels
    7     A12 - Address line 12 : Input with TTL levels
    8    PH12 - CPU clock : Input with CMOS levels
                This input is the host computer PH12out.
    9     -5V - The negative supply voltage.
   10      NC - This is a "no connect" on the Electron.
   11   READY - CPU wait state control : Open collector output
   12    nNMI - Non maskable interrupt : Open collector output
                This signal is connected to the system NMI line. It is active low.
   13    nIRQ - Interrupt request : Open collector output
                This signal is connected to the system IRQ line. It is active low.
   14   nINFC - Internal Page &FC : Memory active decode input : TTL active low
   15   nINFD - Internal page &FD : Memory active decode input : TTL active low
   16   ROMQA - Memory paging select : Input with TTL levels
                This is the least significant bit of the ROM select latch located at &FE05 in the Electron.
   17   Clock - Clock is a 16MHz input with TTL levels.
   18 nROMSTB - nROMSTB is an active low input using TTL levels which selects the location &FC73.
                This is intended to be used as a paging register.
   19   ADOUT - System audio output
   20    AGND - Audio Ground
   21    ADIN - Cartridge audio output
   22      0V - Zero volts

    SIDE 'B'
    1     +5V - Power supply. This is the system logic supply rail.
    2     A10 - Address line 10 : Input with TTL levels
    3      D3 - Data bus line 3 : Input/Output with TTL levels
    4     A11 - Address line 11 : Input with TTL levels
    5      A9 - Address line 9 : Input with TTL levels
    6      D7 - Most significant data bus line : Input/Output with TTL levels
    7      D6 - Data bus line 6 : Input/Output with TTL levels
    8      D5 - Data bus line 5 : Input/Output with TTL levels
    9      D4 - Data bus line 4 : Input/Output with TTL levels
   10    nOE2 - Output Enable : Input with TTL levels
                This line provides an additional active low output enable for ROMs in the Electron.
                This corresponds to ROM position 13 and consequently responds quickly to service
                calls. It is low during the active low portion of PH12.
   11     BA7 - Buffered address line 7 : Input with TTL levels
   12     BA6 - Buffered address line 6 : Input with TTL levels
   13     BA5 - Buffered address line 5 : Input with TTL levels
   14     BA4 - Buffered address line 4 : Input with TTL levels
   15     BA3 - Buffered address line 3 : Input with TTL levels
   16     BA2 - Buffered address line 2 : Input with TTL levels
   17     BA1 - Buffered address line 1 : Input with TTL levels
   18     BA0 - Buffered address line 0 : Input with TTL levels
   19      D0 - Data bus line 0 : Input/Output with TTL levels
   20      D2 - Data bus line 2 : Input/Output with TTL levels
   21      D1 - Data bus line 1 : Input/Output with TTL levels
   22      0V - Zero volts.

**********************************************************************/
#ifndef MAME_BUS_ELECTRON_CARTSLOT_H
#define MAME_BUS_ELECTRON_CARTSLOT_H

#pragma once

#include "softlist_dev.h"


//**************************************************************************
//  INTERFACE CONFIGURATION MACROS
//**************************************************************************

#define ELECTRON_CART_ROM_REGION_TAG ":cart:rom"


//**************************************************************************
//  TYPE DEFINITIONS
//**************************************************************************

// ======================> electron_cartslot_device

class device_electron_cart_interface;

class electron_cartslot_device : public device_t,
									public device_image_interface,
									public device_single_card_slot_interface<device_electron_cart_interface>
{
public:
	// construction/destruction
	template <typename T>
	electron_cartslot_device(machine_config const &mconfig, char const *tag, device_t *owner, uint32_t clock, T &&slot_options, const char *default_option)
		: electron_cartslot_device(mconfig, tag, owner, clock)
	{
		option_reset();
		slot_options(*this);
		set_default_option(default_option);
		set_fixed(false);
	}

	electron_cartslot_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);

	// callbacks
	auto irq_handler() { return m_irq_handler.bind(); }
	auto nmi_handler() { return m_nmi_handler.bind(); }

	// image-level overrides
	virtual image_init_result call_load() override;
	virtual void call_unload() override;
	virtual const software_list_loader &get_software_list_loader() const override { return rom_software_list_loader::instance(); }

	virtual iodevice_t image_type() const override { return IO_CARTSLOT; }
	virtual bool is_readable()  const override { return true; }
	virtual bool is_writeable() const override { return true; }
	virtual bool is_creatable() const override { return false; }
	virtual bool must_be_loaded() const override { return false; }
	virtual bool is_reset_on_load() const override { return true; }
	virtual const char *image_interface() const override { return "electron_cart"; }
	virtual const char *file_extensions() const override { return "rom,bin"; }

	// slot interface overrides
	virtual std::string get_default_card_software(get_default_card_software_hook &hook) const override;

	// reading and writing
	virtual uint8_t read(offs_t offset, int infc, int infd, int romqa, int oe, int oe2);
	virtual void write(offs_t offset, uint8_t data, int infc, int infd, int romqa, int oe, int oe2);

	DECLARE_WRITE_LINE_MEMBER(irq_w) { m_irq_handler(state); }
	DECLARE_WRITE_LINE_MEMBER(nmi_w) { m_nmi_handler(state); }

protected:
	// device-level overrides
	virtual void device_start() override;

	device_electron_cart_interface *m_cart;

private:
	devcb_write_line m_irq_handler;
	devcb_write_line m_nmi_handler;
};


// ======================> device_electron_cart_interface

class device_electron_cart_interface : public device_interface
{
public:
	// construction/destruction
	virtual ~device_electron_cart_interface();

	// reading and writing
	virtual uint8_t read(offs_t offset, int infc, int infd, int romqa, int oe, int oe2) { return 0xff; }
	virtual void write(offs_t offset, uint8_t data, int infc, int infd, int romqa, int oe, int oe2) { }

	void rom_alloc(uint32_t size, const char *tag);
	void ram_alloc(uint32_t size);
	void nvram_alloc(uint32_t size);
	uint8_t* get_rom_base() { return m_rom; }
	uint8_t* get_ram_base() { return &m_ram[0]; }
	uint8_t* get_nvram_base() { return &m_nvram[0]; }
	uint32_t get_rom_size() { return m_rom_size; }
	uint32_t get_ram_size() { return m_ram.size(); }
	uint32_t get_nvram_size() { return m_nvram.size(); }

protected:
	device_electron_cart_interface(const machine_config &mconfig, device_t &device);

	electron_cartslot_device *m_slot;

	// internal state
	uint8_t *m_rom;
	uint32_t m_rom_size;
	std::vector<uint8_t> m_ram;
	std::vector<uint8_t> m_nvram;
};


// device type definition
DECLARE_DEVICE_TYPE(ELECTRON_CARTSLOT, electron_cartslot_device)

void electron_cart(device_slot_interface &device);


#endif // MAME_BUS_ELECTRON_CARTSLOT_H