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 <unistd.h> // sleep();
21
22 #include "kc/system.h"
23
24 #include "kc/kc.h"
25 #include "kc/pio.h"
26 #include "kc/keyb0.h"
27 #include "kc/ports0.h"
28
29 #include "libdbg/dbg.h"
30
Ports0(void)31 Ports0::Ports0(void)
32 {
33 for (int a = 0;a < NR_PORTS;a++)
34 inout[a] = 0xff;
35 }
36
~Ports0(void)37 Ports0::~Ports0(void)
38 {
39 }
40
41 byte_t
in(word_t addr)42 Ports0::in(word_t addr)
43 {
44 byte_t a = addr & 0xff;
45 byte_t val = inout[a];
46
47 switch (a)
48 {
49 case 0x08:
50 break;
51 default:
52 DBG(0, form("KCemu/internal_error",
53 "Ports0: called in() with undefined address %04xh\n",
54 addr));
55 break;
56 }
57
58 DBG(2, form("KCemu/Ports/0/in",
59 "Ports0: in() addr = %04x (returning %02x)\n",
60 addr, val));
61
62 return val;
63 }
64
65 void
out(word_t addr,byte_t val)66 Ports0::out(word_t addr, byte_t val)
67 {
68 byte_t a = addr & 0xff;
69
70 DBG(2, form("KCemu/Ports/0/out",
71 "Ports0: out() addr = %04x, val = %02x\n",
72 addr, val));
73
74 switch (a)
75 {
76 case 0x08:
77 change_0x08(inout[a] ^ val, val);
78 break;
79 default:
80 DBG(0, form("KCemu/internal_error",
81 "Ports0: called out() with undefined address %04xh (val = %02xh)\n",
82 addr, val));
83 break;
84 }
85
86 inout[a] = val;
87 }
88
89 void
change_0x08(byte_t changed,byte_t val)90 Ports0::change_0x08(byte_t changed, byte_t val)
91 {
92 ((Keyboard0 *)keyboard)->set_value(val & 0x0f);
93 }
94