2 // Jaguar memory and I/O physical (hosted!) memory
6 // JLH = James L. Hammons
9 // --- ---------- -----------------------------------------------------------
10 // JLH 12/10/2009 Repurposed this file. :-)
17 Really, just six megabytes short of using the entire address space...
18 Why not? We could just allocate the entire space and then use the MMU code to do
19 things like call functions and whatnot...
20 In other words, read/write would just tuck the value into the host RAM space and
21 the I/O function would take care of any weird stuff...
23 Actually: writes would tuck in the value, but reads would have to be handled
24 correctly since some registers do not fall on the same address as far as reading
25 goes... Still completely doable though. :-)
30 uint8 jagMemSpace[0xF20000]; // The entire memory space of the Jaguar...!
32 uint8 * jaguarMainRAM = &jagMemSpace[0x000000];
33 uint8 * jaguarMainROM = &jagMemSpace[0x800000];
34 uint8 * cdRAM = &jagMemSpace[0xDFFF00];
35 uint8 * gpuRAM = &jagMemSpace[0xF03000];
36 uint8 * dspRAM = &jagMemSpace[0xF1B000];
38 uint8 jaguarBootROM[0x040000]; // 68K CPU BIOS ROM--uses only half of this!
39 uint8 jaguarCDBootROM[0x040000]; // 68K CPU CD BIOS ROM (256K)
47 // This changes depending on endianness...
49 uint8 hi, lo; // Big endian
51 uint8 lo, hi; // Little endian
73 static void test(void)
87 // OR, we could do like so:
90 #define DWORD_BYTE_HWORD_H 1
91 #define DWORD_BYTE_HWORD_L 2
92 #define DWORD_BYTE_LWORD_H 3
93 #define DWORD_BYTE_LWORD_L 4
95 #define DWORD_BYTE_HWORD_H 4
96 #define DWORD_BYTE_HWORD_L 3
97 #define DWORD_BYTE_LWORD_H 2
98 #define DWORD_BYTE_LWORD_L 1
100 // But this starts to get cumbersome after a while... Is union really better?
102 //More union stuff...
103 unsigned long ByteSwap1 (unsigned long nLongNumber)
105 union u {unsigned long vi; unsigned char c[sizeof(unsigned long)];};
106 union v {unsigned long ni; unsigned char d[sizeof(unsigned long)];};
118 //Not sure if this is a good approach yet...
119 //should be if we use proper aliasing, and htonl and friends...
121 uint32 & butch = *((uint32 *)&jagMemSpace[0xDFFF00]); // base of Butch == interrupt control register, R/W
122 uint32 & dscntrl = *((uint32 *)&jagMemSpace[0xDFFF04]); // DSA control register, R/W
123 uint16 & ds_data = *((uint16 *)&jagMemSpace[0xDFFF0A]); // DSA TX/RX data, R/W
124 uint32 & i2cntrl = *((uint32 *)&jagMemSpace[0xDFFF10]); // i2s bus control register, R/W
125 uint32 & sbcntrl = *((uint32 *)&jagMemSpace[0xDFFF14]); // CD subcode control register, R/W
126 uint32 & subdata = *((uint32 *)&jagMemSpace[0xDFFF18]); // Subcode data register A
127 uint32 & subdatb = *((uint32 *)&jagMemSpace[0xDFFF1C]); // Subcode data register B
128 uint32 & sb_time = *((uint32 *)&jagMemSpace[0xDFFF20]); // Subcode time and compare enable (D24)
129 uint32 & fifo_data = *((uint32 *)&jagMemSpace[0xDFFF24]); // i2s FIFO data
130 uint32 & i2sdat2 = *((uint32 *)&jagMemSpace[0xDFFF28]); // i2s FIFO data (old)
131 uint32 & unknown = *((uint32 *)&jagMemSpace[0xDFFF2C]); // Seems to be some sort of I2S interface
133 uint32 butch, dscntrl, ds_data, i2cntrl, sbcntrl, subdata, subdatb, sb_time, fifo_data, i2sdat2, unknown;
136 #warning "Need to separate out this stuff (or do we???)"
137 //if we use a contiguous memory space, we don't need this shit...
138 //err, maybe we do, let's not be so hasty now... :-)
140 //#define ENDIANSAFE(x) htonl(x)
142 // The nice thing about doing it this way is that on big endian machines, htons/l
143 // compile to nothing and on Intel machines, it compiles down to a single bswap instruction.
144 // So endianness issues go away nicely without a lot of drama. :-D
146 #define BSWAP16(x) (htons(x))
147 #define BSWAP32(x) (htonl(x))
148 //this isn't endian safe...
149 #define BSWAP64(x) ((htonl(x & 0xFFFFFFFF) << 32) | htonl(x >> 32))
150 // Actually, we use ESAFExx() macros instead of this, and we use GCC to check the endianness...
151 // Acutally, considering that "byteswap.h" doesn't exist elsewhere, the above
152 // is probably our best bet here. Just need to rename them to ESAFExx().
154 uint16 & memcon1 = *((uint16 *)&jagMemSpace[0xF00000]);
155 uint16 & memcon2 = *((uint16 *)&jagMemSpace[0xF00002]);
156 uint16 & hc = *((uint16 *)&jagMemSpace[0xF00004]);
157 uint16 & vc = *((uint16 *)&jagMemSpace[0xF00006]);
158 uint16 & lph = *((uint16 *)&jagMemSpace[0xF00008]);
159 uint16 & lpv = *((uint16 *)&jagMemSpace[0xF0000A]);
160 uint64 & obData = *((uint64 *)&jagMemSpace[0xF00010]);
161 uint32 & olp = *((uint32 *)&jagMemSpace[0xF00020]);
162 uint16 & obf = *((uint16 *)&jagMemSpace[0xF00026]);
163 uint16 & vmode = *((uint16 *)&jagMemSpace[0xF00028]);
164 uint16 & bord1 = *((uint16 *)&jagMemSpace[0xF0002A]);
165 uint16 & bord2 = *((uint16 *)&jagMemSpace[0xF0002C]);
166 uint16 & hp = *((uint16 *)&jagMemSpace[0xF0002E]);
167 uint16 & hbb = *((uint16 *)&jagMemSpace[0xF00030]);
168 uint16 & hbe = *((uint16 *)&jagMemSpace[0xF00032]);
169 uint16 & hs = *((uint16 *)&jagMemSpace[0xF00034]);
170 uint16 & hvs = *((uint16 *)&jagMemSpace[0xF00036]);
171 uint16 & hdb1 = *((uint16 *)&jagMemSpace[0xF00038]);
172 uint16 & hdb2 = *((uint16 *)&jagMemSpace[0xF0003A]);
173 uint16 & hde = *((uint16 *)&jagMemSpace[0xF0003C]);
174 uint16 & vp = *((uint16 *)&jagMemSpace[0xF0003E]);
175 uint16 & vbb = *((uint16 *)&jagMemSpace[0xF00040]);
176 uint16 & vbe = *((uint16 *)&jagMemSpace[0xF00042]);
177 uint16 & vs = *((uint16 *)&jagMemSpace[0xF00044]);
178 uint16 & vdb = *((uint16 *)&jagMemSpace[0xF00046]);
179 uint16 & vde = *((uint16 *)&jagMemSpace[0xF00048]);
180 uint16 & veb = *((uint16 *)&jagMemSpace[0xF0004A]);
181 uint16 & vee = *((uint16 *)&jagMemSpace[0xF0004C]);
182 uint16 & vi = *((uint16 *)&jagMemSpace[0xF0004E]);
183 uint16 & pit0 = *((uint16 *)&jagMemSpace[0xF00050]);
184 uint16 & pit1 = *((uint16 *)&jagMemSpace[0xF00052]);
185 uint16 & heq = *((uint16 *)&jagMemSpace[0xF00054]);
186 uint32 & bg = *((uint32 *)&jagMemSpace[0xF00058]);
187 uint16 & int1 = *((uint16 *)&jagMemSpace[0xF000E0]);
188 uint16 & int2 = *((uint16 *)&jagMemSpace[0xF000E2]);
189 uint8 * clut = (uint8 *) &jagMemSpace[0xF00400];
190 uint8 * lbuf = (uint8 *) &jagMemSpace[0xF00800];
191 uint32 & g_flags = *((uint32 *)&jagMemSpace[0xF02100]);
192 uint32 & g_mtxc = *((uint32 *)&jagMemSpace[0xF02104]);
193 uint32 & g_mtxa = *((uint32 *)&jagMemSpace[0xF02108]);
194 uint32 & g_end = *((uint32 *)&jagMemSpace[0xF0210C]);
195 uint32 & g_pc = *((uint32 *)&jagMemSpace[0xF02110]);
196 uint32 & g_ctrl = *((uint32 *)&jagMemSpace[0xF02114]);
197 uint32 & g_hidata = *((uint32 *)&jagMemSpace[0xF02118]);
198 uint32 & g_divctrl = *((uint32 *)&jagMemSpace[0xF0211C]);
199 uint32 g_remain; // Dual register with $F0211C
200 uint32 & a1_base = *((uint32 *)&jagMemSpace[0xF02200]);
201 uint32 & a1_flags = *((uint32 *)&jagMemSpace[0xF02204]);
202 uint32 & a1_clip = *((uint32 *)&jagMemSpace[0xF02208]);
203 uint32 & a1_pixel = *((uint32 *)&jagMemSpace[0xF0220C]);
204 uint32 & a1_step = *((uint32 *)&jagMemSpace[0xF02210]);
205 uint32 & a1_fstep = *((uint32 *)&jagMemSpace[0xF02214]);
206 uint32 & a1_fpixel = *((uint32 *)&jagMemSpace[0xF02218]);
207 uint32 & a1_inc = *((uint32 *)&jagMemSpace[0xF0221C]);
208 uint32 & a1_finc = *((uint32 *)&jagMemSpace[0xF02220]);
209 uint32 & a2_base = *((uint32 *)&jagMemSpace[0xF02224]);
210 uint32 & a2_flags = *((uint32 *)&jagMemSpace[0xF02228]);
211 uint32 & a2_mask = *((uint32 *)&jagMemSpace[0xF0222C]);
212 uint32 & a2_pixel = *((uint32 *)&jagMemSpace[0xF02230]);
213 uint32 & a2_step = *((uint32 *)&jagMemSpace[0xF02234]);
214 uint32 & b_cmd = *((uint32 *)&jagMemSpace[0xF02238]);
215 uint32 & b_count = *((uint32 *)&jagMemSpace[0xF0223C]);
216 uint64 & b_srcd = *((uint64 *)&jagMemSpace[0xF02240]);
217 uint64 & b_dstd = *((uint64 *)&jagMemSpace[0xF02248]);
218 uint64 & b_dstz = *((uint64 *)&jagMemSpace[0xF02250]);
219 uint64 & b_srcz1 = *((uint64 *)&jagMemSpace[0xF02258]);
220 uint64 & b_srcz2 = *((uint64 *)&jagMemSpace[0xF02260]);
221 uint64 & b_patd = *((uint64 *)&jagMemSpace[0xF02268]);
222 uint32 & b_iinc = *((uint32 *)&jagMemSpace[0xF02270]);
223 uint32 & b_zinc = *((uint32 *)&jagMemSpace[0xF02274]);
224 uint32 & b_stop = *((uint32 *)&jagMemSpace[0xF02278]);
225 uint32 & b_i3 = *((uint32 *)&jagMemSpace[0xF0227C]);
226 uint32 & b_i2 = *((uint32 *)&jagMemSpace[0xF02280]);
227 uint32 & b_i1 = *((uint32 *)&jagMemSpace[0xF02284]);
228 uint32 & b_i0 = *((uint32 *)&jagMemSpace[0xF02288]);
229 uint32 & b_z3 = *((uint32 *)&jagMemSpace[0xF0228C]);
230 uint32 & b_z2 = *((uint32 *)&jagMemSpace[0xF02290]);
231 uint32 & b_z1 = *((uint32 *)&jagMemSpace[0xF02294]);
232 uint32 & b_z0 = *((uint32 *)&jagMemSpace[0xF02298]);
233 uint16 & jpit1 = *((uint16 *)&jagMemSpace[0xF10000]);
234 uint16 & jpit2 = *((uint16 *)&jagMemSpace[0xF10002]);
235 uint16 & jpit3 = *((uint16 *)&jagMemSpace[0xF10004]);
236 uint16 & jpit4 = *((uint16 *)&jagMemSpace[0xF10006]);
237 uint16 & clk1 = *((uint16 *)&jagMemSpace[0xF10010]);
238 uint16 & clk2 = *((uint16 *)&jagMemSpace[0xF10012]);
239 uint16 & clk3 = *((uint16 *)&jagMemSpace[0xF10014]);
240 uint16 & j_int = *((uint16 *)&jagMemSpace[0xF10020]);
241 uint16 & asidata = *((uint16 *)&jagMemSpace[0xF10030]);
242 uint16 & asictrl = *((uint16 *)&jagMemSpace[0xF10032]);
243 uint16 asistat; // Dual register with $F10032
244 uint16 & asiclk = *((uint16 *)&jagMemSpace[0xF10034]);
245 uint16 & joystick = *((uint16 *)&jagMemSpace[0xF14000]);
246 uint16 & joybuts = *((uint16 *)&jagMemSpace[0xF14002]);
247 uint32 & d_flags = *((uint32 *)&jagMemSpace[0xF1A100]);
248 uint32 & d_mtxc = *((uint32 *)&jagMemSpace[0xF1A104]);
249 uint32 & d_mtxa = *((uint32 *)&jagMemSpace[0xF1A108]);
250 uint32 & d_end = *((uint32 *)&jagMemSpace[0xF1A10C]);
251 uint32 & d_pc = *((uint32 *)&jagMemSpace[0xF1A110]);
252 uint32 & d_ctrl = *((uint32 *)&jagMemSpace[0xF1A114]);
253 uint32 & d_mod = *((uint32 *)&jagMemSpace[0xF1A118]);
254 uint32 & d_divctrl = *((uint32 *)&jagMemSpace[0xF1A11C]);
255 uint32 d_remain; // Dual register with $F0211C
256 uint32 & d_machi = *((uint32 *)&jagMemSpace[0xF1A120]);
257 uint16 & ltxd = *((uint16 *)&jagMemSpace[0xF1A148]);
258 uint16 lrxd; // Dual register with $F1A148
259 uint16 & rtxd = *((uint16 *)&jagMemSpace[0xF1A14C]);
260 uint16 rrxd; // Dual register with $F1A14C
261 uint8 & sclk = *((uint8 *) &jagMemSpace[0xF1A150]);
262 uint8 sstat; // Dual register with $F1A150
263 uint32 & smode = *((uint32 *)&jagMemSpace[0xF1A154]);
265 // Memory debugging identifiers
267 const char * whoName[9] =
268 { "Unknown", "Jaguar", "DSP", "GPU", "TOM", "JERRY", "M68K", "Blitter", "OP" };