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 <ctype.h>
21 
22 #include "kc/system.h"
23 
24 #include "kc/z80.h"
25 #include "kc/fdc0s.h"
26 
27 #include "libdbg/dbg.h"
28 
FDC0S(void)29 FDC0S::FDC0S(void)
30 {
31 }
32 
~FDC0S(void)33 FDC0S::~FDC0S(void)
34 {
35 }
36 
37 long long
get_counter()38 FDC0S::get_counter()
39 {
40   return z80->getCounter();
41 }
42 
43 void
add_callback(unsigned long long offset,Callback * cb,void * data)44 FDC0S::add_callback(unsigned long long offset, Callback *cb, void *data)
45 {
46   z80->addCallback(offset, cb, data);
47 }
48 
49 byte_t
in(word_t addr)50 FDC0S::in(word_t addr)
51 {
52   byte_t val;
53 
54   switch (addr & 0xff)
55     {
56     case 0xf0: // CFDC -- fdc control
57       val = get_msr();
58       break;
59     case 0xf1: // DFDC -- fdc data
60       val = in_data(addr);
61       break;
62     case 0xf2: // MOAUS -- drive motor off
63       break;
64     case 0xf4: // MOAUS -- drive motor on (device 1)
65       break;
66     case 0xf6: // MOTON -- drive motor on (device 0)
67       break;
68     case 0xf8: // TC -- terminal count
69       break;
70     case 0xfa: // FDCRES -- fdc reset
71       break;
72     default:
73       DBG(2, form("KCemu/FDC/in_unhandled",
74                   "FDC::in(): addr = %04x\n",
75                   addr));
76       break;
77     }
78 
79   return val;
80 }
81 
82 void
out(word_t addr,byte_t val)83 FDC0S::out(word_t addr, byte_t val)
84 {
85   switch (addr & 0xff)
86     {
87     case 0xf1:
88       out_data(addr, val);
89       break;
90     case 0xf8: // TC -- terminal count
91       set_terminal_count(1);
92       set_state(FDC_STATE_RESULT);
93       set_input_gate(0x40, 0x00);
94       break;
95     default:
96       DBG(2, form("KCemu/FDC/out_unhandled",
97                   "FDC::out(): addr = %04x, val = %02x [%c]\n",
98                   addr, val, isprint(val) ? val : '.'));
99       break;
100     }
101 }
102