1 //
2 // Jaguar memory and I/O physical (hosted!) memory
3 //
4 // by James Hammons
5 //
6 // JLH = James 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 "vjag_memory.h"
29 
30 uint8_t jagMemSpace[0xF20000];					// The entire memory space of the Jaguar...!
31 
32 uint8_t * jaguarMainRAM = &jagMemSpace[0x000000];
33 uint8_t * jaguarMainROM = &jagMemSpace[0x800000];
34 uint8_t * cdRAM         = &jagMemSpace[0xDFFF00];
35 uint8_t * gpuRAM        = &jagMemSpace[0xF03000];
36 uint8_t * dspRAM        = &jagMemSpace[0xF1B000];
37 
38 //Not sure if this is a good approach yet...
39 //should be if we use proper aliasing, and htonl and friends...
40 uint32_t * butch     = ((uint32_t *)&jagMemSpace[0xDFFF00]);	// base of Butch == interrupt control register, R/W
41 uint32_t * dscntrl   = ((uint32_t *)&jagMemSpace[0xDFFF04]);	// DSA control register, R/W
42 uint16_t * ds_data   = ((uint16_t *)&jagMemSpace[0xDFFF0A]);	// DSA TX/RX data, R/W
43 uint32_t * i2cntrl   = ((uint32_t *)&jagMemSpace[0xDFFF10]);	// i2s bus control register, R/W
44 uint32_t * sbcntrl   = ((uint32_t *)&jagMemSpace[0xDFFF14]);	// CD subcode control register, R/W
45 uint32_t * subdata   = ((uint32_t *)&jagMemSpace[0xDFFF18]);	// Subcode data register A
46 uint32_t * subdatb   = ((uint32_t *)&jagMemSpace[0xDFFF1C]);	// Subcode data register B
47 uint32_t * sb_time   = ((uint32_t *)&jagMemSpace[0xDFFF20]);	// Subcode time and compare enable (D24)
48 uint32_t * fifo_data = ((uint32_t *)&jagMemSpace[0xDFFF24]);	// i2s FIFO data
49 uint32_t * i2sdat2   = ((uint32_t *)&jagMemSpace[0xDFFF28]);	// i2s FIFO data (old)
50 uint32_t * unknown   = ((uint32_t *)&jagMemSpace[0xDFFF2C]);	// Seems to be some sort of I2S interface
51 
52 // The nice thing about doing it this way is that on big endian machines, htons/l
53 // compile to nothing and on Intel machines, it compiles down to a single bswap instruction.
54 // So endianness issues go away nicely without a lot of drama. :-D
55 
56 #define BSWAP16(x) (htons(x))
57 #define BSWAP32(x) (htonl(x))
58 //this isn't endian safe...
59 #define BSWAP64(x) ((htonl(x & 0xFFFFFFFF) << 32) | htonl(x >> 32))
60 
61 uint16_t * memcon1   = ((uint16_t *)&jagMemSpace[0xF00000]);
62 uint16_t * memcon2   = ((uint16_t *)&jagMemSpace[0xF00002]);
63 uint16_t * hc        = ((uint16_t *)&jagMemSpace[0xF00004]);
64 uint16_t * vc        = ((uint16_t *)&jagMemSpace[0xF00006]);
65 uint16_t * lph       = ((uint16_t *)&jagMemSpace[0xF00008]);
66 uint16_t * lpv       = ((uint16_t *)&jagMemSpace[0xF0000A]);
67 uint64_t * obData    = ((uint64_t *)&jagMemSpace[0xF00010]);
68 uint32_t * olp       = ((uint32_t *)&jagMemSpace[0xF00020]);
69 uint16_t * obf       = ((uint16_t *)&jagMemSpace[0xF00026]);
70 uint16_t * vmode     = ((uint16_t *)&jagMemSpace[0xF00028]);
71 uint16_t * bord1     = ((uint16_t *)&jagMemSpace[0xF0002A]);
72 uint16_t * bord2     = ((uint16_t *)&jagMemSpace[0xF0002C]);
73 uint16_t * hp        = ((uint16_t *)&jagMemSpace[0xF0002E]);
74 uint16_t * hbb       = ((uint16_t *)&jagMemSpace[0xF00030]);
75 uint16_t * hbe       = ((uint16_t *)&jagMemSpace[0xF00032]);
76 uint16_t * hs        = ((uint16_t *)&jagMemSpace[0xF00034]);
77 uint16_t * hvs       = ((uint16_t *)&jagMemSpace[0xF00036]);
78 uint16_t * hdb1      = ((uint16_t *)&jagMemSpace[0xF00038]);
79 uint16_t * hdb2      = ((uint16_t *)&jagMemSpace[0xF0003A]);
80 uint16_t * hde       = ((uint16_t *)&jagMemSpace[0xF0003C]);
81 uint16_t * vp        = ((uint16_t *)&jagMemSpace[0xF0003E]);
82 uint16_t * vbb       = ((uint16_t *)&jagMemSpace[0xF00040]);
83 uint16_t * vbe       = ((uint16_t *)&jagMemSpace[0xF00042]);
84 uint16_t * vs        = ((uint16_t *)&jagMemSpace[0xF00044]);
85 uint16_t * vdb       = ((uint16_t *)&jagMemSpace[0xF00046]);
86 uint16_t * vde       = ((uint16_t *)&jagMemSpace[0xF00048]);
87 uint16_t * veb       = ((uint16_t *)&jagMemSpace[0xF0004A]);
88 uint16_t * vee       = ((uint16_t *)&jagMemSpace[0xF0004C]);
89 uint16_t * vi        = ((uint16_t *)&jagMemSpace[0xF0004E]);
90 uint16_t * pit0      = ((uint16_t *)&jagMemSpace[0xF00050]);
91 uint16_t * pit1      = ((uint16_t *)&jagMemSpace[0xF00052]);
92 uint16_t * heq       = ((uint16_t *)&jagMemSpace[0xF00054]);
93 uint32_t * bg        = ((uint32_t *)&jagMemSpace[0xF00058]);
94 uint16_t * int1      = ((uint16_t *)&jagMemSpace[0xF000E0]);
95 uint16_t * int2      = ((uint16_t *)&jagMemSpace[0xF000E2]);
96 uint8_t  * clut      =   (uint8_t *) &jagMemSpace[0xF00400];
97 uint8_t  * lbuf      =   (uint8_t *) &jagMemSpace[0xF00800];
98 uint32_t * g_flags   = ((uint32_t *)&jagMemSpace[0xF02100]);
99 uint32_t * g_mtxc    = ((uint32_t *)&jagMemSpace[0xF02104]);
100 uint32_t * g_mtxa    = ((uint32_t *)&jagMemSpace[0xF02108]);
101 uint32_t * g_end     = ((uint32_t *)&jagMemSpace[0xF0210C]);
102 uint32_t * g_pc      = ((uint32_t *)&jagMemSpace[0xF02110]);
103 uint32_t * g_ctrl    = ((uint32_t *)&jagMemSpace[0xF02114]);
104 uint32_t * g_hidata  = ((uint32_t *)&jagMemSpace[0xF02118]);
105 uint32_t * g_divctrl = ((uint32_t *)&jagMemSpace[0xF0211C]);
106 uint32_t g_remain;								// Dual register with $F0211C
107 uint32_t * a1_base   = ((uint32_t *)&jagMemSpace[0xF02200]);
108 uint32_t * a1_flags  = ((uint32_t *)&jagMemSpace[0xF02204]);
109 uint32_t * a1_clip   = ((uint32_t *)&jagMemSpace[0xF02208]);
110 uint32_t * a1_pixel  = ((uint32_t *)&jagMemSpace[0xF0220C]);
111 uint32_t * a1_step   = ((uint32_t *)&jagMemSpace[0xF02210]);
112 uint32_t * a1_fstep  = ((uint32_t *)&jagMemSpace[0xF02214]);
113 uint32_t * a1_fpixel = ((uint32_t *)&jagMemSpace[0xF02218]);
114 uint32_t * a1_inc    = ((uint32_t *)&jagMemSpace[0xF0221C]);
115 uint32_t * a1_finc   = ((uint32_t *)&jagMemSpace[0xF02220]);
116 uint32_t * a2_base   = ((uint32_t *)&jagMemSpace[0xF02224]);
117 uint32_t * a2_flags  = ((uint32_t *)&jagMemSpace[0xF02228]);
118 uint32_t * a2_mask   = ((uint32_t *)&jagMemSpace[0xF0222C]);
119 uint32_t * a2_pixel  = ((uint32_t *)&jagMemSpace[0xF02230]);
120 uint32_t * a2_step   = ((uint32_t *)&jagMemSpace[0xF02234]);
121 uint32_t * b_cmd     = ((uint32_t *)&jagMemSpace[0xF02238]);
122 uint32_t * b_count   = ((uint32_t *)&jagMemSpace[0xF0223C]);
123 uint64_t * b_srcd    = ((uint64_t *)&jagMemSpace[0xF02240]);
124 uint64_t * b_dstd    = ((uint64_t *)&jagMemSpace[0xF02248]);
125 uint64_t * b_dstz    = ((uint64_t *)&jagMemSpace[0xF02250]);
126 uint64_t * b_srcz1   = ((uint64_t *)&jagMemSpace[0xF02258]);
127 uint64_t * b_srcz2   = ((uint64_t *)&jagMemSpace[0xF02260]);
128 uint64_t * b_patd    = ((uint64_t *)&jagMemSpace[0xF02268]);
129 uint32_t * b_iinc    = ((uint32_t *)&jagMemSpace[0xF02270]);
130 uint32_t * b_zinc    = ((uint32_t *)&jagMemSpace[0xF02274]);
131 uint32_t * b_stop    = ((uint32_t *)&jagMemSpace[0xF02278]);
132 uint32_t * b_i3      = ((uint32_t *)&jagMemSpace[0xF0227C]);
133 uint32_t * b_i2      = ((uint32_t *)&jagMemSpace[0xF02280]);
134 uint32_t * b_i1      = ((uint32_t *)&jagMemSpace[0xF02284]);
135 uint32_t * b_i0      = ((uint32_t *)&jagMemSpace[0xF02288]);
136 uint32_t * b_z3      = ((uint32_t *)&jagMemSpace[0xF0228C]);
137 uint32_t * b_z2      = ((uint32_t *)&jagMemSpace[0xF02290]);
138 uint32_t * b_z1      = ((uint32_t *)&jagMemSpace[0xF02294]);
139 uint32_t * b_z0      = ((uint32_t *)&jagMemSpace[0xF02298]);
140 uint16_t * jpit1     = ((uint16_t *)&jagMemSpace[0xF10000]);
141 uint16_t * jpit2     = ((uint16_t *)&jagMemSpace[0xF10002]);
142 uint16_t * jpit3     = ((uint16_t *)&jagMemSpace[0xF10004]);
143 uint16_t * jpit4     = ((uint16_t *)&jagMemSpace[0xF10006]);
144 uint16_t * clk1      = ((uint16_t *)&jagMemSpace[0xF10010]);
145 uint16_t * clk2      = ((uint16_t *)&jagMemSpace[0xF10012]);
146 uint16_t * clk3      = ((uint16_t *)&jagMemSpace[0xF10014]);
147 uint16_t * j_int     = ((uint16_t *)&jagMemSpace[0xF10020]);
148 uint16_t * asidata   = ((uint16_t *)&jagMemSpace[0xF10030]);
149 uint16_t * asictrl   = ((uint16_t *)&jagMemSpace[0xF10032]);
150 uint16_t asistat;									// Dual register with $F10032
151 uint16_t * asiclk    = ((uint16_t *)&jagMemSpace[0xF10034]);
152 uint16_t * joystick  = ((uint16_t *)&jagMemSpace[0xF14000]);
153 uint16_t * joybuts   = ((uint16_t *)&jagMemSpace[0xF14002]);
154 uint32_t * d_flags   = ((uint32_t *)&jagMemSpace[0xF1A100]);
155 uint32_t * d_mtxc    = ((uint32_t *)&jagMemSpace[0xF1A104]);
156 uint32_t * d_mtxa    = ((uint32_t *)&jagMemSpace[0xF1A108]);
157 uint32_t * d_end     = ((uint32_t *)&jagMemSpace[0xF1A10C]);
158 uint32_t * d_pc      = ((uint32_t *)&jagMemSpace[0xF1A110]);
159 uint32_t * d_ctrl    = ((uint32_t *)&jagMemSpace[0xF1A114]);
160 uint32_t * d_mod     = ((uint32_t *)&jagMemSpace[0xF1A118]);
161 uint32_t * d_divctrl = ((uint32_t *)&jagMemSpace[0xF1A11C]);
162 uint32_t d_remain;								// Dual register with $F0211C
163 uint32_t * d_machi   = ((uint32_t *)&jagMemSpace[0xF1A120]);
164 uint16_t * ltxd      = ((uint16_t *)&jagMemSpace[0xF1A148]);
165 uint16_t lrxd;									// Dual register with $F1A148
166 uint16_t * rtxd      = ((uint16_t *)&jagMemSpace[0xF1A14C]);
167 uint16_t rrxd;									// Dual register with $F1A14C
168 uint8_t  * sclk      = ((uint8_t *) &jagMemSpace[0xF1A150]);
169 uint8_t sstat;									// Dual register with $F1A150
170 uint32_t * smode     = ((uint32_t *)&jagMemSpace[0xF1A154]);
171 
172 // Memory debugging identifiers
173 
174 const char * whoName[10] =
175 	{ "Unknown", "Jaguar", "DSP", "GPU", "TOM", "JERRY", "M68K", "Blitter", "OP", "Debugger" };
176