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/z80.h"
26 #include "kc/ctc1.h"
27 #include "kc/tape.h"
28
29 #include "libdbg/dbg.h"
30
CTC1(void)31 CTC1::CTC1(void)
32 {
33 _last_irq_0 = 0;
34 }
35
~CTC1(void)36 CTC1::~CTC1(void)
37 {
38 }
39
40 byte_t
in(word_t addr)41 CTC1::in(word_t addr)
42 {
43 DBG(2, form("KCemu/CTC/1/in",
44 "CTC1::in(): addr = %04x\n",
45 addr));
46
47 switch (addr & 3)
48 {
49 case 0:
50 return c_in(0);
51 case 1:
52 return c_in(1);
53 case 2:
54 return c_in(2);
55 case 3:
56 return c_in(3);
57 }
58
59 return 0; // shouldn't be reached
60 }
61
62 void
out(word_t addr,byte_t val)63 CTC1::out(word_t addr, byte_t val)
64 {
65 DBG(2, form("KCemu/CTC/1/out",
66 "CTC1::out(): addr = %04x, val = %02x\n",
67 addr, val));
68
69 switch (addr & 3)
70 {
71 case 0:
72 c_out(0, val);
73 break;
74 case 1:
75 c_out(1, val);
76 break;
77 case 2:
78 c_out(2, val);
79 break;
80 case 3:
81 c_out(3, val);
82 break;
83 }
84 }
85
86 bool
irq_0(void)87 CTC1::irq_0(void)
88 {
89 unsigned long diff;
90 unsigned long long c;
91
92 c = z80->getCounter();
93 diff = (unsigned long)(c - _last_irq_0);
94 _last_irq_0 = c;
95 if (diff > 3000)
96 return false;
97
98 tape->tape_signal();
99
100 _last_irq_0 = c;
101
102 return false;
103 }
104
105 bool
irq_1(void)106 CTC1::irq_1(void)
107 {
108 return false;
109 }
110
111 bool
irq_2(void)112 CTC1::irq_2(void)
113 {
114 trigger(3);
115 return false;
116 }
117
118 bool
irq_3(void)119 CTC1::irq_3(void)
120 {
121 return false;
122 }
123
124 long
counter_value_0(void)125 CTC1::counter_value_0(void)
126 {
127 return 0;
128 }
129
130 long
counter_value_1(void)131 CTC1::counter_value_1(void)
132 {
133 return 0;
134 }
135
136 long
counter_value_2(void)137 CTC1::counter_value_2(void)
138 {
139 return 0;
140 }
141
142 long
counter_value_3(void)143 CTC1::counter_value_3(void)
144 {
145 return 0;
146 }
147