1 /*
2  *  KCemu -- The emulator for the KC85 homecomputer series and much more.
3  *  Copyright (C) 1997-2010 Torsten Paul
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License along
16  *  with this program; if not, write to the Free Software Foundation, Inc.,
17  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #include <iostream>
21 #include <iomanip>
22 
23 #include "kc/system.h"
24 
25 #include "kc/kc.h"
26 #include "kc/pio6.h"
27 #include "kc/poly880.h"
28 
29 #include "libdbg/dbg.h"
30 
PIO6_1(void)31 PIO6_1::PIO6_1(void)
32 {
33   _led_value = 0;
34   set_B_EXT(0xff, 0x00);
35 }
36 
~PIO6_1(void)37 PIO6_1::~PIO6_1(void)
38 {
39 }
40 
41 byte_t
in(word_t addr)42 PIO6_1::in(word_t addr)
43 {
44   byte_t val = 0xff;
45 
46   switch (addr & 3)
47     {
48     case 0:
49       val = in_A_DATA();
50       break;
51     case 1:
52       val = in_A_CTRL();
53       break;
54     case 2:
55       val = in_B_DATA();
56       break;
57     case 3:
58       val = in_B_CTRL();
59       break;
60     }
61 
62   DBG(2, form("KCemu/PIO/6a/in",
63               "PIO6_1::in():  addr = %04x, val = %02x\n",
64               addr, val));
65 
66   return val;
67 }
68 
69 void
out(word_t addr,byte_t val)70 PIO6_1::out(word_t addr, byte_t val)
71 {
72   DBG(2, form("KCemu/PIO/6a/out",
73               "PIO6_1::out(): addr = %04x, val = %02x\n",
74               addr, val));
75 
76   switch (addr & 3)
77     {
78     case 0:
79       out_A_DATA(val);
80       _led_value = val;
81       break;
82     case 1:
83       out_A_CTRL(val);
84       break;
85     case 2:
86       out_B_DATA(val);
87       break;
88     case 3:
89       out_B_CTRL(val);
90       break;
91     }
92 }
93 
94 void
change_A(byte_t changed,byte_t val)95 PIO6_1::change_A(byte_t changed, byte_t val)
96 {
97 }
98 
99 void
change_B(byte_t changed,byte_t val)100 PIO6_1::change_B(byte_t changed, byte_t val)
101 {
102   poly880->set_scon((val & 64) == 64);
103   //printf("port B: %02x %s %s\n", val, (val & 4)  ? "MOUT" : "mout", (val & 64) ? "SCON" : "scon");
104 }
105 
106 byte_t
get_led_value(void)107 PIO6_1::get_led_value(void)
108 {
109   return _led_value;
110 }
111 
PIO6_2(void)112 PIO6_2::PIO6_2(void)
113 {
114 }
115 
~PIO6_2(void)116 PIO6_2::~PIO6_2(void)
117 {
118 }
119 
120 byte_t
in(word_t addr)121 PIO6_2::in(word_t addr)
122 {
123   byte_t val = 0xff;
124 
125   switch (addr & 3)
126     {
127     case 0:
128       val = in_A_DATA();
129       break;
130     case 1:
131       val = in_A_CTRL();
132       break;
133     case 2:
134       val = in_B_DATA();
135       break;
136     case 3:
137       val = in_B_CTRL();
138       break;
139     }
140 
141   DBG(2, form("KCemu/PIO/6b/in",
142               "PIO6_2::in():  addr = %04x, val = %02x\n",
143               addr, val));
144 
145   return val;
146 }
147 
148 void
out(word_t addr,byte_t val)149 PIO6_2::out(word_t addr, byte_t val)
150 {
151   DBG(2, form("KCemu/PIO/6b/out",
152               "PIO6_2::out(): addr = %04x, val = %02x\n",
153               addr, val));
154 
155   switch (addr & 3)
156     {
157     case 0:
158       out_A_DATA(val);
159       break;
160     case 1:
161       out_A_CTRL(val);
162       break;
163     case 2:
164       out_B_DATA(val);
165       break;
166     case 3:
167       out_B_CTRL(val);
168       break;
169     }
170 }
171 
172 void
change_A(byte_t changed,byte_t val)173 PIO6_2::change_A(byte_t changed, byte_t val)
174 {
175 }
176 
177 void
change_B(byte_t changed,byte_t val)178 PIO6_2::change_B(byte_t changed, byte_t val)
179 {
180 }
181