1 // license:BSD-3-Clause
2 // copyright-holders:Curt Coder
3 /**********************************************************************
4 
5     Kingsoft cartridge emulation
6 
7 **********************************************************************/
8 
9 #include "emu.h"
10 #include "kingsoft.h"
11 
12 
13 
14 //**************************************************************************
15 //  DEVICE DEFINITIONS
16 //**************************************************************************
17 
18 DEFINE_DEVICE_TYPE(C64_KINGSOFT, c64_kingsoft_cartridge_device, "c64_kingsoft", "C64 Kingsoft cartridge")
19 
20 
21 
22 //**************************************************************************
23 //  LIVE DEVICE
24 //**************************************************************************
25 
26 //-------------------------------------------------
27 //  c64_kingsoft_cartridge_device - constructor
28 //-------------------------------------------------
29 
c64_kingsoft_cartridge_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)30 c64_kingsoft_cartridge_device::c64_kingsoft_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
31 	device_t(mconfig, C64_KINGSOFT, tag, owner, clock),
32 	device_c64_expansion_card_interface(mconfig, *this)
33 {
34 }
35 
36 
37 //-------------------------------------------------
38 //  device_start - device-specific startup
39 //-------------------------------------------------
40 
device_start()41 void c64_kingsoft_cartridge_device::device_start()
42 {
43 }
44 
45 
46 //-------------------------------------------------
47 //  device_reset - device-specific reset
48 //-------------------------------------------------
49 
device_reset()50 void c64_kingsoft_cartridge_device::device_reset()
51 {
52 	m_exrom = 0;
53 }
54 
55 
56 //-------------------------------------------------
57 //  c64_cd_r - cartridge data read
58 //-------------------------------------------------
59 
c64_cd_r(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)60 uint8_t c64_kingsoft_cartridge_device::c64_cd_r(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
61 {
62 	if (!roml)
63 	{
64 		data = m_roml[offset & 0x1fff];
65 	}
66 	else if (!romh)
67 	{
68 		data = m_romh[(m_exrom << 13) | (offset & 0x1fff)];
69 	}
70 	else if (!io1)
71 	{
72 		m_exrom = 0;
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 c64_kingsoft_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 		m_exrom = 1;
88 	}
89 }
90 
91 
92 //-------------------------------------------------
93 //  c64_game_r - GAME read
94 //-------------------------------------------------
95 
c64_game_r(offs_t offset,int sphi2,int ba,int rw)96 int c64_kingsoft_cartridge_device::c64_game_r(offs_t offset, int sphi2, int ba, int rw)
97 {
98 	return m_exrom & ((ba & rw & ((offset >= 0x8000 && offset < 0xc000) || (offset >= 0xe000))) ? 0 : 1);
99 }
100