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...
153 uint16 * memcon1_t = (uint16 *)&jagMemSpace[0xF00000];
154 uint16 & memcon1 = *memcon1_t;
156 uint16 & memcon1 = *((uint16 *)&jagMemSpace[0xF00000]);
157 uint16 & memcon2 = *((uint16 *)&jagMemSpace[0xF00002]);
158 uint16 & hc = *((uint16 *)&jagMemSpace[0xF00004]);
159 uint16 & vc = *((uint16 *)&jagMemSpace[0xF00006]);
160 uint16 & lph = *((uint16 *)&jagMemSpace[0xF00008]);
161 uint16 & lpv = *((uint16 *)&jagMemSpace[0xF0000A]);
164 uint32 obData, olp, obf, vmode, bord1, bord2, hp, hbb, hbe, hs, hvs,
165 hdb1, hdb2, hde, vp, vbb, vbe, vs, vdb, vde, veb, vee, vi, pit0, pit1, heq, bg, int1, int2, clut, lbuf,
166 g_flags, g_mtxc, g_mtxa, g_end, g_pc, g_ctrl, g_hidata, g_remain, g_divctrl,
167 a1_base, a1_pixel, a1_flags, a1_clip, a1_step, a1_fstep, a1_fpixel, a1_inc, a1_finc,
168 a2_base, a2_flags, a2_pixel, a2_mask, a2_step, b_cmd, b_count, b_srcd, b_dstd, b_dstz, b_srcz1, b_srcz2,
169 b_patd, b_iinc, b_zinc, b_stop, b_i3, b_i2, b_i1, b_i0, b_z3, b_z2, b_z1, b_z0,
170 jpit1, jpit2, jpit3, jpit4, clk1, clk2, clk3, j_int, asidata, asistat, asictrl, asiclk, joystick,
171 joybuts, d_flags, d_mtxc, d_mtxa, d_end, d_pc, d_ctrl, d_mod, d_remain, d_divctrl, d_machi,
172 ltxd, rtxd, sstat, sclk, smode;
174 // Memory debugging identifiers
176 const char * whoName[9] =
177 { "Unknown", "Jaguar", "DSP", "GPU", "TOM", "JERRY", "M68K", "Blitter", "OP" };