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

« back to all changes in this revision

Viewing changes to src/drive/iec/cia1581d.c

  • Committer: Bazaar Package Importer
  • Author(s): Zed Pobre
  • Date: 2005-03-27 13:06:04 UTC
  • mfrom: (4 hoary)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20050327130604-zodmv0i60dbbmcik
Tags: 1.16-3
Apply patch from Andreas Jochens <aj@andaco.de> to correct building on
AMD64 and GCC 4.x (closes: #300936)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * cia1581d.c - Definitions for the MOS6526 (CIA) chip in the 1581
 
3
 * disk drive ($4000).  Notice that the real 1581 uses a 8520 CIA.
 
4
 *
 
5
 * Written by
 
6
 *  Andreas Boose <viceteam@t-online.de>
 
7
 *
 
8
 * This file is part of VICE, the Versatile Commodore Emulator.
 
9
 * See README for copyright notice.
 
10
 *
 
11
 *  This program is free software; you can redistribute it and/or modify
 
12
 *  it under the terms of the GNU General Public License as published by
 
13
 *  the Free Software Foundation; either version 2 of the License, or
 
14
 *  (at your option) any later version.
 
15
 *
 
16
 *  This program is distributed in the hope that it will be useful,
 
17
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
19
 *  GNU General Public License for more details.
 
20
 *
 
21
 *  You should have received a copy of the GNU General Public License
 
22
 *  along with this program; if not, write to the Free Software
 
23
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 
24
 *  02111-1307  USA.
 
25
 *
 
26
 */
 
27
 
 
28
#include "vice.h"
 
29
 
 
30
#include <stdio.h>
 
31
 
 
32
#include "cia.h"
 
33
#include "ciad.h"
 
34
#include "drive.h"
 
35
#include "drivecpu.h"
 
36
#include "drivetypes.h"
 
37
#include "iecbus.h"
 
38
#include "iecdrive.h"
 
39
#include "interrupt.h"
 
40
#include "lib.h"
 
41
#include "log.h"
 
42
#include "types.h"
 
43
#include "wd1770.h"
 
44
 
 
45
 
 
46
typedef struct drivecia1581_context_s {
 
47
    unsigned int number;
 
48
    struct drive_s *drive;
 
49
    struct iecbus_s *iecbus;
 
50
} drivecia1581_context_t;
 
51
 
 
52
 
 
53
void REGPARM3 cia1581_store(drive_context_t *ctxptr, WORD addr, BYTE data)
 
54
{
 
55
    ciacore_store(ctxptr->cia1581, addr, data);
 
56
}
 
57
 
 
58
BYTE REGPARM2 cia1581_read(drive_context_t *ctxptr, WORD addr)
 
59
{
 
60
    return ciacore_read(ctxptr->cia1581, addr);
 
61
}
 
62
 
 
63
BYTE REGPARM2 cia1581_peek(drive_context_t *ctxptr, WORD addr)
 
64
{
 
65
    return ciacore_peek(ctxptr->cia1581, addr);
 
66
}
 
67
 
 
68
static void cia_set_int_clk(cia_context_t *cia_context, int value, CLOCK clk)
 
69
{
 
70
    drive_context_t *drive_context;
 
71
 
 
72
    drive_context = (drive_context_t *)(cia_context->context);
 
73
 
 
74
    interrupt_set_irq(drive_context->cpu->int_status, cia_context->int_num,
 
75
                      value, clk);
 
76
}
 
77
 
 
78
static void cia_restore_int(cia_context_t *cia_context, int value)
 
79
{
 
80
    drive_context_t *drive_context;
 
81
 
 
82
    drive_context = (drive_context_t *)(cia_context->context);
 
83
 
 
84
    interrupt_restore_irq(drive_context->cpu->int_status,
 
85
                            cia_context->int_num, value);
 
86
}
 
87
 
 
88
/*************************************************************************
 
89
 * Hardware binding
 
90
 */
 
91
 
 
92
static void do_reset_cia(cia_context_t *cia_context)
 
93
{
 
94
    drivecia1581_context_t *cia1581p;
 
95
 
 
96
    cia1581p = (drivecia1581_context_t *)(cia_context->prv);
 
97
 
 
98
    cia1581p->drive->led_status = 1;
 
99
}
 
100
 
 
101
static void pulse_ciapc(cia_context_t *cia_context, CLOCK rclk)
 
102
{
 
103
}
 
104
 
 
105
#define PRE_STORE_CIA
 
106
#define PRE_READ_CIA
 
107
#define PRE_PEEK_CIA
 
108
 
 
109
static void undump_ciapa(cia_context_t *cia_context, CLOCK rclk, BYTE b)
 
110
{
 
111
    drivecia1581_context_t *cia1581p;
 
112
 
 
113
    cia1581p = (drivecia1581_context_t *)(cia_context->prv);
 
114
 
 
115
    cia1581p->drive->led_status = (b & 0x40) ? 1 : 0;
 
116
}
 
117
 
 
118
static void undump_ciapb(cia_context_t *cia_context, CLOCK rclk, BYTE b)
 
119
{
 
120
}
 
121
 
 
122
static void store_ciapa(cia_context_t *cia_context, CLOCK rclk, BYTE byte)
 
123
{
 
124
    drivecia1581_context_t *cia1581p;
 
125
 
 
126
    cia1581p = (drivecia1581_context_t *)(cia_context->prv);
 
127
 
 
128
    wd1770[cia1581p->number].side = (byte & 0x01) ? 1 : 0;
 
129
    cia1581p->drive->led_status = (byte & 0x40) ? 1 : 0;
 
130
}
 
131
 
 
132
static void store_ciapb(cia_context_t *cia_context, CLOCK rclk, BYTE byte)
 
133
{
 
134
    drivecia1581_context_t *cia1581p;
 
135
    drive_context_t *drive_context;
 
136
 
 
137
    cia1581p = (drivecia1581_context_t *)(cia_context->prv);
 
138
    drive_context = (drive_context_t *)(cia_context->context);
 
139
 
 
140
    if (byte != cia_context->old_pb) {
 
141
        if (cia1581p->iecbus != NULL) {
 
142
            BYTE *drive_bus, *drive_data;
 
143
            unsigned int unit;
 
144
 
 
145
            drive_bus = &(cia1581p->iecbus->drv_bus[cia1581p->number + 8]);
 
146
            drive_data = &(cia1581p->iecbus->drv_data[cia1581p->number + 8]);
 
147
 
 
148
            *drive_data = ~byte;
 
149
            *drive_bus = ((((*drive_data) << 3) & 0x40)
 
150
                | (((*drive_data) << 6)
 
151
                & (((*drive_data) | cia1581p->iecbus->cpu_bus) << 3) & 0x80));
 
152
 
 
153
            cia1581p->iecbus->cpu_port = cia1581p->iecbus->cpu_bus;
 
154
            for (unit = 4; unit < 8+DRIVE_NUM; unit++)
 
155
                cia1581p->iecbus->cpu_port
 
156
                    &= cia1581p->iecbus->drv_bus[unit];
 
157
 
 
158
            cia1581p->iecbus->drv_port
 
159
                = (((cia1581p->iecbus->cpu_port >> 4) & 0x4)
 
160
                | (cia1581p->iecbus->cpu_port >> 7)
 
161
                | ((cia1581p->iecbus->cpu_bus << 3) & 0x80));
 
162
        } else {
 
163
            iec_drive_write((BYTE)(~byte), cia1581p->number);
 
164
        }
 
165
 
 
166
        iec_fast_drive_direction(byte & 0x20, cia1581p->number);
 
167
    }
 
168
}
 
169
 
 
170
static BYTE read_ciapa(cia_context_t *cia_context)
 
171
{
 
172
    drive_context_t *drive_context;
 
173
    drivecia1581_context_t *cia1581p;
 
174
    BYTE tmp;
 
175
 
 
176
    cia1581p = (drivecia1581_context_t *)(cia_context->prv);
 
177
    drive_context = (drive_context_t *)(cia_context->context);
 
178
 
 
179
    tmp = 8 * (cia1581p->number);
 
180
 
 
181
    if (!wd1770_disk_change(drive_context))
 
182
        tmp |= 0x80;
 
183
 
 
184
    return (tmp & ~(cia_context->c_cia[CIA_DDRA]))
 
185
           | (cia_context->c_cia[CIA_PRA] & cia_context->c_cia[CIA_DDRA]);
 
186
}
 
187
 
 
188
static BYTE read_ciapb(cia_context_t *cia_context)
 
189
{
 
190
    drive_context_t *drive_context;
 
191
    drivecia1581_context_t *cia1581p;
 
192
 
 
193
    cia1581p = (drivecia1581_context_t *)(cia_context->prv);
 
194
    drive_context = (drive_context_t *)(cia_context->context);
 
195
 
 
196
    if (cia1581p->iecbus != NULL) {
 
197
        BYTE *drive_port;
 
198
 
 
199
        drive_port = &(cia1581p->iecbus->drv_port);
 
200
 
 
201
        return (((cia_context->c_cia[CIA_PRB] & 0x1a) | (*drive_port)) ^ 0x85)
 
202
            | (cia1581p->drive->read_only ? 0 : 0x40);
 
203
    } else {
 
204
        return (((cia_context->c_cia[CIA_PRB] & 0x1a)
 
205
            | iec_drive_read(cia1581p->number)) ^ 0x85)
 
206
            | (cia1581p->drive->read_only ? 0 : 0x40);
 
207
    }
 
208
}
 
209
 
 
210
static void read_ciaicr(cia_context_t *cia_context)
 
211
{
 
212
}
 
213
 
 
214
static void read_sdr(cia_context_t *cia_context)
 
215
{
 
216
}
 
217
 
 
218
static void store_sdr(cia_context_t *cia_context, BYTE byte)
 
219
{
 
220
    drivecia1581_context_t *cia1581p;
 
221
 
 
222
    cia1581p = (drivecia1581_context_t *)(cia_context->prv);
 
223
 
 
224
    iec_fast_drive_write(byte, cia1581p->number);
 
225
}
 
226
 
 
227
void cia1581_init(drive_context_t *ctxptr)
 
228
{
 
229
    ciacore_init(ctxptr->cia1581, ctxptr->cpu->alarm_context,
 
230
                 ctxptr->cpu->int_status, ctxptr->cpu->clk_guard);
 
231
}
 
232
 
 
233
void cia1581_setup_context(drive_context_t *ctxptr)
 
234
{
 
235
    drivecia1581_context_t *cia1581p;
 
236
    cia_context_t *cia;
 
237
 
 
238
    ctxptr->cia1581 = lib_calloc(1,sizeof(cia_context_t));
 
239
    cia = ctxptr->cia1581;
 
240
 
 
241
    cia->prv = lib_malloc(sizeof(drivecia1581_context_t));
 
242
    cia1581p = (drivecia1581_context_t *)(cia->prv);
 
243
    cia1581p->number = ctxptr->mynumber;
 
244
 
 
245
    cia->context = (void *)ctxptr;
 
246
 
 
247
    cia->rmw_flag = &(ctxptr->cpu->rmw_flag);
 
248
    cia->clk_ptr = ctxptr->clk_ptr;
 
249
 
 
250
    cia->todticks = 100000;
 
251
 
 
252
    ciacore_setup_context(cia);
 
253
 
 
254
    cia->debugFlag = 0;
 
255
    cia->irq_line = IK_IRQ;
 
256
    cia->myname = lib_msprintf("CIA1581D%d", ctxptr->mynumber);
 
257
 
 
258
    cia1581p->drive = ctxptr->drive;
 
259
    cia1581p->iecbus = iecbus_drive_port();
 
260
 
 
261
    cia->undump_ciapa = undump_ciapa;
 
262
    cia->undump_ciapb = undump_ciapb;
 
263
    cia->store_ciapa = store_ciapa;
 
264
    cia->store_ciapb = store_ciapb;
 
265
    cia->store_sdr = store_sdr;
 
266
    cia->read_ciapa = read_ciapa;
 
267
    cia->read_ciapb = read_ciapb;
 
268
    cia->read_ciaicr = read_ciaicr;
 
269
    cia->read_sdr = read_sdr;
 
270
    cia->cia_set_int_clk = cia_set_int_clk;
 
271
    cia->cia_restore_int = cia_restore_int;
 
272
    cia->do_reset_cia = do_reset_cia;
 
273
    cia->pulse_ciapc = pulse_ciapc;
 
274
    cia->pre_store = NULL;
 
275
    cia->pre_read = NULL;
 
276
    cia->pre_peek = NULL;
 
277
}
 
278