1 // license:GPL-2.0+
2 // copyright-holders:Peter Trauner
3 #include "emu.h"
4 #include "cpu/sc61860/sc61860.h"
5
6 #include "includes/pocketc.h"
7 #include "includes/pc1403.h"
8 #include "machine/ram.h"
9
10 #define LOG_ASIC (1 << 0)
11
12 #define VERBSOE (0)
13 #include "logmacro.h"
14
15 /* C-CE while reset, program will not be destroyed! */
16
17 /*
18 port 2:
19 bits 0,1: external rom a14,a15 lines
20 port 3:
21 bits 0..6 keyboard output select matrix line
22 */
23
asic_write(offs_t offset,uint8_t data)24 void pc1403_state::asic_write(offs_t offset, uint8_t data)
25 {
26 m_asic[offset >> 9] = data;
27 switch (offset >> 9)
28 {
29 case 0: // 0x3800
30 // output
31 LOGMASKED(LOG_ASIC, "asic write %.4x %.2x\n", offset, data);
32 break;
33 case 1: // 0x3a00
34 LOGMASKED(LOG_ASIC, "asic write %.4x %.2x\n", offset, data);
35 break;
36 case 2: // 0x3c00
37 membank("bank1")->set_base(memregion("user1")->base() + ((data & 7) << 14));
38 LOGMASKED(LOG_ASIC, "asic write %.4x %.2x\n", offset, data);
39 break;
40 case 3: // 0x3e00
41 break;
42 }
43 }
44
asic_read(offs_t offset)45 uint8_t pc1403_state::asic_read(offs_t offset)
46 {
47 uint8_t data = m_asic[offset >> 9];
48 switch (offset >> 9)
49 {
50 case 0:
51 case 1:
52 case 2:
53 LOGMASKED(LOG_ASIC, "asic read %.4x %.2x\n", offset, data);
54 break;
55 }
56 return data;
57 }
58
in_a_r()59 uint8_t pc1403_state::in_a_r()
60 {
61 uint8_t data = m_outa;
62
63 for (int bit = 0; bit < 7; bit++)
64 if (BIT(m_asic[3], bit))
65 data |= m_keys[bit]->read();
66
67 if (BIT(m_outa, 0))
68 {
69 data |= m_keys[7]->read();
70
71 /* At Power Up we fake a 'C-CE' pressure */
72 if (m_power)
73 data |= 0x02;
74 }
75
76 for (int bit = 1, key = 8; bit < 7; bit++, key++)
77 if (BIT(m_outa, bit))
78 data |= m_keys[key]->read();
79
80 return data;
81 }
82
out_c_w(uint8_t data)83 void pc1403_state::out_c_w(uint8_t data)
84 {
85 m_portc = data;
86 }
87
READ_LINE_MEMBER(pc1403_state::reset_r)88 READ_LINE_MEMBER(pc1403_state::reset_r)
89 {
90 return BIT(m_extra->read(), 1);
91 }
92
machine_start()93 void pc1403_state::machine_start()
94 {
95 pocketc_state::machine_start();
96
97 membank("bank1")->set_base(memregion("user1")->base());
98
99 m_ram_nvram->set_base(memregion("maincpu")->base() + 0x8000, 0x8000);
100
101 uint8_t *gfx = memregion("gfx1")->base();
102 for (int i = 0; i < 128; i++)
103 gfx[i] = i;
104 }
105