]> Shamusworld >> Repos - virtualjaguar/blob - src/memory.cpp
Initial changeset to experimental branch
[virtualjaguar] / src / memory.cpp
1 //
2 // Jaguar memory and I/O physical (hosted!) memory
3 //
4 // by James L. Hammons
5 //
6 // JLH = James L. Hammons
7 //
8 // WHO  WHEN        WHAT
9 // ---  ----------  -----------------------------------------------------------
10 // JLH  12/10/2009  Repurposed this file. :-)
11 //
12
13 /*
14 $FFFFFF => 16,777,215
15 $A00000 => 10,485,760
16
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...
22
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. :-)
26 */
27
28 #include "memory.h"
29
30 uint8 jagMemSpace[0xF20000];                                    // The entire memory space of the Jaguar...!
31
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];
37
38 uint8 jaguarBootROM[0x040000];                                  // 68K CPU BIOS ROM--uses only half of this!
39 uint8 jaguarCDBootROM[0x040000];                                // 68K CPU CD BIOS ROM (256K)
40
41
42 #if 0
43 union Word
44 {
45         uint16 word;
46         struct {
47                 // This changes depending on endianness...
48 #ifdef __BIG_ENDIAN__
49                 uint8 hi, lo;                                                   // Big endian
50 #else
51                 uint8 lo, hi;                                                   // Little endian
52 #endif
53         };
54 };
55 #endif
56
57 #if 0
58 union DWord
59 {
60         uint32 dword;
61         struct
62         {
63 #ifdef __BIG_ENDIAN__
64                 uint16 hiw, low;
65 #else
66                 uint16 low, hiw;
67 #endif
68         };
69 };
70 #endif
71
72 #if 0
73 static void test(void)
74 {
75         Word reg;
76         reg.word = 0x1234;
77         reg.lo = 0xFF;
78         reg.hi = 0xEE;
79
80         DWord reg2;
81         reg2.hiw = 0xFFFE;
82         reg2.low = 0x3322;
83         reg2.low.lo = 0x11;
84 }
85 #endif
86
87 // OR, we could do like so:
88 #if 0
89 #ifdef __BIG_ENDIAN__
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
94 #else
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
99 #endif
100 // But this starts to get cumbersome after a while... Is union really better?
101
102 //More union stuff...
103 unsigned long ByteSwap1 (unsigned long nLongNumber)
104 {
105    union u {unsigned long vi; unsigned char c[sizeof(unsigned long)];};
106    union v {unsigned long ni; unsigned char d[sizeof(unsigned long)];};
107    union u un;
108    union v vn;
109    un.vi = nLongNumber;
110    vn.d[0]=un.c[3];
111    vn.d[1]=un.c[2];
112    vn.d[2]=un.c[1];
113    vn.d[3]=un.c[0];
114    return (vn.ni);
115 }
116 #endif
117
118 //Not sure if this is a good approach yet...
119 //should be if we use proper aliasing, and htonl and friends...
120 #if 1
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
132 #else
133 uint32 butch, dscntrl, ds_data, i2cntrl, sbcntrl, subdata, subdatb, sb_time, fifo_data, i2sdat2, unknown;
134 #endif
135
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... :-)
139
140 //#define ENDIANSAFE(x) htonl(x)
141
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
145
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
152 #if 0
153 uint16 * memcon1_t = (uint16 *)&jagMemSpace[0xF00000];
154 uint16 & memcon1 = *memcon1_t;
155 #else
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]);
162 #endif
163
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;
173
174 // Memory debugging identifiers
175
176 const char * whoName[9] =
177         { "Unknown", "Jaguar", "DSP", "GPU", "TOM", "JERRY", "M68K", "Blitter", "OP" };
178