1 // license:BSD-3-Clause
2 // copyright-holders:Curt Coder
3 /**********************************************************************
4 
5     Cinemaware Warp Speed cartridge emulation
6 
7 **********************************************************************/
8 
9 /*
10 
11     PCB Layout
12     ----------
13 
14     |===================|
15     |=|             SW1 |
16     |=|                 |
17     |=|             SW2 |
18     |=|                 |
19     |=|                 |
20     |=|    ROM          |
21     |=|            LS109|
22     |=|                 |
23     |===================|
24 
25     ROM     - "DEI-356NR-WRPIIDA1 (C) NCR A8847 609-2415038 F833071" 16Kx8 ROM
26     SW1     - mode switch (C64/C128)
27     SW2     - reset button
28 
29 */
30 
31 #include "emu.h"
32 #include "warp_speed.h"
33 
34 
35 
36 //**************************************************************************
37 //  MACROS/CONSTANTS
38 //**************************************************************************
39 
40 #define UNSCRAMBLE_ADDRESS(_offset) \
41 	bitswap<16>(_offset,15,14,12,13,5,2,7,9,11,10,8,6,4,3,1,0)
42 
43 #define UNSCRAMBLE_DATA(_data) \
44 	bitswap<8>(_data,7,6,5,0,1,4,2,3)
45 
46 
47 
48 //**************************************************************************
49 //  DEVICE DEFINITIONS
50 //**************************************************************************
51 
52 DEFINE_DEVICE_TYPE(C64_WARP_SPEED, c64_warp_speed_cartridge_device, "c64_warp_speed", "C64 Warp Speed cartridge")
53 
54 
55 //-------------------------------------------------
56 //  INPUT_PORTS( c64_warp_speed )
57 //-------------------------------------------------
58 
INPUT_PORTS_START(c64_warp_speed)59 static INPUT_PORTS_START( c64_warp_speed )
60 	PORT_START("SW1")
61 	PORT_DIPNAME( 0x01, 0x01, "Mode" )
62 	PORT_DIPSETTING(    0x01, "C64" )
63 	PORT_DIPSETTING(    0x00, "C128" )
64 
65 	PORT_START("SW2")
66 	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("Reset") PORT_CODE(KEYCODE_F11) PORT_WRITE_LINE_DEVICE_MEMBER(DEVICE_SELF_OWNER, c64_expansion_slot_device, reset_w)
67 INPUT_PORTS_END
68 
69 
70 //-------------------------------------------------
71 //  input_ports - device-specific input ports
72 //-------------------------------------------------
73 
74 ioport_constructor c64_warp_speed_cartridge_device::device_input_ports() const
75 {
76 	return INPUT_PORTS_NAME( c64_warp_speed );
77 }
78 
79 
80 
81 //**************************************************************************
82 //  LIVE DEVICE
83 //**************************************************************************
84 
85 //-------------------------------------------------
86 //  c64_warp_speed_cartridge_device - constructor
87 //-------------------------------------------------
88 
c64_warp_speed_cartridge_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)89 c64_warp_speed_cartridge_device::c64_warp_speed_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
90 	device_t(mconfig, C64_WARP_SPEED, tag, owner, clock),
91 	device_c64_expansion_card_interface(mconfig, *this)
92 {
93 }
94 
95 
96 //-------------------------------------------------
97 //  device_start - device-specific startup
98 //-------------------------------------------------
99 
device_start()100 void c64_warp_speed_cartridge_device::device_start()
101 {
102 }
103 
104 
105 //-------------------------------------------------
106 //  device_reset - device-specific reset
107 //-------------------------------------------------
108 
device_reset()109 void c64_warp_speed_cartridge_device::device_reset()
110 {
111 	m_exrom = 0;
112 	m_game = 0;
113 }
114 
115 
116 //-------------------------------------------------
117 //  c64_cd_r - cartridge data read
118 //-------------------------------------------------
119 
c64_cd_r(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)120 uint8_t c64_warp_speed_cartridge_device::c64_cd_r(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
121 {
122 	if (!roml || !romh || !io1 || !io2)
123 	{
124 		offs_t addr = UNSCRAMBLE_ADDRESS(offset & 0x3fff);
125 		data = UNSCRAMBLE_DATA(m_roml[addr]);
126 	}
127 
128 	return data;
129 }
130 
131 
132 //-------------------------------------------------
133 //  c64_cd_w - cartridge data write
134 //-------------------------------------------------
135 
c64_cd_w(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)136 void c64_warp_speed_cartridge_device::c64_cd_w(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
137 {
138 	if (!io1)
139 	{
140 		m_exrom = 0;
141 		m_game = 0;
142 	}
143 	else if (!io2)
144 	{
145 		m_exrom = 1;
146 		m_game = 1;
147 	}
148 }
149