~ubuntu-branches/ubuntu/quantal/vice/quantal

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
 * c64parallel.c - Parallel cable handling for the C64.
 *
 * Written by
 *  Andreas Boose <viceteam@t-online.de>
 *
 * This file is part of VICE, the Versatile Commodore Emulator.
 * See README for copyright notice.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 *  02111-1307  USA.
 *
 */

#include "vice.h"

#include "c64.h"
#include "c64parallel.h"
#include "cia.h"
#include "drive.h"
#include "drivecpu.h"
#include "drivetypes.h"
#include "iecdrive.h"
#include "maincpu.h"
#include "mc6821.h"
#include "types.h"
#include "via.h"


static BYTE parallel_cable_cpu_value = 0xff;
static BYTE parallel_cable_drive_value[DRIVE_NUM] = { 0xff, 0xff, 0xff, 0xff };


static BYTE parallel_cable_value(void)
{
    unsigned int dnr;
    BYTE val;

    val = parallel_cable_cpu_value;

    for (dnr = 0; dnr < DRIVE_NUM; dnr++) {
        if (drive_context[dnr]->drive->enable
            && drive_context[dnr]->drive->parallel_cable)
            val &= parallel_cable_drive_value[dnr];
    }

    return val;
}

void parallel_cable_drive_write(BYTE data, int handshake, unsigned int dnr)
{
#if 0
    log_debug("DW DATA %02x HS %02x", data, handshake);
#endif

    if (handshake == PARALLEL_WRITE_HS || handshake == PARALLEL_HS)
        ciacore_set_flag(machine_context.cia2);

    if (handshake == PARALLEL_WRITE_HS || handshake == PARALLEL_WRITE)
        parallel_cable_drive_value[dnr] = data;
}

BYTE parallel_cable_drive_read(int handshake)
{
    BYTE rc;

    if (handshake)
        ciacore_set_flag(machine_context.cia2);

    rc = parallel_cable_value();

#if 0
    log_debug("DR DATA %02x HS %02x", rc, handshake);
#endif

    return rc;
}

void parallel_cable_cpu_execute(void)
{
    unsigned int dnr;

    for (dnr = 0; dnr < DRIVE_NUM; dnr++) {
        if (drive_context[dnr]->drive->enable
            && drive_context[dnr]->drive->parallel_cable)
            drivecpu_execute(drive_context[dnr], maincpu_clk);
    }
}

void parallel_cable_cpu_write(BYTE data)
{
    parallel_cable_cpu_execute();

    parallel_cable_cpu_value = data;

#if 0
    log_debug("CW DATA %02x", data);
#endif
}

BYTE parallel_cable_cpu_read(void)
{
    BYTE rc;

    parallel_cable_cpu_execute();

    rc = parallel_cable_value();

#if 0
    log_debug("CR %02x", rc);
#endif

    return rc;
}

void parallel_cable_cpu_pulse(void)
{
    unsigned int dnr;

    parallel_cable_cpu_execute();

#if 0
    log_debug("CP");
#endif

    for (dnr = 0; dnr < DRIVE_NUM; dnr++) {
        drive_t *drive;

        drive = drive_context[dnr]->drive;

        if (drive->enable && drive->parallel_cable) {
            if (drive->parallel_cable == DRIVE_PC_DD3)
                mc6821_set_signal(drive_context[dnr], MC6821_SIG_CA1);
            else if (drive->type == DRIVE_TYPE_1570
                || drive->type == DRIVE_TYPE_1571
                || drive->type == DRIVE_TYPE_1571CR)
                ciacore_set_flag(drive_context[dnr]->cia1571);
            else
                viacore_signal(drive_context[dnr]->via1d1541, VIA_SIG_CB1,
                               VIA_SIG_FALL);
        }
    }
}

void parallel_cable_cpu_undump(BYTE data)
{
    parallel_cable_cpu_value = data;
}