1 /*
2  * vic20ieeevia1.c - IEEE488 interface VIA1 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 
42 
ieeevia1_dump(void)43 int ieeevia1_dump(void)
44 {
45     return viacore_dump(machine_context.ieeevia1);
46 }
47 
ieeevia1_store(uint16_t addr,uint8_t data)48 void ieeevia1_store(uint16_t addr, uint8_t data)
49 {
50     viacore_store(machine_context.ieeevia1, addr, data);
51 }
52 
ieeevia1_read(uint16_t addr)53 uint8_t ieeevia1_read(uint16_t addr)
54 {
55     return viacore_read(machine_context.ieeevia1, addr);
56 }
57 
ieeevia1_peek(uint16_t addr)58 uint8_t ieeevia1_peek(uint16_t addr)
59 {
60     return viacore_peek(machine_context.ieeevia1, addr);
61 }
62 
set_ca2(via_context_t * via_context,int state)63 static void set_ca2(via_context_t *via_context, int state)
64 {
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 }
70 
set_int(via_context_t * via_context,unsigned int int_num,int value,CLOCK rclk)71 static void set_int(via_context_t *via_context, unsigned int int_num, int value, CLOCK rclk)
72 {
73     interrupt_set_irq(maincpu_int_status, int_num, value, rclk);
74 }
75 
restore_int(via_context_t * via_context,unsigned int int_num,int value)76 static void restore_int(via_context_t *via_context, unsigned int int_num, int value)
77 {
78     interrupt_restore_irq(maincpu_int_status, int_num, value);
79 }
80 
undump_acr(via_context_t * via_context,uint8_t byte)81 static void undump_acr(via_context_t *via_context, uint8_t byte)
82 {
83 }
84 
store_acr(via_context_t * via_context,uint8_t byte)85 static void store_acr(via_context_t *via_context, uint8_t byte)
86 {
87 }
88 
store_sr(via_context_t * via_context,uint8_t byte)89 static void store_sr(via_context_t *via_context, uint8_t byte)
90 {
91 }
92 
store_t2l(via_context_t * via_context,uint8_t byte)93 static void store_t2l(via_context_t *via_context, uint8_t byte)
94 {
95 }
96 
undump_pra(via_context_t * via_context,uint8_t byte)97 static void undump_pra(via_context_t *via_context, uint8_t byte)
98 {
99 }
100 
store_pra(via_context_t * via_context,uint8_t byte,uint8_t myoldpa,uint16_t addr)101 static void store_pra(via_context_t *via_context, uint8_t byte, uint8_t myoldpa,
102                       uint16_t addr)
103 {
104 }
105 
undump_prb(via_context_t * via_context,uint8_t byte)106 static void undump_prb(via_context_t *via_context, uint8_t byte)
107 {
108     parallel_cpu_set_dav((uint8_t)(!(byte & 0x01)));
109     parallel_cpu_set_nrfd((uint8_t)(!(byte & 0x02)));
110     parallel_cpu_set_ndac((uint8_t)(!(byte & 0x04)));
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     parallel_cpu_set_dav((uint8_t)(!(byte & 0x01)));
117     parallel_cpu_set_nrfd((uint8_t)(!(byte & 0x02)));
118     parallel_cpu_set_ndac((uint8_t)(!(byte & 0x04)));
119 }
120 
undump_pcr(via_context_t * via_context,uint8_t byte)121 static void undump_pcr(via_context_t *via_context, uint8_t byte)
122 {
123 }
124 
reset(via_context_t * via_context)125 static void reset(via_context_t *via_context)
126 {
127     parallel_cpu_set_dav(0);
128     parallel_cpu_set_nrfd(0);
129     parallel_cpu_set_ndac(0);
130 }
131 
store_pcr(via_context_t * via_context,uint8_t byte,uint16_t addr)132 static uint8_t store_pcr(via_context_t *via_context, uint8_t byte, uint16_t addr)
133 {
134     return byte;
135 }
136 
read_pra(via_context_t * via_context,uint16_t addr)137 static uint8_t read_pra(via_context_t *via_context, uint16_t addr)
138 {
139     return 0xff;
140 }
141 
read_prb(via_context_t * via_context)142 static uint8_t read_prb(via_context_t *via_context)
143 {
144     uint8_t byte;
145 
146     drive_cpu_execute_all(maincpu_clk);
147 
148     byte = 255
149            - (parallel_atn ? 0x80 : 0)
150            - (parallel_ndac ? 0x40 : 0)
151            - (parallel_nrfd ? 0x20 : 0)
152            - (parallel_dav ? 0x10 : 0)
153            - (parallel_eoi ? 0x08 : 0);
154 
155     /* none of the load changes output register value -> std. masking */
156     byte = ((byte & ~(via_context->via[VIA_DDRB]))
157             | (via_context->via[VIA_PRB] & via_context->via[VIA_DDRB]));
158     return byte;
159 }
160 
ieeevia1_init(via_context_t * via_context)161 void ieeevia1_init(via_context_t *via_context)
162 {
163     viacore_init(machine_context.ieeevia1, maincpu_alarm_context,
164                  maincpu_int_status, maincpu_clk_guard);
165 }
166 
vic20ieeevia1_setup_context(machine_context_t * machinecontext)167 void vic20ieeevia1_setup_context(machine_context_t *machinecontext)
168 {
169     via_context_t *via;
170 
171     machinecontext->ieeevia1 = lib_malloc(sizeof(via_context_t));
172     via = machinecontext->ieeevia1;
173 
174     via->prv = NULL;
175     via->context = NULL;
176 
177     via->rmw_flag = &maincpu_rmw_flag;
178     via->clk_ptr = &maincpu_clk;
179 
180     via->myname = lib_msprintf("IeeeVia1");
181     via->my_module_name = lib_msprintf("IeeeVia1");
182 
183     viacore_setup_context(via);
184 
185     via->write_offset = 0;
186 
187     via->irq_line = IK_IRQ;
188 
189     via->undump_pra = undump_pra;
190     via->undump_prb = undump_prb;
191     via->undump_pcr = undump_pcr;
192     via->undump_acr = undump_acr;
193     via->store_pra = store_pra;
194     via->store_prb = store_prb;
195     via->store_pcr = store_pcr;
196     via->store_acr = store_acr;
197     via->store_sr = store_sr;
198     via->store_t2l = store_t2l;
199     via->read_pra = read_pra;
200     via->read_prb = read_prb;
201     via->set_int = set_int;
202     via->restore_int = restore_int;
203     via->set_ca2 = set_ca2;
204     via->set_cb2 = set_cb2;
205     via->reset = reset;
206 }
207