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 <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 
24 #include "kc/system.h"
25 
26 #include "kc/kc.h"
27 #include "kc/z80.h"
28 #include "kc/disk_io.h"
29 
30 #include "libdbg/dbg.h"
31 
FloppyIO(void)32 FloppyIO::FloppyIO(void)
33 {
34   _bit[0] = _bit[1] = _bit[2] = _bit[3] = 0;
35 }
36 
~FloppyIO(void)37 FloppyIO::~FloppyIO(void)
38 {
39 }
40 
41 /*
42  * BIT   7 6 5 4 3 2 1 0
43  *               | | | |
44  *               | | |  - Freigabe des Prozessors
45  *               | |  --- Setzen des Prozessors in Dauer-RESET
46  *               |  ----- Ausgabe RESET-Impuls
47  *                ------- Ausgabe NMI-Impuls
48  */
49 byte_t
in(word_t addr)50 FloppyIO::in(word_t addr)
51 {
52   byte_t val = _val;
53 
54   DBG(2, form("KCemu/FloppyIO/in",
55               "FloppyIO::in(): addr = %04x, val = %02x\n",
56               addr, val));
57 
58   return val;
59 }
60 
61 void
out(word_t addr,byte_t val)62 FloppyIO::out(word_t addr, byte_t val)
63 {
64   int a;
65 
66   DBG(2, form("KCemu/FloppyIO/out",
67               "FloppyIO::out(): addr = %04x, val = %02x\n",
68               addr, val));
69 
70   for (a = 0;a < 3;a++)
71     {
72       if (val & (1 << a))
73         {
74           _bit[a] = true;
75           /*
76            *  Hmm, the manual says activation is done after a 1/0
77            *  transition but this doen't really works :-(
78            */
79           activate(a);
80         }
81       else
82         {
83           _bit[a] = false;
84         }
85     }
86 
87   _val = val;
88 }
89 
90 void
activate(int bit_nr)91 FloppyIO::activate(int bit_nr)
92 {
93   switch (bit_nr)
94     {
95     case 0:
96       DBG(2, form("KCemu/FloppyIO/activate",
97                   "FloppyIO::activate(): bit = %d, start processor\n",
98                   bit_nr));
99       z80->start_floppy_cpu();
100       break;
101     case 1:
102       DBG(2, form("KCemu/FloppyIO/activate",
103                   "FloppyIO::activate(): bit = %d, halt processor\n",
104                   bit_nr));
105       z80->halt_floppy_cpu(false);
106       break;
107     case 2:
108       DBG(2, form("KCemu/FloppyIO/activate",
109                   "FloppyIO::activate(): bit = %d, trigger RESET\n",
110                   bit_nr));
111       break;
112     case 3:
113       DBG(2, form("KCemu/FloppyIO/activate",
114                   "FloppyIO::activate(): bit = %d, trigger NMI\n",
115                   bit_nr));
116       break;
117     default:
118       DBG(0, form("KCemu/warning",
119                   "FloppyIO::activate(): bit = %d ???\n",
120                   bit_nr));
121       break;
122     }
123 }
124