1 // license:BSD-3-Clause
2 // copyright-holders:Curt Coder
3 /**********************************************************************
4 
5     Commodore 128 COMAL 80 cartridge emulation
6 
7 **********************************************************************/
8 
9 #include "emu.h"
10 #include "c128_comal80.h"
11 
12 
13 
14 //**************************************************************************
15 //  DEVICE DEFINITIONS
16 //**************************************************************************
17 
18 DEFINE_DEVICE_TYPE(C128_COMAL80, c128_comal80_cartridge_device, "c128_comal80", "C128 COMAL 80 cartridge")
19 
20 
21 
22 //**************************************************************************
23 //  LIVE DEVICE
24 //**************************************************************************
25 
26 //-------------------------------------------------
27 //  c128_comal80_cartridge_device - constructor
28 //-------------------------------------------------
29 
c128_comal80_cartridge_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)30 c128_comal80_cartridge_device::c128_comal80_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
31 	device_t(mconfig, C128_COMAL80, tag, owner, clock),
32 	device_c64_expansion_card_interface(mconfig, *this),
33 	m_bank(0)
34 {
35 }
36 
37 
38 //-------------------------------------------------
39 //  device_start - device-specific startup
40 //-------------------------------------------------
41 
device_start()42 void c128_comal80_cartridge_device::device_start()
43 {
44 	// state saving
45 	save_item(NAME(m_bank));
46 }
47 
48 
49 //-------------------------------------------------
50 //  device_reset - device-specific reset
51 //-------------------------------------------------
52 
device_reset()53 void c128_comal80_cartridge_device::device_reset()
54 {
55 	m_bank = 0;
56 }
57 
58 
59 //-------------------------------------------------
60 //  c64_cd_r - cartridge data read
61 //-------------------------------------------------
62 
c64_cd_r(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)63 uint8_t c128_comal80_cartridge_device::c64_cd_r(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
64 {
65 	if (!romh)
66 	{
67 		offs_t addr = ((m_bank & 0x07) << 14) | (offset & 0x3fff);
68 		data = m_romh[addr];
69 	}
70 	else if (!io1)
71 	{
72 		data = (m_bank << 4) | (data & 0x0f);
73 	}
74 
75 	return data;
76 }
77 
78 
79 //-------------------------------------------------
80 //  c64_cd_w - cartridge data write
81 //-------------------------------------------------
82 
c64_cd_w(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)83 void c128_comal80_cartridge_device::c64_cd_w(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
84 {
85 	if (!io1)
86 	{
87 		/*
88 
89 		    bit     description
90 
91 		    0
92 		    1
93 		    2
94 		    3
95 		    4       A14
96 		    5       A15
97 		    6       A16
98 		    7       A17
99 
100 		*/
101 
102 		m_bank = data >> 4;
103 	}
104 }
105