Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
Ports |
|
| 8.0;8 |
1 | /* |
|
2 | * Ports.java |
|
3 | * |
|
4 | * This file is part of JavaGear. |
|
5 | * |
|
6 | * JavaGear is free software; you can redistribute it and/or modify |
|
7 | * it under the terms of the GNU General Public License as published by |
|
8 | * the Free Software Foundation; either version 2 of the License, or |
|
9 | * (at your option) any later version. |
|
10 | * |
|
11 | * JavaGear is distributed in the hope that it will be useful, |
|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 | * GNU General Public License for more details. |
|
15 | * |
|
16 | * You should have received a copy of the GNU General Public License |
|
17 | * along with JavaGear; if not, write to the Free Software |
|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
19 | */ |
|
20 | ||
21 | package uk.co.javagear; |
|
22 | ||
23 | /** |
|
24 | * A class to attach virtual devices to the Z80's ports. |
|
25 | * |
|
26 | * @author Copyright (C) 2002 Chris White |
|
27 | * @version 6th March 2002 |
|
28 | * @see "JavaGear Final Project Report" |
|
29 | */ |
|
30 | public final class Ports { |
|
31 | /** |
|
32 | * Pointer to VDP. |
|
33 | */ |
|
34 | private Vdp vdp; |
|
35 | ||
36 | /** |
|
37 | * Pointer to Controllers. |
|
38 | */ |
|
39 | private Controllers controllers; |
|
40 | ||
41 | /** |
|
42 | * Pointer to SN76496. |
|
43 | */ |
|
44 | private SN76496 sn76496; |
|
45 | ||
46 | /** |
|
47 | * Nationalization Bit 1. |
|
48 | */ |
|
49 | private int nat1; |
|
50 | ||
51 | /** |
|
52 | * Nationalization Bit 2. |
|
53 | */ |
|
54 | private int nat2; |
|
55 | ||
56 | /** |
|
57 | * European / Domestic System. |
|
58 | */ |
|
59 | private boolean europe; |
|
60 | ||
61 | /** |
|
62 | * Ports Constructor. |
|
63 | * |
|
64 | * @param v Vdp |
|
65 | * @param c Controllers |
|
66 | * @param s SN76496 |
|
67 | */ |
|
68 | 0 | public Ports(Vdp v, Controllers c, SN76496 s) { |
69 | 0 | this.controllers = c; |
70 | 0 | this.vdp = v; |
71 | 0 | sn76496 = s; |
72 | // Reset Nationalization Bits |
|
73 | 0 | nat1 = 0; |
74 | 0 | nat2 = 0; |
75 | // Default to a European System |
|
76 | 0 | europe = true; |
77 | 0 | } |
78 | ||
79 | /** |
|
80 | * Output to a Z80 port. |
|
81 | * |
|
82 | * @param port Port Number |
|
83 | * @param value Value to Output |
|
84 | */ |
|
85 | public void out(int port, int value) { |
|
86 | 0 | switch(port) { |
87 | // GG Serial Ports |
|
88 | case 0x00: |
|
89 | case 0x01: |
|
90 | case 0x02: |
|
91 | case 0x03: |
|
92 | case 0x04: |
|
93 | case 0x05: |
|
94 | 0 | break; |
95 | // VDP Data port |
|
96 | case 0xBE: |
|
97 | 0 | vdp.dataWrite(value); |
98 | 0 | break; |
99 | // VDP Control port (Mirrored at two locations) |
|
100 | case 0xBD: |
|
101 | case 0xBF: |
|
102 | 0 | vdp.controlWrite(value); |
103 | 0 | break; |
104 | // Automatic Nationalization |
|
105 | case 0x3F: |
|
106 | 0 | nat1 = ((value & 0x20) == 0x20) ? 1 : 0; |
107 | 0 | nat2 = ((value & 0x80) == 0x80) ? 1 : 0; |
108 | ||
109 | 0 | if (!europe) { |
110 | 0 | nat1 = ~nat1; |
111 | 0 | nat2 = ~nat2; |
112 | } |
|
113 | break; |
|
114 | // SN76489 PSG Output (Mirrored) |
|
115 | case 0x7E: |
|
116 | case 0x7F: |
|
117 | 0 | sn76496.write(value); |
118 | 0 | break; |
119 | default: |
|
120 | break; |
|
121 | } |
|
122 | 0 | } |
123 | ||
124 | /** |
|
125 | * Read from a Z80 Port. |
|
126 | * |
|
127 | * @param port Port Number |
|
128 | * |
|
129 | * @return Value from Port Number |
|
130 | */ |
|
131 | public int in(int port) { |
|
132 | 0 | int value = 0; |
133 | ||
134 | 0 | switch(port) { |
135 | // GameGear (Start Button and Nationalization) |
|
136 | case 0x00: |
|
137 | 0 | value = controllers.getGameGearStart(); |
138 | 0 | value = europe ? (value | 0x40) : (value & ~0x40); |
139 | 0 | break; |
140 | // GG Serial Communication Ports - |
|
141 | // Return 0 for now as "OutRun" gets stuck in a loop by returning 0xFF |
|
142 | case 0x01: |
|
143 | case 0x02: |
|
144 | case 0x03: |
|
145 | case 0x04: |
|
146 | case 0x05: |
|
147 | 0 | value = 0; |
148 | 0 | break; |
149 | // Controller 1 (mirrored) |
|
150 | case 0xC0: |
|
151 | case 0xDC: |
|
152 | 0 | value = controllers.getController1(); |
153 | 0 | break; |
154 | // Controller 2 (mirrored) and Nationalization |
|
155 | case 0xC1: |
|
156 | case 0xDD: |
|
157 | 0 | value = controllers.getController2(); |
158 | // Reads bits 6 and 7 to determine nationalization |
|
159 | 0 | value = (nat1 == 1) ? (value | 0x40) : (value & ~0x40); |
160 | 0 | value = (nat2 == 1) ? (value | 0x80) : (value & ~0x80); |
161 | 0 | break; |
162 | // Vertical Port |
|
163 | case 0x7E: |
|
164 | 0 | value = vdp.getVCount(); |
165 | 0 | break; |
166 | // Horizontal Port (NOT EMULATED) |
|
167 | case 0x7F: |
|
168 | //System.out.println("Read to horizontal port"); |
|
169 | 0 | break; |
170 | // VDP Data port |
|
171 | case 0xBE: |
|
172 | 0 | value = vdp.dataRead(); |
173 | 0 | break; |
174 | // VDP Control port |
|
175 | case 0xBD: |
|
176 | case 0xBF: |
|
177 | 0 | value = vdp.controlRead(); |
178 | 0 | break; |
179 | // Default Value is 0xFF |
|
180 | default: |
|
181 | 0 | value = 0xff; |
182 | break; |
|
183 | } |
|
184 | ||
185 | 0 | return value; |
186 | } |
|
187 | ||
188 | /** |
|
189 | * Set Console to European / Japanese Model. |
|
190 | * |
|
191 | * @param value True is European, False is Japanese |
|
192 | */ |
|
193 | public void setEurope(boolean value) { |
|
194 | 0 | europe = value; |
195 | 0 | } |
196 | ||
197 | } |