1 /*
2 * vic20ieeevia2.c - IEEE488 interface VIA2 emulation in the VIC-1112.
3 *
4 * Written by
5 * Andre Fachat <a.fachat@physik.tu-chemnitz.de>
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 "drive.h"
33 #include "interrupt.h"
34 #include "lib.h"
35 #include "maincpu.h"
36 #include "parallel.h"
37 #include "types.h"
38 #include "via.h"
39 #include "vic20.h"
40 #include "vic20ieeevia.h"
41
ieeevia2_dump(void)42 int ieeevia2_dump(void)
43 {
44 return viacore_dump(machine_context.ieeevia2);
45 }
46
ieeevia2_store(uint16_t addr,uint8_t data)47 void ieeevia2_store(uint16_t addr, uint8_t data)
48 {
49 viacore_store(machine_context.ieeevia2, addr, data);
50 }
51
ieeevia2_read(uint16_t addr)52 uint8_t ieeevia2_read(uint16_t addr)
53 {
54 return viacore_read(machine_context.ieeevia2, addr);
55 }
56
ieeevia2_peek(uint16_t addr)57 uint8_t ieeevia2_peek(uint16_t addr)
58 {
59 return viacore_peek(machine_context.ieeevia2, addr);
60 }
61
set_ca2(via_context_t * via_context,int state)62 static void set_ca2(via_context_t *via_context, int state)
63 {
64 parallel_cpu_set_atn((char)(state ? 0 : 1));
65 }
66
set_cb2(via_context_t * via_context,int state)67 static void set_cb2(via_context_t *via_context, int state)
68 {
69 parallel_cpu_set_eoi((uint8_t)(state ? 0 : 1));
70 }
71
set_int(via_context_t * via_context,unsigned int int_num,int value,CLOCK rclk)72 static void set_int(via_context_t *via_context, unsigned int int_num, int value, CLOCK rclk)
73 {
74 interrupt_set_irq(maincpu_int_status, int_num, value, rclk);
75 }
76
restore_int(via_context_t * via_context,unsigned int int_num,int value)77 static void restore_int(via_context_t *via_context, unsigned int int_num, int value)
78 {
79 interrupt_restore_irq(maincpu_int_status, int_num, value);
80 }
81
undump_acr(via_context_t * via_context,uint8_t byte)82 static void undump_acr(via_context_t *via_context, uint8_t byte)
83 {
84 }
85
store_acr(via_context_t * via_context,uint8_t byte)86 static void store_acr(via_context_t *via_context, uint8_t byte)
87 {
88 }
89
store_sr(via_context_t * via_context,uint8_t byte)90 static void store_sr(via_context_t *via_context, uint8_t byte)
91 {
92 }
93
store_t2l(via_context_t * via_context,uint8_t byte)94 static void store_t2l(via_context_t *via_context, uint8_t byte)
95 {
96 }
97
undump_pra(via_context_t * via_context,uint8_t byte)98 static void undump_pra(via_context_t *via_context, uint8_t byte)
99 {
100 parallel_cpu_set_bus(byte);
101 }
102
store_pra(via_context_t * via_context,uint8_t byte,uint8_t myoldpa,uint16_t addr)103 static void store_pra(via_context_t *via_context, uint8_t byte, uint8_t myoldpa,
104 uint16_t addr)
105 {
106 parallel_cpu_set_bus(byte);
107 }
108
undump_prb(via_context_t * via_context,uint8_t byte)109 static void undump_prb(via_context_t *via_context, uint8_t byte)
110 {
111 }
112
store_prb(via_context_t * via_context,uint8_t byte,uint8_t myoldpb,uint16_t addr)113 static void store_prb(via_context_t *via_context, uint8_t byte, uint8_t myoldpb,
114 uint16_t addr)
115 {
116 }
117
undump_pcr(via_context_t * via_context,uint8_t byte)118 static void undump_pcr(via_context_t *via_context, uint8_t byte)
119 {
120 }
121
reset(via_context_t * via_context)122 static void reset(via_context_t *via_context)
123 {
124 parallel_cpu_set_bus(0xff); /* all data lines high, because of input mode */
125 }
126
store_pcr(via_context_t * via_context,uint8_t byte,uint16_t addr)127 static uint8_t store_pcr(via_context_t *via_context, uint8_t byte, uint16_t addr)
128 {
129 #if 0
130 if (byte != via_context->via[VIA_PCR]) {
131 register uint8_t tmp = byte;
132 /* first set bit 1 and 5 to the real output values */
133 if ((tmp & 0x0c) != 0x0c) {
134 tmp |= 0x02;
135 }
136 if ((tmp & 0xc0) != 0xc0) {
137 tmp |= 0x20;
138 }
139 parallel_cpu_set_atn((byte & 2) ? 0 : 1);
140 parallel_cpu_set_eoi((byte & 0x20) ? 0 : 1);
141 }
142 #endif
143 return byte;
144 }
145
read_prb(via_context_t * via_context)146 static uint8_t read_prb(via_context_t *via_context)
147 {
148 uint8_t byte;
149
150 drive_cpu_execute_all(maincpu_clk);
151
152 byte = (parallel_bus & ~(via_context->via[VIA_DDRB]))
153 | (via_context->via[VIA_PRB] & via_context->via[VIA_DDRB]);
154 return byte;
155 }
156
read_pra(via_context_t * via_context,uint16_t addr)157 static uint8_t read_pra(via_context_t *via_context, uint16_t addr)
158 {
159 return 0xff;
160 }
161
ieeevia2_init(via_context_t * via_context)162 void ieeevia2_init(via_context_t *via_context)
163 {
164 viacore_init(machine_context.ieeevia2, maincpu_alarm_context,
165 maincpu_int_status, maincpu_clk_guard);
166 }
167
vic20ieeevia2_setup_context(machine_context_t * machinecontext)168 void vic20ieeevia2_setup_context(machine_context_t *machinecontext)
169 {
170 via_context_t *via;
171
172 machinecontext->ieeevia2 = lib_malloc(sizeof(via_context_t));
173 via = machinecontext->ieeevia2;
174
175 via->prv = NULL;
176 via->context = NULL;
177
178 via->rmw_flag = &maincpu_rmw_flag;
179 via->clk_ptr = &maincpu_clk;
180
181 via->myname = lib_msprintf("IeeeVia2");
182 via->my_module_name = lib_msprintf("IeeeVia2");
183
184 viacore_setup_context(via);
185
186 via->write_offset = 0;
187
188 via->irq_line = IK_IRQ;
189
190 via->undump_pra = undump_pra;
191 via->undump_prb = undump_prb;
192 via->undump_pcr = undump_pcr;
193 via->undump_acr = undump_acr;
194 via->store_pra = store_pra;
195 via->store_prb = store_prb;
196 via->store_pcr = store_pcr;
197 via->store_acr = store_acr;
198 via->store_sr = store_sr;
199 via->store_t2l = store_t2l;
200 via->read_pra = read_pra;
201 via->read_prb = read_prb;
202 via->set_int = set_int;
203 via->restore_int = restore_int;
204 via->set_ca2 = set_ca2;
205 via->set_cb2 = set_cb2;
206 via->reset = reset;
207 }
208