| Previous | 15994 Revisions | Next |
| r5770 Thursday 17th September, 2009 at 16:29:33 UTC by Fabio Priuli |
|---|
| Ported Capcom CX4 implementation over from bsnes (original code by zsKnight, anomie and Nach). Mega Man X2 and X3 are now playable, with bugs. [Harmony] |
| [src/mame/machine] | cx4data.c* cx4fn.c* cx4oam.c* cx4ops.c* snes.c snescx4.c* snescx4.h* |
| [src/mess] | mess.mak |
| r0 | r5770 | |
|---|---|---|
| 1 | /*************************************************************************** | |
| 2 | ||
| 3 | cx4ops.c | |
| 4 | ||
| 5 | Code based on original work by zsKnight, anomie and Nach. | |
| 6 | This implementation is based on C++ "cx4*.cpp" by byuu | |
| 7 | (up to date with source v 0.49). | |
| 8 | ||
| 9 | ***************************************************************************/ | |
| 10 | ||
| 11 | //Sprite Functions | |
| 12 | void CX4_op00(running_machine* machine) | |
| 13 | { | |
| 14 | switch(cx4.reg[0x4d]) | |
| 15 | { | |
| 16 | case 0x00: CX4_op00_00(machine); break; | |
| 17 | case 0x03: CX4_op00_03(); break; | |
| 18 | case 0x05: CX4_op00_05(machine); break; | |
| 19 | case 0x07: CX4_op00_07(); break; | |
| 20 | case 0x08: CX4_op00_08(machine); break; | |
| 21 | case 0x0b: CX4_op00_0b(machine); break; | |
| 22 | case 0x0c: CX4_op00_0c(machine); break; | |
| 23 | } | |
| 24 | } | |
| 25 | ||
| 26 | //Draw Wireframe | |
| 27 | void CX4_op01(running_machine* machine) | |
| 28 | { | |
| 29 | memset(cx4.ram + 0x300, 0, 2304); | |
| 30 | CX4_C4DrawWireFrame(machine); | |
| 31 | } | |
| 32 | ||
| 33 | //Propulsion | |
| 34 | void CX4_op05(running_machine *machine) | |
| 35 | { | |
| 36 | INT32 temp = 0x10000; | |
| 37 | if(CX4_readw(0x1f83)) | |
| 38 | { | |
| 39 | temp = CX4_sar((temp / CX4_readw(0x1f83)) * CX4_readw(0x1f81), 8); | |
| 40 | } | |
| 41 | CX4_writew(machine, 0x1f80, temp); | |
| 42 | } | |
| 43 | ||
| 44 | //Set Vector length | |
| 45 | void CX4_op0d(running_machine *machine) | |
| 46 | { | |
| 47 | cx4.C41FXVal = CX4_readw(0x1f80); | |
| 48 | cx4.C41FYVal = CX4_readw(0x1f83); | |
| 49 | cx4.C41FDistVal = CX4_readw(0x1f86); | |
| 50 | cx4.tanval = sqrt(((double)cx4.C41FYVal) * ((double)cx4.C41FYVal) + ((double)cx4.C41FXVal) * ((double)cx4.C41FXVal)); | |
| 51 | cx4.tanval = (double)cx4.C41FDistVal / cx4.tanval; | |
| 52 | cx4.C41FYVal = (INT16)(((double)cx4.C41FYVal * cx4.tanval) * 0.99); | |
| 53 | cx4.C41FXVal = (INT16)(((double)cx4.C41FXVal * cx4.tanval) * 0.98); | |
| 54 | CX4_writew(machine, 0x1f89, cx4.C41FXVal); | |
| 55 | CX4_writew(machine, 0x1f8c, cx4.C41FYVal); | |
| 56 | } | |
| 57 | ||
| 58 | //Triangle | |
| 59 | void CX4_op10() | |
| 60 | { | |
| 61 | cx4.r0 = CX4_ldr(0); | |
| 62 | cx4.r1 = CX4_ldr(1); | |
| 63 | ||
| 64 | cx4.r4 = cx4.r0 & 0x1ff; | |
| 65 | if(cx4.r1 & 0x8000) | |
| 66 | { | |
| 67 | cx4.r1 |= ~0x7fff; | |
| 68 | } | |
| 69 | ||
| 70 | CX4_mul(CX4_cos(cx4.r4), cx4.r1, &cx4.r5, &cx4.r2); | |
| 71 | cx4.r5 = (cx4.r5 >> 16) & 0xff; | |
| 72 | cx4.r2 = (cx4.r2 << 8) + cx4.r5; | |
| 73 | ||
| 74 | CX4_mul(CX4_sin(cx4.r4), cx4.r1, &cx4.r5, &cx4.r3); | |
| 75 | cx4.r5 = (cx4.r5 >> 16) & 0xff; | |
| 76 | cx4.r3 = (cx4.r3 << 8) + cx4.r5; | |
| 77 | ||
| 78 | CX4_str(0, cx4.r0); | |
| 79 | CX4_str(1, cx4.r1); | |
| 80 | CX4_str(2, cx4.r2); | |
| 81 | CX4_str(3, cx4.r3); | |
| 82 | CX4_str(4, cx4.r4); | |
| 83 | CX4_str(5, cx4.r5); | |
| 84 | } | |
| 85 | ||
| 86 | //Triangle | |
| 87 | void CX4_op13() | |
| 88 | { | |
| 89 | cx4.r0 = CX4_ldr(0); | |
| 90 | cx4.r1 = CX4_ldr(1); | |
| 91 | ||
| 92 | cx4.r4 = cx4.r0 & 0x1ff; | |
| 93 | ||
| 94 | CX4_mul(CX4_cos(cx4.r4), cx4.r1, &cx4.r5, &cx4.r2); | |
| 95 | cx4.r5 = (cx4.r5 >> 8) & 0xffff; | |
| 96 | cx4.r2 = (cx4.r2 << 16) + cx4.r5; | |
| 97 | ||
| 98 | CX4_mul(CX4_sin(cx4.r4), cx4.r1, &cx4.r5, &cx4.r3); | |
| 99 | cx4.r5 = (cx4.r5 >> 8) & 0xffff; | |
| 100 | cx4.r3 = (cx4.r3 << 16) + cx4.r5; | |
| 101 | ||
| 102 | CX4_str(0, cx4.r0); | |
| 103 | CX4_str(1, cx4.r1); | |
| 104 | CX4_str(2, cx4.r2); | |
| 105 | CX4_str(3, cx4.r3); | |
| 106 | CX4_str(4, cx4.r4); | |
| 107 | CX4_str(5, cx4.r5); | |
| 108 | } | |
| 109 | ||
| 110 | //Pythagorean | |
| 111 | void CX4_op15(running_machine *machine) | |
| 112 | { | |
| 113 | double temp = 0.0; | |
| 114 | cx4.C41FXVal = CX4_readw(0x1f80); | |
| 115 | cx4.C41FYVal = CX4_readw(0x1f83); | |
| 116 | temp = sqrt((double)cx4.C41FXVal * (double)cx4.C41FXVal + (double)cx4.C41FYVal * (double)cx4.C41FYVal); | |
| 117 | cx4.C41FDist = (INT16)temp; | |
| 118 | CX4_writew(machine, 0x1f80, cx4.C41FDist); | |
| 119 | } | |
| 120 | ||
| 121 | //Calculate distance | |
| 122 | void CX4_op1f(running_machine *machine) | |
| 123 | { | |
| 124 | cx4.C41FXVal = CX4_readw(0x1f80); | |
| 125 | cx4.C41FYVal = CX4_readw(0x1f83); | |
| 126 | if(!cx4.C41FXVal) | |
| 127 | { | |
| 128 | cx4.C41FAngleRes = (cx4.C41FYVal > 0) ? 0x080 : 0x180; | |
| 129 | } | |
| 130 | else | |
| 131 | { | |
| 132 | cx4.tanval = ((double)cx4.C41FYVal) / ((double)cx4.C41FXVal); | |
| 133 | cx4.C41FAngleRes = (INT16)(atan(cx4.tanval) / (PI * 2) * 512); | |
| 134 | cx4.C41FAngleRes = cx4.C41FAngleRes; | |
| 135 | if(cx4.C41FXVal < 0) | |
| 136 | { | |
| 137 | cx4.C41FAngleRes += 0x100; | |
| 138 | } | |
| 139 | cx4.C41FAngleRes &= 0x1ff; | |
| 140 | } | |
| 141 | CX4_writew(machine, 0x1f86, cx4.C41FAngleRes); | |
| 142 | } | |
| 143 | ||
| 144 | //Trapezoid | |
| 145 | void CX4_op22() | |
| 146 | { | |
| 147 | INT16 angle1 = CX4_readw(0x1f8c) & 0x1ff; | |
| 148 | INT16 angle2 = CX4_readw(0x1f8f) & 0x1ff; | |
| 149 | INT32 tan1 = CX4_Tan(angle1); | |
| 150 | INT32 tan2 = CX4_Tan(angle2); | |
| 151 | INT16 y = CX4_readw(0x1f83) - CX4_readw(0x1f89); | |
| 152 | INT16 left, right; | |
| 153 | INT32 j; | |
| 154 | ||
| 155 | for(j = 0; j < 225; j++, y++) | |
| 156 | { | |
| 157 | if(y >= 0) | |
| 158 | { | |
| 159 | left = CX4_sar((INT32)tan1 * y, 16) - CX4_readw(0x1f80) + CX4_readw(0x1f86); | |
| 160 | right = CX4_sar((INT32)tan2 * y, 16) - CX4_readw(0x1f80) + CX4_readw(0x1f86) + CX4_readw(0x1f93); | |
| 161 | ||
| 162 | if(left < 0 && right < 0) | |
| 163 | { | |
| 164 | left = 1; | |
| 165 | right = 0; | |
| 166 | } | |
| 167 | else if(left < 0) | |
| 168 | { | |
| 169 | left = 0; | |
| 170 | } | |
| 171 | else if(right < 0) | |
| 172 | { | |
| 173 | right = 0; | |
| 174 | } | |
| 175 | ||
| 176 | if(left > 255 && right > 255) | |
| 177 | { | |
| 178 | left = 255; | |
| 179 | right = 254; | |
| 180 | } | |
| 181 | else if(left > 255) | |
| 182 | { | |
| 183 | left = 255; | |
| 184 | } | |
| 185 | else if(right > 255) | |
| 186 | { | |
| 187 | right = 255; | |
| 188 | } | |
| 189 | } | |
| 190 | else | |
| 191 | { | |
| 192 | left = 1; | |
| 193 | right = 0; | |
| 194 | } | |
| 195 | cx4.ram[j + 0x800] = (UINT8)left; | |
| 196 | cx4.ram[j + 0x900] = (UINT8)right; | |
| 197 | } | |
| 198 | } | |
| 199 | ||
| 200 | //Multiply | |
| 201 | void CX4_op25() | |
| 202 | { | |
| 203 | cx4.r0 = CX4_ldr(0); | |
| 204 | cx4.r1 = CX4_ldr(1); | |
| 205 | CX4_mul(cx4.r0, cx4.r1, &cx4.r0, &cx4.r1); | |
| 206 | CX4_str(0, cx4.r0); | |
| 207 | CX4_str(1, cx4.r1); | |
| 208 | } | |
| 209 | ||
| 210 | //Transform Coords | |
| 211 | void CX4_op2d(running_machine *machine) | |
| 212 | { | |
| 213 | cx4.C4WFXVal = CX4_readw(0x1f81); | |
| 214 | cx4.C4WFYVal = CX4_readw(0x1f84); | |
| 215 | cx4.C4WFZVal = CX4_readw(0x1f87); | |
| 216 | cx4.C4WFX2Val = CX4_read (0x1f89); | |
| 217 | cx4.C4WFY2Val = CX4_read (0x1f8a); | |
| 218 | cx4.C4WFDist = CX4_read (0x1f8b); | |
| 219 | cx4.C4WFScale = CX4_readw(0x1f90); | |
| 220 | CX4_C4TransfWireFrame2(); | |
| 221 | CX4_writew(machine, 0x1f80, cx4.C4WFXVal); | |
| 222 | CX4_writew(machine, 0x1f83, cx4.C4WFYVal); | |
| 223 | } | |
| 224 | ||
| 225 | //Sum | |
| 226 | void CX4_op40() | |
| 227 | { | |
| 228 | UINT32 i; | |
| 229 | cx4.r0 = 0; | |
| 230 | for(i=0;i<0x800;i++) | |
| 231 | { | |
| 232 | cx4.r0 += cx4.ram[i]; | |
| 233 | } | |
| 234 | CX4_str(0, cx4.r0); | |
| 235 | } | |
| 236 | ||
| 237 | //Square | |
| 238 | void CX4_op54() | |
| 239 | { | |
| 240 | cx4.r0 = CX4_ldr(0); | |
| 241 | CX4_mul(cx4.r0, cx4.r0, &cx4.r1, &cx4.r2); | |
| 242 | CX4_str(1, cx4.r1); | |
| 243 | CX4_str(2, cx4.r2); | |
| 244 | } | |
| 245 | ||
| 246 | //Immediate Register | |
| 247 | void CX4_op5c() | |
| 248 | { | |
| 249 | CX4_str(0, 0x000000); | |
| 250 | CX4_immediate_reg(0); | |
| 251 | } | |
| 252 | ||
| 253 | //Immediate Register (Multiple) | |
| 254 | void CX4_op5e() { CX4_immediate_reg( 0); } | |
| 255 | void CX4_op60() { CX4_immediate_reg( 3); } | |
| 256 | void CX4_op62() { CX4_immediate_reg( 6); } | |
| 257 | void CX4_op64() { CX4_immediate_reg( 9); } | |
| 258 | void CX4_op66() { CX4_immediate_reg(12); } | |
| 259 | void CX4_op68() { CX4_immediate_reg(15); } | |
| 260 | void CX4_op6a() { CX4_immediate_reg(18); } | |
| 261 | void CX4_op6c() { CX4_immediate_reg(21); } | |
| 262 | void CX4_op6e() { CX4_immediate_reg(24); } | |
| 263 | void CX4_op70() { CX4_immediate_reg(27); } | |
| 264 | void CX4_op72() { CX4_immediate_reg(30); } | |
| 265 | void CX4_op74() { CX4_immediate_reg(33); } | |
| 266 | void CX4_op76() { CX4_immediate_reg(36); } | |
| 267 | void CX4_op78() { CX4_immediate_reg(39); } | |
| 268 | void CX4_op7a() { CX4_immediate_reg(42); } | |
| 269 | void CX4_op7c() { CX4_immediate_reg(45); } | |
| 270 | ||
| 271 | //Immediate ROM | |
| 272 | void CX4_op89() | |
| 273 | { | |
| 274 | CX4_str(0, 0x054336); | |
| 275 | CX4_str(1, 0xffffff); | |
| 276 | } |
| r0 | r5770 | |
|---|---|---|
| 1 | /*************************************************************************** | |
| 2 | ||
| 3 | cx4fn.c | |
| 4 | ||
| 5 | Code based on original work by zsKnight, anomie and Nach. | |
| 6 | This implementation is based on C++ "cx4*.cpp" by byuu | |
| 7 | (up to date with source v 0.49). | |
| 8 | ||
| 9 | ***************************************************************************/ | |
| 10 | ||
| 11 | #include <math.h> | |
| 12 | #define CX4_Tan(a) (CX4_CosTable[a] ? ((((INT32)CX4_SinTable[a]) << 16) / CX4_CosTable[a]) : 0x80000000) | |
| 13 | #define CX4_sar(b, n) ((b) >> (n)) | |
| 14 | #ifdef PI | |
| 15 | #undef PI | |
| 16 | #endif | |
| 17 | #define PI 3.1415926535897932384626433832795 | |
| 18 | ||
| 19 | //Wireframe Helpers | |
| 20 | void CX4_C4TransfWireFrame(void) | |
| 21 | { | |
| 22 | cx4.c4x = (double)cx4.C4WFXVal; | |
| 23 | cx4.c4y = (double)cx4.C4WFYVal; | |
| 24 | cx4.c4z = (double)cx4.C4WFZVal - 0x95; | |
| 25 | ||
| 26 | //Rotate X | |
| 27 | cx4.tanval = -(double)cx4.C4WFX2Val * PI * 2 / 128; | |
| 28 | cx4.c4y2 = cx4.c4y * CX4_cos(cx4.tanval) - cx4.c4z * CX4_sin(cx4.tanval); | |
| 29 | cx4.c4z2 = cx4.c4y * CX4_sin(cx4.tanval) + cx4.c4z * CX4_cos(cx4.tanval); | |
| 30 | ||
| 31 | //Rotate Y | |
| 32 | cx4.tanval = -(double)cx4.C4WFY2Val * PI * 2 / 128; | |
| 33 | cx4.c4x2 = cx4.c4x * CX4_cos(cx4.tanval) + cx4.c4z2 * CX4_sin(cx4.tanval); | |
| 34 | cx4.c4z = cx4.c4x * -CX4_sin(cx4.tanval) + cx4.c4z2 * CX4_cos(cx4.tanval); | |
| 35 | ||
| 36 | //Rotate Z | |
| 37 | cx4.tanval = -(double)cx4.C4WFDist * PI * 2 / 128; | |
| 38 | cx4.c4x = cx4.c4x2 * CX4_cos(cx4.tanval) - cx4.c4y2 * CX4_sin(cx4.tanval); | |
| 39 | cx4.c4y = cx4.c4x2 * CX4_sin(cx4.tanval) + cx4.c4y2 * CX4_cos(cx4.tanval); | |
| 40 | ||
| 41 | //Scale | |
| 42 | cx4.C4WFXVal = (INT16)(cx4.c4x * cx4.C4WFScale / (0x90 * (cx4.c4z + 0x95)) * 0x95); | |
| 43 | cx4.C4WFYVal = (INT16)(cx4.c4y * cx4.C4WFScale / (0x90 * (cx4.c4z + 0x95)) * 0x95); | |
| 44 | } | |
| 45 | ||
| 46 | void CX4_C4CalcWireFrame(void) | |
| 47 | { | |
| 48 | cx4.C4WFXVal = cx4.C4WFX2Val - cx4.C4WFXVal; | |
| 49 | cx4.C4WFYVal = cx4.C4WFY2Val - cx4.C4WFYVal; | |
| 50 | ||
| 51 | if(abs(cx4.C4WFXVal) > abs(cx4.C4WFYVal)) | |
| 52 | { | |
| 53 | cx4.C4WFDist = abs(cx4.C4WFXVal) + 1; | |
| 54 | cx4.C4WFYVal = (256 * (long)cx4.C4WFYVal) / abs(cx4.C4WFXVal); | |
| 55 | cx4.C4WFXVal = (cx4.C4WFXVal < 0) ? -256 : 256; | |
| 56 | } | |
| 57 | else if(cx4.C4WFYVal != 0) | |
| 58 | { | |
| 59 | cx4.C4WFDist = abs(cx4.C4WFYVal) + 1; | |
| 60 | cx4.C4WFXVal = (256 * (long)cx4.C4WFXVal) / abs(cx4.C4WFYVal); | |
| 61 | cx4.C4WFYVal = (cx4.C4WFYVal < 0) ? -256 : 256; | |
| 62 | } | |
| 63 | else | |
| 64 | { | |
| 65 | cx4.C4WFDist = 0; | |
| 66 | } | |
| 67 | } | |
| 68 | ||
| 69 | void CX4_C4TransfWireFrame2(void) | |
| 70 | { | |
| 71 | cx4.c4x = (double)cx4.C4WFXVal; | |
| 72 | cx4.c4y = (double)cx4.C4WFYVal; | |
| 73 | cx4.c4z = (double)cx4.C4WFZVal; | |
| 74 | ||
| 75 | //Rotate X | |
| 76 | cx4.tanval = -(double)cx4.C4WFX2Val * PI * 2 / 128; | |
| 77 | cx4.c4y2 = cx4.c4y * CX4_cos(cx4.tanval) - cx4.c4z * CX4_sin(cx4.tanval); | |
| 78 | cx4.c4z2 = cx4.c4y * CX4_sin(cx4.tanval) + cx4.c4z * CX4_cos(cx4.tanval); | |
| 79 | ||
| 80 | //Rotate Y | |
| 81 | cx4.tanval = -(double)cx4.C4WFY2Val * PI * 2 / 128; | |
| 82 | cx4.c4x2 = cx4.c4x * CX4_cos(cx4.tanval) + cx4.c4z2 * CX4_sin(cx4.tanval); | |
| 83 | cx4.c4z = cx4.c4x * -CX4_sin(cx4.tanval) + cx4.c4z2 * CX4_cos(cx4.tanval); | |
| 84 | ||
| 85 | //Rotate Z | |
| 86 | cx4.tanval = -(double)cx4.C4WFDist * PI * 2 / 128; | |
| 87 | cx4.c4x = cx4.c4x2 * CX4_cos(cx4.tanval) - cx4.c4y2 * CX4_sin(cx4.tanval); | |
| 88 | cx4.c4y = cx4.c4x2 * CX4_sin(cx4.tanval) + cx4.c4y2 * CX4_cos(cx4.tanval); | |
| 89 | ||
| 90 | //Scale | |
| 91 | cx4.C4WFXVal = (INT16)(cx4.c4x * cx4.C4WFScale / 0x100); | |
| 92 | cx4.C4WFYVal = (INT16)(cx4.c4y * cx4.C4WFScale / 0x100); | |
| 93 | } | |
| 94 | ||
| 95 | void CX4_C4DrawWireFrame(running_machine *machine) | |
| 96 | { | |
| 97 | UINT32 line = CX4_readl(0x1f80); | |
| 98 | UINT32 point1, point2; | |
| 99 | INT16 X1, Y1, Z1; | |
| 100 | INT16 X2, Y2, Z2; | |
| 101 | UINT8 Color; | |
| 102 | INT32 i; | |
| 103 | ||
| 104 | for(i = cx4.ram[0x0295]; i > 0; i--, line += 5) | |
| 105 | { | |
| 106 | if(memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), line) == 0xff && | |
| 107 | memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), line + 1) == 0xff) | |
| 108 | { | |
| 109 | INT32 tmp = line - 5; | |
| 110 | while(memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), tmp + 2) == 0xff && | |
| 111 | memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), tmp + 3) == 0xff && | |
| 112 | (tmp + 2) >= 0) | |
| 113 | { | |
| 114 | tmp -= 5; | |
| 115 | } | |
| 116 | point1 = (CX4_read(0x1f82) << 16) | | |
| 117 | (memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), tmp + 2) << 8) | | |
| 118 | memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), tmp + 3); | |
| 119 | } | |
| 120 | else | |
| 121 | { | |
| 122 | point1 = (CX4_read(0x1f82) << 16) | | |
| 123 | (memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), line) << 8) | | |
| 124 | memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), line + 1); | |
| 125 | } | |
| 126 | point2 = (CX4_read(0x1f82) << 16) | | |
| 127 | (memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), line + 2) << 8) | | |
| 128 | memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), line + 3); | |
| 129 | ||
| 130 | X1=(memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), point1 + 0) << 8) | | |
| 131 | memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), point1 + 1); | |
| 132 | Y1=(memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), point1 + 2) << 8) | | |
| 133 | memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), point1 + 3); | |
| 134 | Z1=(memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), point1 + 4) << 8) | | |
| 135 | memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), point1 + 5); | |
| 136 | X2=(memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), point2 + 0) << 8) | | |
| 137 | memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), point2 + 1); | |
| 138 | Y2=(memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), point2 + 2) << 8) | | |
| 139 | memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), point2 + 3); | |
| 140 | Z2=(memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), point2 + 4) << 8) | | |
| 141 | memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), point2 + 5); | |
| 142 | Color = memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), line + 4); | |
| 143 | CX4_C4DrawLine(X1, Y1, Z1, X2, Y2, Z2, Color); | |
| 144 | } | |
| 145 | } | |
| 146 | ||
| 147 | void CX4_C4DrawLine(INT32 X1, INT32 Y1, INT16 Z1, INT32 X2, INT32 Y2, INT16 Z2, UINT8 Color) | |
| 148 | { | |
| 149 | INT32 i; | |
| 150 | ||
| 151 | //Transform coordinates | |
| 152 | cx4.C4WFXVal = (INT16)X1; | |
| 153 | cx4.C4WFYVal = (INT16)Y1; | |
| 154 | cx4.C4WFZVal = Z1; | |
| 155 | cx4.C4WFScale = CX4_read(0x1f90); | |
| 156 | cx4.C4WFX2Val = CX4_read(0x1f86); | |
| 157 | cx4.C4WFY2Val = CX4_read(0x1f87); | |
| 158 | cx4.C4WFDist = CX4_read(0x1f88); | |
| 159 | CX4_C4TransfWireFrame2(); | |
| 160 | X1 = (cx4.C4WFXVal + 48) << 8; | |
| 161 | Y1 = (cx4.C4WFYVal + 48) << 8; | |
| 162 | ||
| 163 | cx4.C4WFXVal = (INT16)X2; | |
| 164 | cx4.C4WFYVal = (INT16)Y2; | |
| 165 | cx4.C4WFZVal = Z2; | |
| 166 | CX4_C4TransfWireFrame2(); | |
| 167 | X2 = (cx4.C4WFXVal + 48) << 8; | |
| 168 | Y2 = (cx4.C4WFYVal + 48) << 8; | |
| 169 | ||
| 170 | //Get line info | |
| 171 | cx4.C4WFXVal = (INT16)(X1 >> 8); | |
| 172 | cx4.C4WFYVal = (INT16)(Y1 >> 8); | |
| 173 | cx4.C4WFX2Val = (INT16)(X2 >> 8); | |
| 174 | cx4.C4WFY2Val = (INT16)(Y2 >> 8); | |
| 175 | CX4_C4CalcWireFrame(); | |
| 176 | X2 = (INT16)cx4.C4WFXVal; | |
| 177 | Y2 = (INT16)cx4.C4WFYVal; | |
| 178 | ||
| 179 | //Render line | |
| 180 | for(i = cx4.C4WFDist ? cx4.C4WFDist : 1; i > 0; i--) | |
| 181 | { | |
| 182 | if(X1 > 0xff && Y1 > 0xff && X1 < 0x6000 && Y1 < 0x6000) | |
| 183 | { | |
| 184 | UINT16 addr = (((Y1 >> 8) >> 3) << 8) - (((Y1 >> 8) >> 3) << 6) + (((X1 >> 8) >> 3) << 4) + ((Y1 >> 8) & 7) * 2; | |
| 185 | UINT8 bit = 0x80 >> ((X1 >> 8) & 7); | |
| 186 | cx4.ram[addr + 0x300] &= ~bit; | |
| 187 | cx4.ram[addr + 0x301] &= ~bit; | |
| 188 | if(Color & 1) | |
| 189 | { | |
| 190 | cx4.ram[addr + 0x300] |= bit; | |
| 191 | } | |
| 192 | if(Color & 2) | |
| 193 | { | |
| 194 | cx4.ram[addr + 0x301] |= bit; | |
| 195 | } | |
| 196 | } | |
| 197 | X1 += X2; | |
| 198 | Y1 += Y2; | |
| 199 | } | |
| 200 | } | |
| 201 | ||
| 202 | void CX4_C4DoScaleRotate(int row_padding) | |
| 203 | { | |
| 204 | INT16 A, B, C, D; | |
| 205 | INT32 x, y; | |
| 206 | ||
| 207 | //Calculate Pixel Resolution | |
| 208 | UINT8 w = CX4_read(0x1f89) & ~7; | |
| 209 | UINT8 h = CX4_read(0x1f8c) & ~7; | |
| 210 | ||
| 211 | INT32 Cx = (INT16)CX4_readw(0x1f83); | |
| 212 | INT32 Cy = (INT16)CX4_readw(0x1f86); | |
| 213 | ||
| 214 | INT32 LineX, LineY; | |
| 215 | UINT32 X, Y; | |
| 216 | UINT8 byte; | |
| 217 | INT32 outidx = 0; | |
| 218 | UINT8 bit = 0x80; | |
| 219 | ||
| 220 | //Calculate matrix | |
| 221 | INT32 XScale = CX4_readw(0x1f8f); | |
| 222 | INT32 YScale = CX4_readw(0x1f92); | |
| 223 | ||
| 224 | if(XScale & 0x8000) | |
| 225 | { | |
| 226 | XScale = 0x7fff; | |
| 227 | } | |
| 228 | if(YScale & 0x8000) | |
| 229 | { | |
| 230 | YScale = 0x7fff; | |
| 231 | } | |
| 232 | ||
| 233 | if(CX4_readw(0x1f80) == 0) | |
| 234 | { //no rotation | |
| 235 | A = (INT16)XScale; | |
| 236 | B = 0; | |
| 237 | C = 0; | |
| 238 | D = (INT16)YScale; | |
| 239 | } | |
| 240 | else if(CX4_readw(0x1f80) == 128) | |
| 241 | { //90 degree rotation | |
| 242 | A = 0; | |
| 243 | B = (INT16)(-YScale); | |
| 244 | C = (INT16)XScale; | |
| 245 | D = 0; | |
| 246 | } | |
| 247 | else if(CX4_readw(0x1f80) == 256) | |
| 248 | { //180 degree rotation | |
| 249 | A = (INT16)(-XScale); | |
| 250 | B = 0; | |
| 251 | C = 0; | |
| 252 | D = (INT16)(-YScale); | |
| 253 | } | |
| 254 | else if(CX4_readw(0x1f80) == 384) | |
| 255 | { //270 degree rotation | |
| 256 | A = 0; | |
| 257 | B = (INT16)YScale; | |
| 258 | C = (INT16)(-XScale); | |
| 259 | D = 0; | |
| 260 | } | |
| 261 | else | |
| 262 | { | |
| 263 | A = (INT16) CX4_sar(CX4_CosTable[CX4_readw(0x1f80) & 0x1ff] * XScale, 15); | |
| 264 | B = (INT16)(-CX4_sar(CX4_SinTable[CX4_readw(0x1f80) & 0x1ff] * YScale, 15)); | |
| 265 | C = (INT16) CX4_sar(CX4_SinTable[CX4_readw(0x1f80) & 0x1ff] * XScale, 15); | |
| 266 | D = (INT16) CX4_sar(CX4_CosTable[CX4_readw(0x1f80) & 0x1ff] * YScale, 15); | |
| 267 | } | |
| 268 | ||
| 269 | //Clear the output RAM | |
| 270 | memset(cx4.ram, 0, (w + row_padding / 4) * h / 2); | |
| 271 | ||
| 272 | //Calculate start position (i.e. (Ox, Oy) = (0, 0)) | |
| 273 | //The low 12 bits are fractional, so (Cx<<12) gives us the Cx we want in | |
| 274 | //the function. We do Cx*A etc normally because the matrix parameters | |
| 275 | //already have the fractional parts. | |
| 276 | LineX = (Cx << 12) - Cx * A - Cx * B; | |
| 277 | LineY = (Cy << 12) - Cy * C - Cy * D; | |
| 278 | ||
| 279 | //Start loop | |
| 280 | for(y = 0; y < h; y++) | |
| 281 | { | |
| 282 | X = LineX; | |
| 283 | Y = LineY; | |
| 284 | for(x = 0; x < w; x++) | |
| 285 | { | |
| 286 | if((X >> 12) >= w || (Y >> 12) >= h) | |
| 287 | { | |
| 288 | byte = 0; | |
| 289 | } | |
| 290 | else | |
| 291 | { | |
| 292 | UINT32 addr = (Y >> 12) * w + (X >> 12); | |
| 293 | byte = CX4_read(0x600 + (addr >> 1)); | |
| 294 | if(addr & 1) | |
| 295 | { | |
| 296 | byte >>= 4; | |
| 297 | } | |
| 298 | } | |
| 299 | ||
| 300 | //De-bitplanify | |
| 301 | if(byte & 1) { cx4.ram[outidx ] |= bit; } | |
| 302 | if(byte & 2) { cx4.ram[outidx + 1] |= bit; } | |
| 303 | if(byte & 4) { cx4.ram[outidx + 16] |= bit; } | |
| 304 | if(byte & 8) { cx4.ram[outidx + 17] |= bit; } | |
| 305 | ||
| 306 | bit >>= 1; | |
| 307 | if(!bit) | |
| 308 | { | |
| 309 | bit = 0x80; | |
| 310 | outidx += 32; | |
| 311 | } | |
| 312 | ||
| 313 | X += A; //Add 1 to output x => add an A and a C | |
| 314 | Y += C; | |
| 315 | } | |
| 316 | outidx += 2 + row_padding; | |
| 317 | if(outidx & 0x10) | |
| 318 | { | |
| 319 | outidx &= ~0x10; | |
| 320 | } | |
| 321 | else | |
| 322 | { | |
| 323 | outidx -= w * 4 + row_padding; | |
| 324 | } | |
| 325 | LineX += B; //Add 1 to output y => add a B and a D | |
| 326 | LineY += D; | |
| 327 | } | |
| 328 | } |
| r0 | r5770 | |
|---|---|---|
| 1 | /*************************************************************************** | |
| 2 | ||
| 3 | snescx4.c | |
| 4 | ||
| 5 | File to handle emulation of the SNES "CX4" add-on chip. | |
| 6 | ||
| 7 | Code based on original work by zsKnight, anomie and Nach. | |
| 8 | This implementation is based on C++ "cx4*.cpp" by byuu | |
| 9 | (up to date with source v 0.49). | |
| 10 | ||
| 11 | ***************************************************************************/ | |
| 12 | ||
| 13 | #include "snescx4.h" | |
| 14 | #include "cx4data.c" | |
| 15 | #include "cx4fn.c" | |
| 16 | #include "cx4oam.c" | |
| 17 | #include "cx4ops.c" | |
| 18 | ||
| 19 | UINT32 CX4_ldr(UINT8 r) | |
| 20 | { | |
| 21 | UINT16 addr = 0x0080 + (r * 3); | |
| 22 | return (cx4.reg[addr + 0] << 0) | |
| 23 | | (cx4.reg[addr + 1] << 8) | |
| 24 | | (cx4.reg[addr + 2] << 16); | |
| 25 | } | |
| 26 | ||
| 27 | void CX4_str(UINT8 r, UINT32 data) | |
| 28 | { | |
| 29 | UINT16 addr = 0x0080 + (r * 3); | |
| 30 | cx4.reg[addr + 0] = (data >> 0); | |
| 31 | cx4.reg[addr + 1] = (data >> 8); | |
| 32 | cx4.reg[addr + 2] = (data >> 16); | |
| 33 | } | |
| 34 | ||
| 35 | void CX4_mul(UINT32 x, UINT32 y, UINT32 *rl, UINT32 *rh) | |
| 36 | { | |
| 37 | INT64 rx = x & 0xffffff; | |
| 38 | INT64 ry = y & 0xffffff; | |
| 39 | if(rx & 0x800000)rx |= ~0x7fffff; | |
| 40 | if(ry & 0x800000)ry |= ~0x7fffff; | |
| 41 | ||
| 42 | rx *= ry; | |
| 43 | ||
| 44 | *rl = (rx) & 0xffffff; | |
| 45 | *rh = (rx >> 24) & 0xffffff; | |
| 46 | } | |
| 47 | ||
| 48 | UINT32 CX4_sin(UINT32 rx) | |
| 49 | { | |
| 50 | cx4.r0 = rx & 0x1ff; | |
| 51 | if(cx4.r0 & 0x100) | |
| 52 | { | |
| 53 | cx4.r0 ^= 0x1ff; | |
| 54 | } | |
| 55 | if(cx4.r0 & 0x080) | |
| 56 | { | |
| 57 | cx4.r0 ^= 0x0ff; | |
| 58 | } | |
| 59 | if(rx & 0x100) | |
| 60 | { | |
| 61 | return CX4_sin_table[cx4.r0 + 0x80]; | |
| 62 | } | |
| 63 | else | |
| 64 | { | |
| 65 | return CX4_sin_table[cx4.r0]; | |
| 66 | } | |
| 67 | } | |
| 68 | ||
| 69 | UINT32 CX4_cos(UINT32 rx) | |
| 70 | { | |
| 71 | return CX4_sin(rx + 0x080); | |
| 72 | } | |
| 73 | ||
| 74 | void CX4_immediate_reg(UINT32 start) | |
| 75 | { | |
| 76 | UINT32 i = 0; | |
| 77 | cx4.r0 = CX4_ldr(0); | |
| 78 | for(i = start; i < 48; i++) | |
| 79 | { | |
| 80 | if((cx4.r0 & 0x0fff) < 0x0c00) | |
| 81 | { | |
| 82 | cx4.ram[cx4.r0 & 0x0fff] = CX4_immediate_data[i]; | |
| 83 | } | |
| 84 | cx4.r0++; | |
| 85 | } | |
| 86 | CX4_str(0, cx4.r0); | |
| 87 | } | |
| 88 | ||
| 89 | void CX4_transfer_data(running_machine *machine) | |
| 90 | { | |
| 91 | UINT32 src; | |
| 92 | UINT16 dest, count; | |
| 93 | UINT32 i; | |
| 94 | ||
| 95 | src = (cx4.reg[0x40]) | (cx4.reg[0x41] << 8) | (cx4.reg[0x42] << 16); | |
| 96 | count = (cx4.reg[0x43]) | (cx4.reg[0x44] << 8); | |
| 97 | dest = (cx4.reg[0x45]) | (cx4.reg[0x46] << 8); | |
| 98 | ||
| 99 | for(i=0;i<count;i++) | |
| 100 | { | |
| 101 | CX4_write(machine, dest++, memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), src++)); | |
| 102 | } | |
| 103 | } | |
| 104 | ||
| 105 | void CX4_write(running_machine *machine, UINT32 addr, UINT8 data) | |
| 106 | { | |
| 107 | addr &= 0x1fff; | |
| 108 | ||
| 109 | if(addr < 0x0c00) | |
| 110 | { | |
| 111 | //ram | |
| 112 | cx4.ram[addr] = data; | |
| 113 | return; | |
| 114 | } | |
| 115 | ||
| 116 | if(addr < 0x1f00) | |
| 117 | { | |
| 118 | //unmapped | |
| 119 | return; | |
| 120 | } | |
| 121 | ||
| 122 | //command register | |
| 123 | cx4.reg[addr & 0xff] = data; | |
| 124 | ||
| 125 | if(addr == 0x1f47) | |
| 126 | { | |
| 127 | //memory transfer | |
| 128 | CX4_transfer_data(machine); | |
| 129 | return; | |
| 130 | } | |
| 131 | ||
| 132 | if(addr == 0x1f4f) | |
| 133 | { | |
| 134 | //c4 command | |
| 135 | if(cx4.reg[0x4d] == 0x0e && !(data & 0xc3)) | |
| 136 | { | |
| 137 | //c4 test command | |
| 138 | cx4.reg[0x80] = data >> 2; | |
| 139 | return; | |
| 140 | } | |
| 141 | ||
| 142 | switch(data) | |
| 143 | { | |
| 144 | case 0x00: CX4_op00(machine); break; | |
| 145 | case 0x01: CX4_op01(machine); break; | |
| 146 | case 0x05: CX4_op05(machine); break; | |
| 147 | case 0x0d: CX4_op0d(machine); break; | |
| 148 | case 0x10: CX4_op10(); break; | |
| 149 | case 0x13: CX4_op13(); break; | |
| 150 | case 0x15: CX4_op15(machine); break; | |
| 151 | case 0x1f: CX4_op1f(machine); break; | |
| 152 | case 0x22: CX4_op22(); break; | |
| 153 | case 0x25: CX4_op25(); break; | |
| 154 | case 0x2d: CX4_op2d(machine); break; | |
| 155 | case 0x40: CX4_op40(); break; | |
| 156 | case 0x54: CX4_op54(); break; | |
| 157 | case 0x5c: CX4_op5c(); break; | |
| 158 | case 0x5e: CX4_op5e(); break; | |
| 159 | case 0x60: CX4_op60(); break; | |
| 160 | case 0x62: CX4_op62(); break; | |
| 161 | case 0x64: CX4_op64(); break; | |
| 162 | case 0x66: CX4_op66(); break; | |
| 163 | case 0x68: CX4_op68(); break; | |
| 164 | case 0x6a: CX4_op6a(); break; | |
| 165 | case 0x6c: CX4_op6c(); break; | |
| 166 | case 0x6e: CX4_op6e(); break; | |
| 167 | case 0x70: CX4_op70(); break; | |
| 168 | case 0x72: CX4_op72(); break; | |
| 169 | case 0x74: CX4_op74(); break; | |
| 170 | case 0x76: CX4_op76(); break; | |
| 171 | case 0x78: CX4_op78(); break; | |
| 172 | case 0x7a: CX4_op7a(); break; | |
| 173 | case 0x7c: CX4_op7c(); break; | |
| 174 | case 0x89: CX4_op89(); break; | |
| 175 | } | |
| 176 | } | |
| 177 | } | |
| 178 | ||
| 179 | void CX4_writeb(running_machine *machine, UINT16 addr, UINT8 data) | |
| 180 | { | |
| 181 | CX4_write(machine, addr, data); | |
| 182 | } | |
| 183 | ||
| 184 | void CX4_writew(running_machine *machine, UINT16 addr, UINT16 data) | |
| 185 | { | |
| 186 | CX4_write(machine, addr + 0, data >> 0); | |
| 187 | CX4_write(machine, addr + 1, data >> 8); | |
| 188 | } | |
| 189 | ||
| 190 | void CX4_writel(running_machine *machine, UINT16 addr, UINT32 data) | |
| 191 | { | |
| 192 | CX4_write(machine, addr + 0, data >> 0); | |
| 193 | CX4_write(machine, addr + 1, data >> 8); | |
| 194 | CX4_write(machine, addr + 2, data >> 16); | |
| 195 | } | |
| 196 | ||
| 197 | UINT8 CX4_read(UINT32 addr) | |
| 198 | { | |
| 199 | addr &= 0x1fff; | |
| 200 | ||
| 201 | if(addr < 0x0c00) | |
| 202 | { | |
| 203 | return cx4.ram[addr]; | |
| 204 | } | |
| 205 | ||
| 206 | if(addr >= 0x1f00) | |
| 207 | { | |
| 208 | return cx4.reg[addr & 0xff]; | |
| 209 | } | |
| 210 | ||
| 211 | return 0xff; | |
| 212 | } | |
| 213 | ||
| 214 | UINT8 CX4_readb(UINT16 addr) | |
| 215 | { | |
| 216 | return CX4_read(addr); | |
| 217 | } | |
| 218 | ||
| 219 | UINT16 CX4_readw(UINT16 addr) | |
| 220 | { | |
| 221 | return CX4_read(addr) | (CX4_read(addr + 1) << 8); | |
| 222 | } | |
| 223 | ||
| 224 | UINT32 CX4_readl(UINT16 addr) | |
| 225 | { | |
| 226 | return CX4_read(addr) | (CX4_read(addr + 1) << 8) | (CX4_read(addr + 2) << 16); | |
| 227 | } | |
| 228 | ||
| 229 | void CX4_reset() | |
| 230 | { | |
| 231 | memset(cx4.ram, 0, 0x0c00); | |
| 232 | memset(cx4.reg, 0, 0x0100); | |
| 233 | } |
| r0 | r5770 | |
|---|---|---|
| 1 | /*************************************************************************** | |
| 2 | ||
| 3 | snescx4.h | |
| 4 | ||
| 5 | Code based on original work by zsKnight, anomie and Nach. | |
| 6 | This implementation is based on C++ "cx4*.cpp" by byuu | |
| 7 | (up to date with source v 0.49). | |
| 8 | ||
| 9 | ***************************************************************************/ | |
| 10 | ||
| 11 | #include "driver.h" | |
| 12 | ||
| 13 | typedef struct | |
| 14 | { | |
| 15 | UINT8 ram[0x0c00]; | |
| 16 | UINT8 reg[0x0100]; | |
| 17 | UINT32 r0, r1, r2, r3, r4, r5, r6, r7, | |
| 18 | r8, r9, r10, r11, r12, r13, r14, r15; | |
| 19 | ||
| 20 | INT16 C4WFXVal, C4WFYVal, C4WFZVal, C4WFX2Val, C4WFY2Val, C4WFDist, C4WFScale; | |
| 21 | INT16 C41FXVal, C41FYVal, C41FAngleRes, C41FDist, C41FDistVal; | |
| 22 | ||
| 23 | double tanval; | |
| 24 | double c4x, c4y, c4z; | |
| 25 | double c4x2, c4y2, c4z2; | |
| 26 | } CX4; | |
| 27 | ||
| 28 | static CX4 cx4; | |
| 29 | ||
| 30 | UINT32 CX4_ldr(UINT8 r); | |
| 31 | void CX4_str(UINT8 r, UINT32 data); | |
| 32 | void CX4_mul(UINT32 x, UINT32 y, UINT32 *rl, UINT32 *rh); | |
| 33 | UINT32 CX4_sin(UINT32 rx); | |
| 34 | UINT32 CX4_cos(UINT32 rx); | |
| 35 | ||
| 36 | void CX4_transfer_data(running_machine *machine); | |
| 37 | void CX4_immediate_reg(UINT32 num); | |
| 38 | ||
| 39 | void CX4_op00_00(running_machine *machine); | |
| 40 | void CX4_op00_03(void); | |
| 41 | void CX4_op00_05(running_machine *machine); | |
| 42 | void CX4_op00_07(void); | |
| 43 | void CX4_op00_08(running_machine *machine); | |
| 44 | void CX4_op00_0b(running_machine *machine); | |
| 45 | void CX4_op00_0c(running_machine *machine); | |
| 46 | ||
| 47 | void CX4_op00(running_machine* machine); | |
| 48 | void CX4_op01(running_machine* machine); | |
| 49 | void CX4_op05(running_machine *machine); | |
| 50 | void CX4_op0d(running_machine *machine); | |
| 51 | void CX4_op10(void); | |
| 52 | void CX4_op13(void); | |
| 53 | void CX4_op15(running_machine *machine); | |
| 54 | void CX4_op1f(running_machine *machine); | |
| 55 | void CX4_op22(void); | |
| 56 | void CX4_op25(void); | |
| 57 | void CX4_op2d(running_machine *machine); | |
| 58 | void CX4_op40(void); | |
| 59 | void CX4_op54(void); | |
| 60 | void CX4_op5c(void); | |
| 61 | void CX4_op5e(void); | |
| 62 | void CX4_op60(void); | |
| 63 | void CX4_op62(void); | |
| 64 | void CX4_op64(void); | |
| 65 | void CX4_op66(void); | |
| 66 | void CX4_op68(void); | |
| 67 | void CX4_op6a(void); | |
| 68 | void CX4_op6c(void); | |
| 69 | void CX4_op6e(void); | |
| 70 | void CX4_op70(void); | |
| 71 | void CX4_op72(void); | |
| 72 | void CX4_op74(void); | |
| 73 | void CX4_op76(void); | |
| 74 | void CX4_op78(void); | |
| 75 | void CX4_op7a(void); | |
| 76 | void CX4_op7c(void); | |
| 77 | void CX4_op89(void); | |
| 78 | ||
| 79 | UINT8 CX4_readb(UINT16 addr); | |
| 80 | UINT16 CX4_readw(UINT16 addr); | |
| 81 | UINT32 CX4_readl(UINT16 addr); | |
| 82 | ||
| 83 | void CX4_writeb(running_machine *machine, UINT16 addr, UINT8 data); | |
| 84 | void CX4_writew(running_machine *machine, UINT16 addr, UINT16 data); | |
| 85 | void CX4_writel(running_machine *machine, UINT16 addr, UINT32 data); | |
| 86 | ||
| 87 | void CX4_reset(void); | |
| 88 | ||
| 89 | UINT8 CX4_read(UINT32 addr); | |
| 90 | void CX4_write(running_machine *machine, UINT32 addr, UINT8 data); | |
| 91 | ||
| 92 | void CX4_C4DrawLine(INT32 X1, INT32 Y1, INT16 Z1, INT32 X2, INT32 Y2, INT16 Z2, UINT8 Color); |
| r5769 | r5770 | |
|---|---|---|
| 61 | 61 | #include "machine/snesdsp3.c" |
| 62 | 62 | #include "machine/snesdsp4.c" |
| 63 | 63 | #include "machine/snesobc1.c" |
| 64 | #include "machine/snescx4.c" | |
| 64 | 65 | #include "machine/snesrtc.c" |
| 65 | 66 | #include "machine/snessdd1.c" |
| 66 | 67 | |
| r5769 | r5770 | |
| 1467 | 1468 | value = (address < 0x7000) ? DSP2_read() : 0x00; |
| 1468 | 1469 | else if ((snes_cart.mode == SNES_MODE_21) && (snes_has_addon_chip == HAS_DSP1) && (offset < 0x100000)) |
| 1469 | 1470 | value = (address < 0x7000) ? DSP1_getDr() : DSP1_getSr(); |
| 1471 | else if (snes_has_addon_chip == HAS_CX4) | |
| 1472 | value = CX4_read(address - 0x6000); | |
| 1470 | 1473 | else |
| 1471 | 1474 | { |
| 1472 | 1475 | logerror( "snes_r_bank1: Unmapped external chip read: %04x\n", address ); |
| r5769 | r5770 | |
| 1704 | 1707 | DSP2_write(data); |
| 1705 | 1708 | else if ((snes_cart.mode == SNES_MODE_21) && (snes_has_addon_chip == HAS_DSP1) && (offset < 0x100000)) |
| 1706 | 1709 | DSP1_setDr(data); |
| 1710 | else if (snes_has_addon_chip == HAS_CX4) | |
| 1711 | CX4_write(space->machine, address - 0x6000, data); | |
| 1707 | 1712 | else |
| 1708 | 1713 | logerror( "snes_w_bank1: Attempt to write to reserved address: %x = %02x\n", offset, data ); |
| 1709 | 1714 | } |
| r0 | r5770 | |
|---|---|---|
| 1 | /*************************************************************************** | |
| 2 | ||
| 3 | cx4data.c | |
| 4 | ||
| 5 | Code based on original work by zsKnight, anomie and Nach. | |
| 6 | This implementation is based on C++ "cx4*.cpp" by byuu | |
| 7 | (up to date with source v 0.49). | |
| 8 | ||
| 9 | ***************************************************************************/ | |
| 10 | ||
| 11 | const UINT8 CX4_immediate_data[48] = | |
| 12 | { | |
| 13 | 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, | |
| 14 | 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x80, 0xff, 0xff, 0x7f, | |
| 15 | 0x00, 0x80, 0x00, 0xff, 0x7f, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0xff, | |
| 16 | 0x00, 0x00, 0x01, 0xff, 0xff, 0xfe, 0x00, 0x01, 0x00, 0xff, 0xfe, 0x00 | |
| 17 | }; | |
| 18 | ||
| 19 | const UINT16 CX4_wave_data[40] = | |
| 20 | { | |
| 21 | 0x0000, 0x0002, 0x0004, 0x0006, 0x0008, 0x000a, 0x000c, 0x000e, | |
| 22 | 0x0200, 0x0202, 0x0204, 0x0206, 0x0208, 0x020a, 0x020c, 0x020e, | |
| 23 | 0x0400, 0x0402, 0x0404, 0x0406, 0x0408, 0x040a, 0x040c, 0x040e, | |
| 24 | 0x0600, 0x0602, 0x0604, 0x0606, 0x0608, 0x060a, 0x060c, 0x060e, | |
| 25 | 0x0800, 0x0802, 0x0804, 0x0806, 0x0808, 0x080a, 0x080c, 0x080e | |
| 26 | }; | |
| 27 | ||
| 28 | const UINT32 CX4_sin_table[256] = | |
| 29 | { | |
| 30 | 0x000000, 0x000324, 0x000648, 0x00096c, 0x000c8f, 0x000fb2, 0x0012d5, 0x0015f6, | |
| 31 | 0x001917, 0x001c37, 0x001f56, 0x002273, 0x002590, 0x0028aa, 0x002bc4, 0x002edb, | |
| 32 | 0x0031f1, 0x003505, 0x003817, 0x003b26, 0x003e33, 0x00413e, 0x004447, 0x00474d, | |
| 33 | 0x004a50, 0x004d50, 0x00504d, 0x005347, 0x00563e, 0x005931, 0x005c22, 0x005f0e, | |
| 34 | 0x0061f7, 0x0064dc, 0x0067bd, 0x006a9b, 0x006d74, 0x007049, 0x007319, 0x0075e5, | |
| 35 | 0x0078ad, 0x007b70, 0x007e2e, 0x0080e7, 0x00839c, 0x00864b, 0x0088f5, 0x008b9a, | |
| 36 | 0x008e39, 0x0090d3, 0x009368, 0x0095f6, 0x00987f, 0x009b02, 0x009d7f, 0x009ff6, | |
| 37 | 0x00a267, 0x00a4d2, 0x00a736, 0x00a994, 0x00abeb, 0x00ae3b, 0x00b085, 0x00b2c8, | |
| 38 | 0x00b504, 0x00b73a, 0x00b968, 0x00bb8f, 0x00bdae, 0x00bfc7, 0x00c1d8, 0x00c3e2, | |
| 39 | 0x00c5e4, 0x00c7de, 0x00c9d1, 0x00cbbb, 0x00cd9f, 0x00cf7a, 0x00d14d, 0x00d318, | |
| 40 | 0x00d4db, 0x00d695, 0x00d848, 0x00d9f2, 0x00db94, 0x00dd2d, 0x00debe, 0x00e046, | |
| 41 | 0x00e1c5, 0x00e33c, 0x00e4aa, 0x00e60f, 0x00e76b, 0x00e8bf, 0x00ea09, 0x00eb4b, | |
| 42 | 0x00ec83, 0x00edb2, 0x00eed8, 0x00eff5, 0x00f109, 0x00f213, 0x00f314, 0x00f40b, | |
| 43 | 0x00f4fa, 0x00f5de, 0x00f6ba, 0x00f78b, 0x00f853, 0x00f912, 0x00f9c7, 0x00fa73, | |
| 44 | 0x00fb14, 0x00fbac, 0x00fc3b, 0x00fcbf, 0x00fd3a, 0x00fdab, 0x00fe13, 0x00fe70, | |
| 45 | 0x00fec4, 0x00ff0e, 0x00ff4e, 0x00ff84, 0x00ffb1, 0x00ffd3, 0x00ffec, 0x00fffb, | |
| 46 | 0x000000, 0xfffcdb, 0xfff9b7, 0xfff693, 0xfff370, 0xfff04d, 0xffed2a, 0xffea09, | |
| 47 | 0xffe6e8, 0xffe3c8, 0xffe0a9, 0xffdd8c, 0xffda6f, 0xffd755, 0xffd43b, 0xffd124, | |
| 48 | 0xffce0e, 0xffcafa, 0xffc7e8, 0xffc4d9, 0xffc1cc, 0xffbec1, 0xffbbb8, 0xffb8b2, | |
| 49 | 0xffb5af, 0xffb2af, 0xffafb2, 0xffacb8, 0xffa9c1, 0xffa6ce, 0xffa3dd, 0xffa0f1, | |
| 50 | 0xff9e08, 0xff9b23, 0xff9842, 0xff9564, 0xff928b, 0xff8fb6, 0xff8ce6, 0xff8a1a, | |
| 51 | 0xff8752, 0xff848f, 0xff81d1, 0xff7f18, 0xff7c63, 0xff79b4, 0xff770a, 0xff7465, | |
| 52 | 0xff71c6, 0xff6f2c, 0xff6c97, 0xff6a09, 0xff6780, 0xff64fd, 0xff6280, 0xff6009, | |
| 53 | 0xff5d98, 0xff5b2d, 0xff58c9, 0xff566b, 0xff5414, 0xff51c4, 0xff4f7a, 0xff4d37, | |
| 54 | 0xff4afb, 0xff48c5, 0xff4697, 0xff4470, 0xff4251, 0xff4038, 0xff3e27, 0xff3c1e, | |
| 55 | 0xff3a1b, 0xff3821, 0xff362e, 0xff3444, 0xff3260, 0xff3085, 0xff2eb2, 0xff2ce7, | |
| 56 | 0xff2b24, 0xff296a, 0xff27b7, 0xff260d, 0xff246b, 0xff22d2, 0xff2141, 0xff1fb9, | |
| 57 | 0xff1e3a, 0xff1cc3, 0xff1b55, 0xff19f0, 0xff1894, 0xff1740, 0xff15f6, 0xff14b4, | |
| 58 | 0xff137c, 0xff124d, 0xff1127, 0xff100a, 0xff0ef6, 0xff0dec, 0xff0ceb, 0xff0bf4, | |
| 59 | 0xff0b05, 0xff0a21, 0xff0945, 0xff0874, 0xff07ac, 0xff06ed, 0xff0638, 0xff058d, | |
| 60 | 0xff04eb, 0xff0453, 0xff03c4, 0xff0340, 0xff02c5, 0xff0254, 0xff01ec, 0xff018f, | |
| 61 | 0xff013b, 0xff00f1, 0xff00b1, 0xff007b, 0xff004e, 0xff002c, 0xff0013, 0xff0004 | |
| 62 | }; | |
| 63 | ||
| 64 | const INT16 CX4_SinTable[512] = | |
| 65 | { | |
| 66 | 0, 402, 804, 1206, 1607, 2009, 2410, 2811, | |
| 67 | 3211, 3611, 4011, 4409, 4808, 5205, 5602, 5997, | |
| 68 | 6392, 6786, 7179, 7571, 7961, 8351, 8739, 9126, | |
| 69 | 9512, 9896, 10278, 10659, 11039, 11416, 11793, 12167, | |
| 70 | 12539, 12910, 13278, 13645, 14010, 14372, 14732, 15090, | |
| 71 | 15446, 15800, 16151, 16499, 16846, 17189, 17530, 17869, | |
| 72 | 18204, 18537, 18868, 19195, 19519, 19841, 20159, 20475, | |
| 73 | 20787, 21097, 21403, 21706, 22005, 22301, 22594, 22884, | |
| 74 | 23170, 23453, 23732, 24007, 24279, 24547, 24812, 25073, | |
| 75 | 25330, 25583, 25832, 26077, 26319, 26557, 26790, 27020, | |
| 76 | 27245, 27466, 27684, 27897, 28106, 28310, 28511, 28707, | |
| 77 | 28898, 29086, 29269, 29447, 29621, 29791, 29956, 30117, | |
| 78 | 30273, 30425, 30572, 30714, 30852, 30985, 31114, 31237, | |
| 79 | 31357, 31471, 31581, 31685, 31785, 31881, 31971, 32057, | |
| 80 | 32138, 32214, 32285, 32351, 32413, 32469, 32521, 32568, | |
| 81 | 32610, 32647, 32679, 32706, 32728, 32745, 32758, 32765, | |
| 82 | 32767, 32765, 32758, 32745, 32728, 32706, 32679, 32647, | |
| 83 | 32610, 32568, 32521, 32469, 32413, 32351, 32285, 32214, | |
| 84 | 32138, 32057, 31971, 31881, 31785, 31685, 31581, 31471, | |
| 85 | 31357, 31237, 31114, 30985, 30852, 30714, 30572, 30425, | |
| 86 | 30273, 30117, 29956, 29791, 29621, 29447, 29269, 29086, | |
| 87 | 28898, 28707, 28511, 28310, 28106, 27897, 27684, 27466, | |
| 88 | 27245, 27020, 26790, 26557, 26319, 26077, 25832, 25583, | |
| 89 | 25330, 25073, 24812, 24547, 24279, 24007, 23732, 23453, | |
| 90 | 23170, 22884, 22594, 22301, 22005, 21706, 21403, 21097, | |
| 91 | 20787, 20475, 20159, 19841, 19519, 19195, 18868, 18537, | |
| 92 | 18204, 17869, 17530, 17189, 16846, 16499, 16151, 15800, | |
| 93 | 15446, 15090, 14732, 14372, 14010, 13645, 13278, 12910, | |
| 94 | 12539, 12167, 11793, 11416, 11039, 10659, 10278, 9896, | |
| 95 | 9512, 9126, 8739, 8351, 7961, 7571, 7179, 6786, | |
| 96 | 6392, 5997, 5602, 5205, 4808, 4409, 4011, 3611, | |
| 97 | 3211, 2811, 2410, 2009, 1607, 1206, 804, 402, | |
| 98 | 0, -402, -804, -1206, -1607, -2009, -2410, -2811, | |
| 99 | -3211, -3611, -4011, -4409, -4808, -5205, -5602, -5997, | |
| 100 | -6392, -6786, -7179, -7571, -7961, -8351, -8739, -9126, | |
| 101 | -9512, -9896, -10278, -10659, -11039, -11416, -11793, -12167, | |
| 102 | -12539, -12910, -13278, -13645, -14010, -14372, -14732, -15090, | |
| 103 | -15446, -15800, -16151, -16499, -16846, -17189, -17530, -17869, | |
| 104 | -18204, -18537, -18868, -19195, -19519, -19841, -20159, -20475, | |
| 105 | -20787, -21097, -21403, -21706, -22005, -22301, -22594, -22884, | |
| 106 | -23170, -23453, -23732, -24007, -24279, -24547, -24812, -25073, | |
| 107 | -25330, -25583, -25832, -26077, -26319, -26557, -26790, -27020, | |
| 108 | -27245, -27466, -27684, -27897, -28106, -28310, -28511, -28707, | |
| 109 | -28898, -29086, -29269, -29447, -29621, -29791, -29956, -30117, | |
| 110 | -30273, -30425, -30572, -30714, -30852, -30985, -31114, -31237, | |
| 111 | -31357, -31471, -31581, -31685, -31785, -31881, -31971, -32057, | |
| 112 | -32138, -32214, -32285, -32351, -32413, -32469, -32521, -32568, | |
| 113 | -32610, -32647, -32679, -32706, -32728, -32745, -32758, -32765, | |
| 114 | -32767, -32765, -32758, -32745, -32728, -32706, -32679, -32647, | |
| 115 | -32610, -32568, -32521, -32469, -32413, -32351, -32285, -32214, | |
| 116 | -32138, -32057, -31971, -31881, -31785, -31685, -31581, -31471, | |
| 117 | -31357, -31237, -31114, -30985, -30852, -30714, -30572, -30425, | |
| 118 | -30273, -30117, -29956, -29791, -29621, -29447, -29269, -29086, | |
| 119 | -28898, -28707, -28511, -28310, -28106, -27897, -27684, -27466, | |
| 120 | -27245, -27020, -26790, -26557, -26319, -26077, -25832, -25583, | |
| 121 | -25330, -25073, -24812, -24547, -24279, -24007, -23732, -23453, | |
| 122 | -23170, -22884, -22594, -22301, -22005, -21706, -21403, -21097, | |
| 123 | -20787, -20475, -20159, -19841, -19519, -19195, -18868, -18537, | |
| 124 | -18204, -17869, -17530, -17189, -16846, -16499, -16151, -15800, | |
| 125 | -15446, -15090, -14732, -14372, -14010, -13645, -13278, -12910, | |
| 126 | -12539, -12167, -11793, -11416, -11039, -10659, -10278, -9896, | |
| 127 | -9512, -9126, -8739, -8351, -7961, -7571, -7179, -6786, | |
| 128 | -6392, -5997, -5602, -5205, -4808, -4409, -4011, -3611, | |
| 129 | -3211, -2811, -2410, -2009, -1607, -1206, -804, -402 | |
| 130 | }; | |
| 131 | ||
| 132 | const INT16 CX4_CosTable[512] = | |
| 133 | { | |
| 134 | 32767, 32765, 32758, 32745, 32728, 32706, 32679, 32647, | |
| 135 | 32610, 32568, 32521, 32469, 32413, 32351, 32285, 32214, | |
| 136 | 32138, 32057, 31971, 31881, 31785, 31685, 31581, 31471, | |
| 137 | 31357, 31237, 31114, 30985, 30852, 30714, 30572, 30425, | |
| 138 | 30273, 30117, 29956, 29791, 29621, 29447, 29269, 29086, | |
| 139 | 28898, 28707, 28511, 28310, 28106, 27897, 27684, 27466, | |
| 140 | 27245, 27020, 26790, 26557, 26319, 26077, 25832, 25583, | |
| 141 | 25330, 25073, 24812, 24547, 24279, 24007, 23732, 23453, | |
| 142 | 23170, 22884, 22594, 22301, 22005, 21706, 21403, 21097, | |
| 143 | 20787, 20475, 20159, 19841, 19519, 19195, 18868, 18537, | |
| 144 | 18204, 17869, 17530, 17189, 16846, 16499, 16151, 15800, | |
| 145 | 15446, 15090, 14732, 14372, 14010, 13645, 13278, 12910, | |
| 146 | 12539, 12167, 11793, 11416, 11039, 10659, 10278, 9896, | |
| 147 | 9512, 9126, 8739, 8351, 7961, 7571, 7179, 6786, | |
| 148 | 6392, 5997, 5602, 5205, 4808, 4409, 4011, 3611, | |
| 149 | 3211, 2811, 2410, 2009, 1607, 1206, 804, 402, | |
| 150 | 0, -402, -804, -1206, -1607, -2009, -2410, -2811, | |
| 151 | -3211, -3611, -4011, -4409, -4808, -5205, -5602, -5997, | |
| 152 | -6392, -6786, -7179, -7571, -7961, -8351, -8739, -9126, | |
| 153 | -9512, -9896, -10278, -10659, -11039, -11416, -11793, -12167, | |
| 154 | -12539, -12910, -13278, -13645, -14010, -14372, -14732, -15090, | |
| 155 | -15446, -15800, -16151, -16499, -16846, -17189, -17530, -17869, | |
| 156 | -18204, -18537, -18868, -19195, -19519, -19841, -20159, -20475, | |
| 157 | -20787, -21097, -21403, -21706, -22005, -22301, -22594, -22884, | |
| 158 | -23170, -23453, -23732, -24007, -24279, -24547, -24812, -25073, | |
| 159 | -25330, -25583, -25832, -26077, -26319, -26557, -26790, -27020, | |
| 160 | -27245, -27466, -27684, -27897, -28106, -28310, -28511, -28707, | |
| 161 | -28898, -29086, -29269, -29447, -29621, -29791, -29956, -30117, | |
| 162 | -30273, -30425, -30572, -30714, -30852, -30985, -31114, -31237, | |
| 163 | -31357, -31471, -31581, -31685, -31785, -31881, -31971, -32057, | |
| 164 | -32138, -32214, -32285, -32351, -32413, -32469, -32521, -32568, | |
| 165 | -32610, -32647, -32679, -32706, -32728, -32745, -32758, -32765, | |
| 166 | -32767, -32765, -32758, -32745, -32728, -32706, -32679, -32647, | |
| 167 | -32610, -32568, -32521, -32469, -32413, -32351, -32285, -32214, | |
| 168 | -32138, -32057, -31971, -31881, -31785, -31685, -31581, -31471, | |
| 169 | -31357, -31237, -31114, -30985, -30852, -30714, -30572, -30425, | |
| 170 | -30273, -30117, -29956, -29791, -29621, -29447, -29269, -29086, | |
| 171 | -28898, -28707, -28511, -28310, -28106, -27897, -27684, -27466, | |
| 172 | -27245, -27020, -26790, -26557, -26319, -26077, -25832, -25583, | |
| 173 | -25330, -25073, -24812, -24547, -24279, -24007, -23732, -23453, | |
| 174 | -23170, -22884, -22594, -22301, -22005, -21706, -21403, -21097, | |
| 175 | -20787, -20475, -20159, -19841, -19519, -19195, -18868, -18537, | |
| 176 | -18204, -17869, -17530, -17189, -16846, -16499, -16151, -15800, | |
| 177 | -15446, -15090, -14732, -14372, -14010, -13645, -13278, -12910, | |
| 178 | -12539, -12167, -11793, -11416, -11039, -10659, -10278, -9896, | |
| 179 | -9512, -9126, -8739, -8351, -7961, -7571, -7179, -6786, | |
| 180 | -6392, -5997, -5602, -5205, -4808, -4409, -4011, -3611, | |
| 181 | -3211, -2811, -2410, -2009, -1607, -1206, -804, -402, | |
| 182 | 0, 402, 804, 1206, 1607, 2009, 2410, 2811, | |
| 183 | 3211, 3611, 4011, 4409, 4808, 5205, 5602, 5997, | |
| 184 | 6392, 6786, 7179, 7571, 7961, 8351, 8739, 9126, | |
| 185 | 9512, 9896, 10278, 10659, 11039, 11416, 11793, 12167, | |
| 186 | 12539, 12910, 13278, 13645, 14010, 14372, 14732, 15090, | |
| 187 | 15446, 15800, 16151, 16499, 16846, 17189, 17530, 17869, | |
| 188 | 18204, 18537, 18868, 19195, 19519, 19841, 20159, 20475, | |
| 189 | 20787, 21097, 21403, 21706, 22005, 22301, 22594, 22884, | |
| 190 | 23170, 23453, 23732, 24007, 24279, 24547, 24812, 25073, | |
| 191 | 25330, 25583, 25832, 26077, 26319, 26557, 26790, 27020, | |
| 192 | 27245, 27466, 27684, 27897, 28106, 28310, 28511, 28707, | |
| 193 | 28898, 29086, 29269, 29447, 29621, 29791, 29956, 30117, | |
| 194 | 30273, 30425, 30572, 30714, 30852, 30985, 31114, 31237, | |
| 195 | 31357, 31471, 31581, 31685, 31785, 31881, 31971, 32057, | |
| 196 | 32138, 32214, 32285, 32351, 32413, 32469, 32521, 32568, | |
| 197 | 32610, 32647, 32679, 32706, 32728, 32745, 32758, 32765 | |
| 198 | }; |
| r0 | r5770 | |
|---|---|---|
| 1 | /*************************************************************************** | |
| 2 | ||
| 3 | cx4oam.c | |
| 4 | ||
| 5 | Code based on original work by zsKnight, anomie and Nach. | |
| 6 | This implementation is based on C++ "cx4*.cpp" by byuu | |
| 7 | (up to date with source v 0.49). | |
| 8 | ||
| 9 | ***************************************************************************/ | |
| 10 | ||
| 11 | //Build OAM | |
| 12 | void CX4_op00_00(running_machine *machine) | |
| 13 | { | |
| 14 | INT32 i; | |
| 15 | ||
| 16 | UINT32 oamptr = cx4.ram[0x626] << 2; | |
| 17 | UINT16 globalx, globaly; | |
| 18 | UINT32 oamptr2; | |
| 19 | INT16 sprx, spry; | |
| 20 | UINT8 sprname, sprattr; | |
| 21 | UINT8 sprcount; | |
| 22 | UINT8 offset; | |
| 23 | UINT32 srcptr; | |
| 24 | ||
| 25 | for(i = 0x1fd; i > oamptr && i >= 0; i -= 4) | |
| 26 | { | |
| 27 | //clear oam-to-be | |
| 28 | if(i >= 0) | |
| 29 | { | |
| 30 | cx4.ram[i] = 0xe0; | |
| 31 | } | |
| 32 | } | |
| 33 | ||
| 34 | globalx = CX4_readw(0x621); | |
| 35 | globaly = CX4_readw(0x623); | |
| 36 | oamptr2 = 0x200 + (cx4.ram[0x626] >> 2); | |
| 37 | ||
| 38 | if(!cx4.ram[0x620]) | |
| 39 | { | |
| 40 | return; | |
| 41 | } | |
| 42 | ||
| 43 | sprcount = 128 - cx4.ram[0x626]; | |
| 44 | offset = (cx4.ram[0x626] & 3) * 2; | |
| 45 | srcptr = 0x220; | |
| 46 | ||
| 47 | for(i = cx4.ram[0x620]; i > 0 && sprcount > 0; i--, srcptr += 16) | |
| 48 | { | |
| 49 | UINT32 spraddr = CX4_readl(srcptr + 7); | |
| 50 | ||
| 51 | sprx = CX4_readw(srcptr) - globalx; | |
| 52 | spry = CX4_readw(srcptr + 2) - globaly; | |
| 53 | sprname = cx4.ram[srcptr + 5]; | |
| 54 | sprattr = cx4.ram[srcptr + 4] | cx4.ram[srcptr + 6]; | |
| 55 | ||
| 56 | if(memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), spraddr)) | |
| 57 | { | |
| 58 | INT16 x, y; | |
| 59 | INT32 sprcnt; | |
| 60 | for(sprcnt = memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), spraddr++); sprcnt > 0 && sprcount > 0; sprcnt--, spraddr += 4) | |
| 61 | { | |
| 62 | x = (INT8)memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), spraddr + 1); | |
| 63 | if(sprattr & 0x40) | |
| 64 | { | |
| 65 | x = -x - ((memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), spraddr) & 0x20) ? 16 : 8); | |
| 66 | } | |
| 67 | x += sprx; | |
| 68 | if(x >= -16 && x <= 272) | |
| 69 | { | |
| 70 | y = (INT8)memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), spraddr + 2); | |
| 71 | if(sprattr & 0x80) | |
| 72 | { | |
| 73 | y = -y - ((memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), spraddr) & 0x20) ? 16 : 8); | |
| 74 | } | |
| 75 | y += spry; | |
| 76 | if(y >= -16 && y <= 224) | |
| 77 | { | |
| 78 | cx4.ram[oamptr ] = (UINT8)x; | |
| 79 | cx4.ram[oamptr + 1] = (UINT8)y; | |
| 80 | cx4.ram[oamptr + 2] = sprname + memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), spraddr + 3); | |
| 81 | cx4.ram[oamptr + 3] = sprattr ^ (memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), spraddr) & 0xc0); | |
| 82 | cx4.ram[oamptr2] &= ~(3 << offset); | |
| 83 | if(x & 0x100) | |
| 84 | { | |
| 85 | cx4.ram[oamptr2] |= 1 << offset; | |
| 86 | } | |
| 87 | if(memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), spraddr) & 0x20) | |
| 88 | { | |
| 89 | cx4.ram[oamptr2] |= 2 << offset; | |
| 90 | } | |
| 91 | oamptr += 4; | |
| 92 | sprcount--; | |
| 93 | offset = (offset + 2) & 6; | |
| 94 | if(!offset) | |
| 95 | { | |
| 96 | oamptr2++; | |
| 97 | } | |
| 98 | } | |
| 99 | } | |
| 100 | } | |
| 101 | } | |
| 102 | else if(sprcount > 0) | |
| 103 | { | |
| 104 | cx4.ram[oamptr ] = (UINT8)sprx; | |
| 105 | cx4.ram[oamptr + 1] = (UINT8)spry; | |
| 106 | cx4.ram[oamptr + 2] = sprname; | |
| 107 | cx4.ram[oamptr + 3] = sprattr; | |
| 108 | cx4.ram[oamptr2] &= ~(3 << offset); | |
| 109 | if(sprx & 0x100) | |
| 110 | { | |
| 111 | cx4.ram[oamptr2] |= 3 << offset; | |
| 112 | } | |
| 113 | else | |
| 114 | { | |
| 115 | cx4.ram[oamptr2] |= 2 << offset; | |
| 116 | } | |
| 117 | oamptr += 4; | |
| 118 | sprcount--; | |
| 119 | offset = (offset + 2) & 6; | |
| 120 | if(!offset) | |
| 121 | { | |
| 122 | oamptr2++; | |
| 123 | } | |
| 124 | } | |
| 125 | } | |
| 126 | } | |
| 127 | ||
| 128 | //Scale and Rotate | |
| 129 | void CX4_op00_03() | |
| 130 | { | |
| 131 | CX4_C4DoScaleRotate(0); | |
| 132 | } | |
| 133 | ||
| 134 | //Transform Lines | |
| 135 | void CX4_op00_05(running_machine *machine) | |
| 136 | { | |
| 137 | INT32 i; | |
| 138 | UINT32 ptr = 0, ptr2 = 0; | |
| 139 | ||
| 140 | cx4.C4WFX2Val = CX4_read(0x1f83); | |
| 141 | cx4.C4WFY2Val = CX4_read(0x1f86); | |
| 142 | cx4.C4WFDist = CX4_read(0x1f89); | |
| 143 | cx4.C4WFScale = CX4_read(0x1f8c); | |
| 144 | ||
| 145 | //Transform Vertices | |
| 146 | for(i = CX4_readw(0x1f80); i > 0; i--, ptr += 0x10) | |
| 147 | { | |
| 148 | cx4.C4WFXVal = CX4_readw(ptr + 1); | |
| 149 | cx4.C4WFYVal = CX4_readw(ptr + 5); | |
| 150 | cx4.C4WFZVal = CX4_readw(ptr + 9); | |
| 151 | CX4_C4TransfWireFrame(); | |
| 152 | ||
| 153 | //Displace | |
| 154 | CX4_writew(machine, ptr + 1, cx4.C4WFXVal + 0x80); | |
| 155 | CX4_writew(machine, ptr + 5, cx4.C4WFYVal + 0x50); | |
| 156 | } | |
| 157 | ||
| 158 | CX4_writew(machine, 0x600, 23); | |
| 159 | CX4_writew(machine, 0x602, 0x60); | |
| 160 | CX4_writew(machine, 0x605, 0x40); | |
| 161 | CX4_writew(machine, 0x600 + 8, 23); | |
| 162 | CX4_writew(machine, 0x602 + 8, 0x60); | |
| 163 | CX4_writew(machine, 0x605 + 8, 0x40); | |
| 164 | ||
| 165 | ptr = 0xb02; | |
| 166 | ||
| 167 | for(i = CX4_readw(0xb00); i > 0; i--, ptr += 2, ptr2 += 8) | |
| 168 | { | |
| 169 | cx4.C4WFXVal = CX4_readw((CX4_read(ptr + 0) << 4) + 1); | |
| 170 | cx4.C4WFYVal = CX4_readw((CX4_read(ptr + 0) << 4) + 5); | |
| 171 | cx4.C4WFX2Val = CX4_readw((CX4_read(ptr + 1) << 4) + 1); | |
| 172 | cx4.C4WFY2Val = CX4_readw((CX4_read(ptr + 1) << 4) + 5); | |
| 173 | CX4_C4CalcWireFrame(); | |
| 174 | CX4_writew(machine, ptr2 + 0x600, cx4.C4WFDist ? cx4.C4WFDist : 1); | |
| 175 | CX4_writew(machine, ptr2 + 0x602, cx4.C4WFXVal); | |
| 176 | CX4_writew(machine, ptr2 + 0x605, cx4.C4WFYVal); | |
| 177 | } | |
| 178 | } | |
| 179 | ||
| 180 | //Scale and Rotate | |
| 181 | void CX4_op00_07() | |
| 182 | { | |
| 183 | CX4_C4DoScaleRotate(64); | |
| 184 | } | |
| 185 | ||
| 186 | //Draw Wireframe | |
| 187 | void CX4_op00_08(running_machine *machine) | |
| 188 | { | |
| 189 | CX4_C4DrawWireFrame(machine); | |
| 190 | } | |
| 191 | ||
| 192 | //Disintegrate | |
| 193 | void CX4_op00_0b(running_machine *machine) | |
| 194 | { | |
| 195 | UINT8 width, height; | |
| 196 | UINT32 startx, starty; | |
| 197 | UINT32 srcptr; | |
| 198 | UINT32 x, y; | |
| 199 | INT32 scalex, scaley; | |
| 200 | INT32 cx, cy; | |
| 201 | INT32 i, j; | |
| 202 | ||
| 203 | width = CX4_read(0x1f89); | |
| 204 | height = CX4_read(0x1f8c); | |
| 205 | cx = CX4_readw(0x1f80); | |
| 206 | cy = CX4_readw(0x1f83); | |
| 207 | ||
| 208 | scalex = (INT16)CX4_readw(0x1f86); | |
| 209 | scaley = (INT16)CX4_readw(0x1f8f); | |
| 210 | startx = -cx * scalex + (cx << 8); | |
| 211 | starty = -cy * scaley + (cy << 8); | |
| 212 | srcptr = 0x600; | |
| 213 | ||
| 214 | for(i = 0; i < (width * height) >> 1; i++) | |
| 215 | { | |
| 216 | CX4_write(machine, i, 0); | |
| 217 | } | |
| 218 | ||
| 219 | for(y = starty, i = 0;i < height; i++, y += scaley) | |
| 220 | { | |
| 221 | for(x = startx, j = 0;j < width; j++, x += scalex) | |
| 222 | { | |
| 223 | if((x >> 8) < width && (y >> 8) < height && (y >> 8) * width + (x >> 8) < 0x2000) | |
| 224 | { | |
| 225 | UINT8 pixel = (j & 1) ? (cx4.ram[srcptr] >> 4) : (cx4.ram[srcptr]); | |
| 226 | INT32 index = (y >> 11) * width * 4 + (x >> 11) * 32 + ((y >> 8) & 7) * 2; | |
| 227 | UINT8 mask = 0x80 >> ((x >> 8) & 7); | |
| 228 | ||
| 229 | if(pixel & 1) cx4.ram[index ] |= mask; | |
| 230 | if(pixel & 2) cx4.ram[index + 1] |= mask; | |
| 231 | if(pixel & 4) cx4.ram[index + 16] |= mask; | |
| 232 | if(pixel & 8) cx4.ram[index + 17] |= mask; | |
| 233 | } | |
| 234 | if(j & 1) | |
| 235 | { | |
| 236 | srcptr++; | |
| 237 | } | |
| 238 | } | |
| 239 | } | |
| 240 | } | |
| 241 | ||
| 242 | //Bitplane Wave | |
| 243 | void CX4_op00_0c(running_machine *machine) | |
| 244 | { | |
| 245 | int i, j; | |
| 246 | UINT32 destptr = 0; | |
| 247 | UINT32 waveptr = CX4_read(0x1f83); | |
| 248 | UINT16 mask1 = 0xc0c0; | |
| 249 | UINT16 mask2 = 0x3f3f; | |
| 250 | ||
| 251 | for(j = 0; j < 0x10; j++) | |
| 252 | { | |
| 253 | do | |
| 254 | { | |
| 255 | INT16 height = -((INT8)CX4_read(waveptr + 0xb00)) - 16; | |
| 256 | for(i = 0; i < 40; i++) | |
| 257 | { | |
| 258 | UINT16 temp = CX4_readw(destptr + CX4_wave_data[i]) & mask2; | |
| 259 | if(height >= 0) | |
| 260 | { | |
| 261 | if(height < 8) | |
| 262 | { | |
| 263 | temp |= mask1 & CX4_readw(0xa00 + height * 2); | |
| 264 | } | |
| 265 | else | |
| 266 | { | |
| 267 | temp |= mask1 & 0xff00; | |
| 268 | } | |
| 269 | } | |
| 270 | CX4_writew(machine, destptr + CX4_wave_data[i], temp); | |
| 271 | height++; | |
| 272 | } | |
| 273 | waveptr = (waveptr + 1) & 0x7f; | |
| 274 | mask1 = (mask1 >> 2) | (mask1 << 6); | |
| 275 | mask2 = (mask2 >> 2) | (mask2 << 6); | |
| 276 | } while(mask1 != 0xc0c0); | |
| 277 | destptr += 16; | |
| 278 | ||
| 279 | do | |
| 280 | { | |
| 281 | INT16 height = -((INT8)CX4_read(waveptr + 0xb00)) - 16; | |
| 282 | for(i = 0; i < 40; i++) | |
| 283 | { | |
| 284 | UINT16 temp = CX4_readw(destptr + CX4_wave_data[i]) & mask2; | |
| 285 | if(height >= 0) | |
| 286 | { | |
| 287 | if(height < 8) | |
| 288 | { | |
| 289 | temp |= mask1 & CX4_readw(0xa10 + height * 2); | |
| 290 | } | |
| 291 | else | |
| 292 | { | |
| 293 | temp |= mask1 & 0xff00; | |
| 294 | } | |
| 295 | } | |
| 296 | CX4_writew(machine, destptr + CX4_wave_data[i], temp); | |
| 297 | height++; | |
| 298 | } | |
| 299 | waveptr = (waveptr + 1) & 0x7f; | |
| 300 | mask1 = (mask1 >> 2) | (mask1 << 6); | |
| 301 | mask2 = (mask2 >> 2) | (mask2 << 6); | |
| 302 | } while(mask1 != 0xc0c0); | |
| 303 | destptr += 16; | |
| 304 | } | |
| 305 | } |
| r5769 | r5770 | |
|---|---|---|
| 1546 | 1546 | $(MAMESRC)/machine/snesdsp3.c \ |
| 1547 | 1547 | $(MAMESRC)/machine/snesdsp4.c \ |
| 1548 | 1548 | $(MAMESRC)/machine/snesobc1.c \ |
| 1549 | $(MAMESRC)/machine/snescx4.c \ | |
| 1550 | $(MAMESRC)/machine/cx4ops.c \ | |
| 1551 | $(MAMESRC)/machine/cx4oam.c \ | |
| 1552 | $(MAMESRC)/machine/cx4fn.c \ | |
| 1553 | $(MAMESRC)/machine/cx4data.c \ | |
| 1549 | 1554 | $(MAMESRC)/machine/snesrtc.c \ |
| 1550 | 1555 | $(MAMESRC)/machine/snessdd1.c |
| 1551 | 1556 |
| Previous | 15994 Revisions | Next |