Previous 199869 Revisions Next

r32352 Wednesday 24th September, 2014 at 14:34:28 UTC by David Haywood
more functions (nw)
[src/mame/drivers]legionna.c
[src/mame/machine]raiden2cop.c raiden2cop.h

trunk/src/mame/drivers/legionna.c
r32351r32352
109109   
110110   AM_RANGE(0x100432, 0x100433) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_pgm_data_w)
111111   AM_RANGE(0x100434, 0x100435) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_pgm_addr_w)
112//   AM_RANGE(0x100436, 0x100437) AM_WRITE(cop_hitbox_baseadr_w)
112   AM_RANGE(0x100436, 0x100437) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_hitbox_baseadr_w)
113113   AM_RANGE(0x100438, 0x100439) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_pgm_value_w)
114114   AM_RANGE(0x10043a, 0x10043b) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_pgm_mask_w)
115115   AM_RANGE(0x10043c, 0x10043d) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_pgm_trigger_w)
trunk/src/mame/machine/raiden2cop.c
r32351r32352
749749/* Main COP functionality */
750750
751751/*
752(masked) just assumes 0x0080 masked out, actual masking / command selection is more complex, sometimes needs 0x2000 masked out too, but that would cause clashes in some tables
752(masked) just assumes 0x0080 masked out, actual masking / command selection is more complex, it seems bit 0x0001 is masked too (used for sign in 0904 / 0905) and more
753753
754754## - trig (masked) :  (sq0, sq1, sq2, sq3, sq4, sq5, sq6, sq7)  valu  mask
75575500 - 0205 (0205  ) :  (188, 282, 082, b8e, 98e, 000, 000, 000)  6     ffeb   (heatbrl, legionna, cupsoc, godzilla, grainbow, denjinmk, raiden2, raidendx, zeroteam, xsedae)
r32351r32352
764764   space.write_word(cop_regs[0] + 0x1e + offset * 4, space.read_word(cop_regs[0] + 0x1e + offset * 4) + delta);
765765}
766766
767void raiden2cop_device::LEGACY_execute_0205(address_space &space, int offset, UINT16 data)
768{
769   UINT8 offs;
770
771   offs = (offset & 3) * 4;
772   int ppos = space.read_dword(cop_regs[0] + 4 + offs);
773   int npos = ppos + space.read_dword(cop_regs[0] + 0x10 + offs);
774   int delta = (npos >> 16) - (ppos >> 16);
775
776   space.write_dword(cop_regs[0] + 4 + offs, npos);
777   space.write_word(cop_regs[0] + 0x1c + offs, space.read_word(cop_regs[0] + 0x1c + offs) + delta);
778}
779
767780/*
76878101 - 0905 (0905  ) :  (194, 288, 088, 000, 000, 000, 000, 000)  6     fbfb   (heatbrl, legionna, cupsoc, godzilla, grainbow, denjinmk, raiden2, raidendx, zeroteam, xsedae)
76978201 - 0b05 (0b05  ) :  (180, 2e0, 0a0, 182, 2e0, 0c0, 000, 000)  6     ffdb   (zeroteamsr)
r32351r32352
781794   space.write_dword(cop_regs[0] + 16 + offset * 4, space.read_dword(cop_regs[0] + 16 + offset * 4) + space.read_dword(cop_regs[0] + 0x28 + offset * 4));
782795}
783796
797void raiden2cop_device::LEGACY_execute_0905(address_space &space, int offset, UINT16 data)
798{
799   UINT8 offs;
784800
801   offs = (offset & 3) * 4;
802
803   /* read 0x28 + offs */
804   /* add 0x10 + offs */
805   /* write 0x10 + offs */
806
807   space.write_dword(cop_regs[0] + 0x10 + offs, space.read_dword(cop_regs[0] + 0x10 + offs) + space.read_dword(cop_regs[0] + 0x28 + offs));
808
809}
810
785811/*
78681202 - 138e (130e  ) :  (984, aa4, d82, aa2, 39b, b9a, b9a, b9a)  5     bf7f   (heatbrl, legionna)
78781302 - 138e (130e  ) :  (984, aa4, d82, aa2, 39b, b9a, b9a, a9a)  5     bf7f   (cupsoc, godzilla, grainbow, denjinmk)
r32351r32352
795821   execute_338e(space, offset, data);
796822}
797823
824void raiden2cop_device::LEGACY_execute_130e(address_space &space, int offset, UINT16 data)
825{
826   int dy = space.read_dword(cop_regs[1] + 4) - space.read_dword(cop_regs[0] + 4);
827   int dx = space.read_dword(cop_regs[1] + 8) - space.read_dword(cop_regs[0] + 8);
828
829   cop_status = 7;
830   if (!dx) {
831      cop_status |= 0x8000;
832      cop_angle = 0;
833   }
834   else {
835      cop_angle = atan(double(dy) / double(dx)) * 128.0 / M_PI;
836      if (dx < 0)
837         cop_angle += 0x80;
838   }
839
840   cop_angle -= 0x80;
841   m_LEGACY_r0 = dy;
842   m_LEGACY_r1 = dx;
843
844   if (data & 0x80)
845      space.write_word(cop_regs[0] + (0x34 ^ 2), cop_angle);
846}
847
848void raiden2cop_device::LEGACY_execute_130e_cupsoc(address_space &space, int offset, UINT16 data)
849{
850   int dy = space.read_dword(cop_regs[1] + 4) - space.read_dword(cop_regs[0] + 4);
851   int dx = space.read_dword(cop_regs[1] + 8) - space.read_dword(cop_regs[0] + 8);
852
853   cop_status = 7;
854   if (!dx) {
855      cop_status |= 0x8000;
856      cop_angle = 0;
857   }
858   else {
859      cop_angle = atan(double(dy) / double(dx)) * 128.0 / M_PI;
860      if (dx < 0)
861         cop_angle += 0x80;
862   }
863
864   m_LEGACY_r0 = dy;
865   m_LEGACY_r1 = dx;
866
867   //printf("%d %d %f %04x\n",dx,dy,atan(double(dy)/double(dx)) * 128 / M_PI,cop_angle);
868
869   if (data & 0x80)
870      space.write_word(cop_regs[0] + (0x34 ^ 2), cop_angle);
871}
872
798873/*
79987403 - 1905 (1905  ) :  (994, a88, 088, 000, 000, 000, 000, 000)  6     fbfb   (heatbrl, legionna, cupsoc, godzilla, grainbow, denjinmk, raiden2, raidendx, zeroteam, xsedae)
800875*/
r32351r32352
885960      space.write_word(cop_regs[0] + (data & 0x200 ? 0x3a : 0x38), cop_dist);
886961}
887962
963void raiden2cop_device::LEGACY_execute_3b30(address_space &space, int offset, UINT16 data)
964{
965   int dy = m_LEGACY_r0;
966   int dx = m_LEGACY_r1;
888967
968   dx >>= 16;
969   dy >>= 16;
970   cop_dist = sqrt((double)(dx*dx + dy*dy));
971
972   if (data & 0x80)
973      space.write_word(cop_regs[0] + (0x38), cop_dist);
974}
975
889976/*
89097708 - 42c2 (4242  ) :  (f9a, b9a, b9c, b9c, b9c, 29c, 000, 000)  5     fcdd   (heatbrl, legionna, cupsoc, godzilla, grainbow, denjinmk, raiden2, raidendx, zeroteam, xsedae)
891978*/
r32351r32352
901988   space.write_word(cop_regs[0] + (0x38), (cop_dist << (5 - cop_scale)) / div);
902989}
903990
991void raiden2cop_device::LEGACY_execute_42c2(address_space &space, int offset, UINT16 data)
992{
993   int dy = m_LEGACY_r0;
994   int dx = m_LEGACY_r1;
995   int div = space.read_word(cop_regs[0] + (0x36 ^ 2));
996   int res;
997   int cop_dist_raw;
904998
999   if (!div)
1000   {
1001      printf("divide by zero?\n");
1002      div = 1;
1003   }
1004
1005   /* TODO: calculation of this one should occur at 0x3b30/0x3bb0 I *think* */
1006   /* TODO: recheck if cop_scale still masks at 3 with this command */
1007   dx >>= 11 + cop_scale;
1008   dy >>= 11 + cop_scale;
1009   cop_dist_raw = sqrt((double)(dx*dx + dy*dy));
1010
1011   res = cop_dist_raw;
1012   res /= div;
1013
1014   cop_dist = (1 << (5 - cop_scale)) / div;
1015
1016   /* TODO: bits 5-6-15 */
1017   cop_status = 7;
1018
1019   space.write_word(cop_regs[0] + (0x38 ^ 2), res);
1020
1021}
1022
9051023/*
906102409 - 4aa0 (4a20  ) :  (f9a, b9a, b9c, b9c, b9c, 99b, 000, 000)  5     fcdd   (heatbrl, legionna, cupsoc, godzilla, grainbow, denjinmk, raiden2, raidendx, zeroteam, xsedae)
9071025*/
r32351r32352
9731091   space.write_byte(cop_regs[0] + 0x34, angle);
9741092}
9751093
1094void raiden2cop_device::LEGACY_execute_6200(address_space &space, int offset, UINT16 data)
1095{
1096   UINT8 cur_angle;
1097   UINT16 flags;
1098
1099   /* 0 [1] */
1100   /* 0xc [1] */
1101   /* 0 [0] */
1102   /* 0 [1] */
1103   /* 0xc [1] */
1104
1105   cur_angle = space.read_byte(cop_regs[1] + (0xc ^ 3));
1106   flags = space.read_word(cop_regs[1]);
1107   //space.write_byte(cop_regs[1] + (0^3),space.read_byte(cop_regs[1] + (0^3)) & 0xfb); //correct?
1108
1109   INT8 tempangle_compare = (INT8)cop_angle_target;
1110   INT8 tempangle_mod_val = (INT8)cop_angle_step;
1111
1112   tempangle_compare &= 0xff;
1113   tempangle_mod_val &= 0xff;
1114
1115   cop_angle_target = tempangle_compare;
1116   cop_angle_step = tempangle_mod_val;
1117
1118   flags &= ~0x0004;
1119
1120   int delta = cur_angle - tempangle_compare;
1121   if (delta >= 128)
1122      delta -= 256;
1123   else if (delta < -128)
1124      delta += 256;
1125   if (delta < 0)
1126   {
1127      if (delta >= -tempangle_mod_val)
1128      {
1129         cur_angle = tempangle_compare;
1130         flags |= 0x0004;
1131      }
1132      else
1133         cur_angle += tempangle_mod_val;
1134   }
1135   else
1136   {
1137      if (delta <= tempangle_mod_val)
1138      {
1139         cur_angle = tempangle_compare;
1140         flags |= 0x0004;
1141      }
1142      else
1143         cur_angle -= tempangle_mod_val;
1144   }
1145
1146   space.write_byte(cop_regs[1] + (0 ^ 2), flags);
1147   space.write_byte(cop_regs[1] + (0xc ^ 3), cur_angle);
1148}
1149
1150void raiden2cop_device::LEGACY_execute_6200_grainbow(address_space &space, int offset, UINT16 data)
1151{
1152   UINT8 cur_angle;
1153   UINT16 flags;
1154
1155   cur_angle = space.read_byte(cop_regs[0] + (0x34 ^ 3));
1156   flags = space.read_word(cop_regs[0] + (0 ^ 2));
1157   //space.write_byte(cop_regs[1] + (0^3),space.read_byte(cop_regs[1] + (0^3)) & 0xfb); //correct?
1158
1159   INT8 tempangle_compare = (INT8)cop_angle_target;
1160   INT8 tempangle_mod_val = (INT8)cop_angle_step;
1161
1162   tempangle_compare &= 0xff;
1163   tempangle_mod_val &= 0xff;
1164
1165   cop_angle_target = tempangle_compare;
1166   cop_angle_step = tempangle_mod_val;
1167
1168
1169   flags &= ~0x0004;
1170
1171   int delta = cur_angle - tempangle_compare;
1172   if (delta >= 128)
1173      delta -= 256;
1174   else if (delta < -128)
1175      delta += 256;
1176   if (delta < 0)
1177   {
1178      if (delta >= -tempangle_mod_val)
1179      {
1180         cur_angle = tempangle_compare;
1181         flags |= 0x0004;
1182      }
1183      else
1184         cur_angle += tempangle_mod_val;
1185   }
1186   else
1187   {
1188      if (delta <= tempangle_mod_val)
1189      {
1190         cur_angle = tempangle_compare;
1191         flags |= 0x0004;
1192      }
1193      else
1194         cur_angle -= tempangle_mod_val;
1195   }
1196
1197   space.write_byte(cop_regs[0] + (0 ^ 3), flags);
1198   space.write_word(cop_regs[0] + (0x34 ^ 3), cur_angle);
1199}
1200
9761201/*
9771202
97812030d - 6880 (6800  ) :  (b80, ba0, 000, 000, 000, 000, 000, 000)  a     fff3   (heatbrl, legionna, cupsoc, godzilla, denjinmk)
97912040d - 6980 (6900  ) :  (b80, ba0, 000, 000, 000, 000, 000, 000)  a     fff3   (grainbow, zeroteam, xsedae)
1205*/
1206void raiden2cop_device::LEGACY_execute_6980(address_space &space, int offset, UINT16 data)
1207{
1208   UINT8 offs;
1209   int abs_x, abs_y, rel_xy;
9801210
1211   offs = (offset & 3) * 4;
1212
1213   /* TODO: I really suspect that following two are actually taken from the 0xa180 macro command then internally loaded */
1214   abs_x = space.read_word(cop_regs[0] + 8) - m_cop_sprite_dma_abs_x;
1215   abs_y = space.read_word(cop_regs[0] + 4) - m_cop_sprite_dma_abs_y;
1216   rel_xy = space.read_word(m_cop_sprite_dma_src + 4 + offs);
1217
1218   //if(rel_xy & 0x0706)
1219   //  printf("sprite rel_xy = %04x\n",rel_xy);
1220
1221   if (rel_xy & 1)
1222      space.write_word(cop_regs[4] + offs + 4, 0xc0 + abs_x - (rel_xy & 0xf8));
1223   else
1224      space.write_word(cop_regs[4] + offs + 4, (((rel_xy & 0x78) + (abs_x)-((rel_xy & 0x80) ? 0x80 : 0))));
1225
1226   space.write_word(cop_regs[4] + offs + 6, (((rel_xy & 0x7800) >> 8) + (abs_y)-((rel_xy & 0x8000) ? 0x80 : 0)));
1227}
1228
1229/*
1230
98112310e - 7100 (7100  ) :  (b80, a80, b80, 000, 000, 000, 000, 000)  8     fdfd   (zeroteam, xsedae)
9821232
98312330f - 7905 (7905  ) :  (1a2, 2c2, 0a2, 000, 000, 000, 000, 000)  6     fffb   (cupsoc, grainbow)
r32351r32352
10461296{
10471297   cop_collision_read_pos(space, 0, cop_regs[0], data & 0x0080);
10481298}
1299
1300void raiden2cop_device::LEGACY_execute_a100(address_space &space, int offset, UINT16 data)
1301{
1302   m_LEGACY_cop_collision_info[0].y = (space.read_dword(cop_regs[0] + 4));
1303   m_LEGACY_cop_collision_info[0].x = (space.read_dword(cop_regs[0] + 8));
1304}
1305
10491306/*
1050130715 - a900 (a900  ) :  (ba0, ba2, ba4, ba6, 000, 000, 000, 000)  f     ffff   (heatbrl, zeroteam, xsedae)
1051130815 - a980 (a900  ) :  (ba0, ba2, ba4, ba6, 000, 000, 000, 000)  f     ffff   (legionna, cupsoc, godzilla, denjinmk)
r32351r32352
10561313{
10571314   cop_collision_read_pos(space, 1, cop_regs[1], data & 0x0080);
10581315}
1316
1317void raiden2cop_device::LEGACY_execute_a900(address_space &space, int offset, UINT16 data)
1318{
1319   m_LEGACY_cop_collision_info[1].y = (space.read_dword(cop_regs[1] + 4));
1320   m_LEGACY_cop_collision_info[1].x = (space.read_dword(cop_regs[1] + 8));
1321}
1322
10591323/*
1060132416 - b080 (b000  ) :  (b40, bc0, bc2, 000, 000, 000, 000, 000)  9     ffff   (heatbrl)
1061132516 - b100 (b100  ) :  (b40, bc0, bc2, 000, 000, 000, 000, 000)  9     ffff   (legionna, cupsoc, godzilla, grainbow, denjinmk, raiden2, raidendx, zeroteam, xsedae)
r32351r32352
10641328{
10651329   cop_collision_update_hitbox(space, 0, cop_regs[2]);
10661330}
1331
1332void raiden2cop_device::LEGACY_execute_b100(address_space &space, int offset, UINT16 data)
1333{
1334   m_LEGACY_cop_collision_info[0].hitbox = space.read_word(cop_regs[2]);
1335   m_LEGACY_cop_collision_info[0].hitbox_y = space.read_word((cop_regs[2] & 0xffff0000) | (m_LEGACY_cop_collision_info[0].hitbox));
1336   m_LEGACY_cop_collision_info[0].hitbox_x = space.read_word(((cop_regs[2] & 0xffff0000) | (m_LEGACY_cop_collision_info[0].hitbox)) + 2);
1337
1338   /* do the math */
1339   LEGACY_cop_take_hit_box_params(0);
1340   cop_hit_status = LEGACY_cop_calculate_collsion_detection();
1341}
1342
10671343/*
1068134417 - b880 (b800  ) :  (b60, be0, be2, 000, 000, 000, 000, 000)  6     ffff   (heatbrl)
1069134517 - b900 (b900  ) :  (b60, be0, be2, 000, 000, 000, 000, 000)  6     ffff   (legionna, cupsoc, godzilla, grainbow, denjinmk, raiden2, raidendx, zeroteam, xsedae)
r32351r32352
10731349   cop_collision_update_hitbox(space, 1, cop_regs[3]);
10741350}
10751351
1352void raiden2cop_device::LEGACY_execute_b900(address_space &space, int offset, UINT16 data)
1353{
1354   m_LEGACY_cop_collision_info[1].hitbox = space.read_word(cop_regs[3]);
1355   m_LEGACY_cop_collision_info[1].hitbox_y = space.read_word((cop_regs[3] & 0xffff0000) | (m_LEGACY_cop_collision_info[1].hitbox));
1356   m_LEGACY_cop_collision_info[1].hitbox_x = space.read_word(((cop_regs[3] & 0xffff0000) | (m_LEGACY_cop_collision_info[1].hitbox)) + 2);
1357
1358   /* do the math */
1359   LEGACY_cop_take_hit_box_params(1);
1360   cop_hit_status = LEGACY_cop_calculate_collsion_detection();
1361}
1362
10761363/*
1077136418 - c480 (c400  ) :  (080, 882, 000, 000, 000, 000, 000, 000)  a     ff00   (heatbrl, legionna, cupsoc, godzilla, grainbow, denjinmk)
1078136518 - 7c80 (7c00  ) :  (080, 882, 000, 000, 000, 000, 000, 000)  a     ff00   (zeroteam, xsedae)
1366*/
10791367
1368void raiden2cop_device::LEGACY_execute_c480(address_space &space, int offset, UINT16 data)
1369{
1370   UINT8 offs;
1371
1372   offs = (offset & 3) * 4;
1373
1374   space.write_word(cop_regs[4] + offs + 0, space.read_word(m_cop_sprite_dma_src + offs) + (m_cop_sprite_dma_param & 0x3f));
1375   //space.write_word(cop_regs[4] + offs + 2,space.read_word(m_cop_sprite_dma_src+2 + offs));
1376
1377}
1378
1379/*
1080138019 - cb8f (cb0f  ) :  (984, aa4, d82, aa2, 39b, b9a, b9a, a9f)  5     bf7f   (cupsoc, grainbow)
10811381
108213821a - d104 (d104  ) :  (ac2, 9e0, 0a2, 000, 000, 000, 000, 000)  5     fffb   (cupsoc, grainbow)
1383*/
1384void raiden2cop_device::LEGACY_execute_d104(address_space &space, int offset, UINT16 data)
1385{
1386   UINT8 *ROM = space.machine().root_device().memregion("maincpu")->base();
1387   UINT32 rom_addr = (m_cop_rom_addr_hi << 16 | m_cop_rom_addr_lo) & ~1;
1388   UINT16 rom_data = (ROM[rom_addr + 0]) | (ROM[rom_addr + 1] << 8);
10831389
1390   /* writes to some unemulated COP registers, then puts the result in here, adding a parameter taken from ROM */
1391   //space.write_word(cop_regs[0]+(0x44 + offset * 4), rom_data);
1392
1393   logerror("%04x%04x %04x %04x\n", m_cop_rom_addr_hi, m_cop_rom_addr_lo, m_cop_rom_addr_unk, rom_data);
1394}
1395/*
108413961b - dde5 (dd65  ) :  (f80, aa2, 984, 0c2, 000, 000, 000, 000)  5     7ff7   (cupsoc, grainbow)
1397*/
10851398
1399void raiden2cop_device::LEGACY_execute_dde5(address_space &space, int offset, UINT16 data)
1400{
1401   UINT8 offs;
1402   int div;
1403   INT16 dir_offset;
1404   //              INT16 offs_val;
1405
1406   /* TODO: [4-7] could be mirrors of [0-3] (this is the only command so far that uses 4-7 actually)*/
1407   /* ? 0 + [4] */
1408   /* sub32 4 + [5] */
1409   /* write16h 8 + [4] */
1410   /* addmem16 4 + [6] */
1411
1412   // these two are obvious ...
1413   // 0xf x 16 = 240
1414   // 0x14 x 16 = 320
1415   // what are these two instead? scale factor? offsets? (edit: offsets to apply from the initial sprite data)
1416   // 0xfc69 ?
1417   // 0x7f4 ?
1418   //printf("%08x %08x %08x %08x %08x %08x %08x\n",cop_regs[0],cop_regs[1],cop_regs[2],cop_regs[3],cop_regs[4],cop_regs[5],cop_regs[6]);
1419
1420   offs = (offset & 3) * 4;
1421
1422   div = space.read_word(cop_regs[4] + offs);
1423   dir_offset = space.read_word(cop_regs[4] + offs + 8);
1424   //              offs_val = space.read_word(cop_regs[3] + offs);
1425   //420 / 180 = 500 : 400 = 30 / 50 = 98 / 18
1426
1427   /* TODO: this probably trips a cop status flag */
1428   if (div == 0) { div = 1; }
1429
1430
1431   space.write_word((cop_regs[6] + offs + 4), ((space.read_word(cop_regs[5] + offs + 4) + dir_offset) / div));
1432}
1433
1434/*
108614351c - e38e (e30e  ) :  (984, ac4, d82, ac2, 39b, b9a, b9a, a9a)  5     b07f   (cupsoc, grainbow)
108714361c - e105 (e105  ) :  (a88, 994, 088, 000, 000, 000, 000, 000)  5     06fb   (zeroteam, xsedae)
1437*/
10881438
1439void raiden2cop_device::LEGACY_execute_e30e(address_space &space, int offset, UINT16 data)
1440{
1441   int dy = space.read_dword(cop_regs[2] + 4) - space.read_dword(cop_regs[0] + 4);
1442   int dx = space.read_dword(cop_regs[2] + 8) - space.read_dword(cop_regs[0] + 8);
1443
1444   cop_status = 7;
1445   if (!dx) {
1446      cop_status |= 0x8000;
1447      cop_angle = 0;
1448   }
1449   else {
1450      cop_angle = atan(double(dy) / double(dx)) * 128.0 / M_PI;
1451      if (dx < 0)
1452         cop_angle += 0x80;
1453   }
1454
1455   m_LEGACY_r0 = dy;
1456   m_LEGACY_r1 = dx;
1457
1458   //printf("%d %d %f %04x\n",dx,dy,atan(double(dy)/double(dx)) * 128 / M_PI,cop_angle);
1459
1460   if (data & 0x80)
1461      space.write_word(cop_regs[0] + (0x34 ^ 2), cop_angle);
1462}
1463
1464/*
108914651d - eb8e (eb0e  ) :  (984, ac4, d82, ac2, 39b, b9a, b9a, a9f)  5     b07f   (cupsoc, grainbow)
109014661d - ede5 (ed65  ) :  (f88, a84, 986, 08a, 000, 000, 000, 000)  5     05f7   (zeroteam, xsedae)
10911467
r32351r32352
16061982   dword ^= 0
16071983   word ^= 2
16081984   byte ^= 3
1609   - some macro commands here have a commented algorithm, it's how Seibu Cup Bootleg version handles maths inside the 14/15 roms.
1985   - some macro commands here have a commented algorithm, it's how Seibu Cup **BOOTLEG** version handles maths inside the 14/15 roms.
16101986   The ROMs map tables in the following arrangement:
16111987   0x00000 - 0x1ffff Sine math results
16121988   0x20000 - 0x3ffff Cosine math results
r32351r32352
16211997   if (check_command_matches(command, 0x188, 0x282, 0x082, 0xb8e, 0x98e, 0x000, 0x000, 0x000, 6, 0xffeb))
16221998   {
16231999      executed = 1;
1624      UINT8 offs;
1625
1626      offs = (offset & 3) * 4;
1627      int ppos = space.read_dword(cop_regs[0] + 4 + offs);
1628      int npos = ppos + space.read_dword(cop_regs[0] + 0x10 + offs);
1629      int delta = (npos >> 16) - (ppos >> 16);
1630
1631      space.write_dword(cop_regs[0] + 4 + offs, npos);
1632      space.write_word(cop_regs[0] + 0x1c + offs, space.read_word(cop_regs[0] + 0x1c + offs) + delta);
2000      LEGACY_execute_0205(space, offset, data);
16332001      return;
16342002   }
16352003
r32351r32352
16372005   if (check_command_matches(command, 0x194, 0x288, 0x088, 0x000, 0x000, 0x000, 0x000, 0x000, 6, 0xfbfb))
16382006   {
16392007      executed = 1;
1640      UINT8 offs;
1641
1642      offs = (offset & 3) * 4;
1643
1644      /* read 0x28 + offs */
1645      /* add 0x10 + offs */
1646      /* write 0x10 + offs */
1647
1648      space.write_dword(cop_regs[0] + 0x10 + offs, space.read_dword(cop_regs[0] + 0x10 + offs) + space.read_dword(cop_regs[0] + 0x28 + offs));
2008      LEGACY_execute_0905(space, offset, data);
16492009      return;
16502010   }
16512011
r32351r32352
16912051   if (check_command_matches(command, 0x984, 0xaa4, 0xd82, 0xaa2, 0x39b, 0xb9a, 0xb9a, 0xa9a, 5, 0xbf7f))
16922052   {
16932053      executed = 1;
1694      int dy = space.read_dword(cop_regs[1] + 4) - space.read_dword(cop_regs[0] + 4);
1695      int dx = space.read_dword(cop_regs[1] + 8) - space.read_dword(cop_regs[0] + 8);
1696
1697      cop_status = 7;
1698      if (!dx) {
1699         cop_status |= 0x8000;
1700         cop_angle = 0;
1701      }
1702      else {
1703         cop_angle = atan(double(dy) / double(dx)) * 128.0 / M_PI;
1704         if (dx < 0)
1705            cop_angle += 0x80;
1706      }
1707
1708      m_LEGACY_r0 = dy;
1709      m_LEGACY_r1 = dx;
1710
1711      //printf("%d %d %f %04x\n",dx,dy,atan(double(dy)/double(dx)) * 128 / M_PI,cop_angle);
1712
1713      if (data & 0x80)
1714         space.write_word(cop_regs[0] + (0x34 ^ 2), cop_angle);
2054      LEGACY_execute_130e_cupsoc(space, offset, data);
17152055      return;
17162056   }
17172057
r32351r32352
17202060   if (check_command_matches(command, 0x984, 0xaa4, 0xd82, 0xaa2, 0x39b, 0xb9a, 0xb9a, 0xb9a, 5, 0xbf7f))
17212061   {
17222062      executed = 1;
1723      int dy = space.read_dword(cop_regs[1] + 4) - space.read_dword(cop_regs[0] + 4);
1724      int dx = space.read_dword(cop_regs[1] + 8) - space.read_dword(cop_regs[0] + 8);
1725
1726      cop_status = 7;
1727      if (!dx) {
1728         cop_status |= 0x8000;
1729         cop_angle = 0;
1730      }
1731      else {
1732         cop_angle = atan(double(dy) / double(dx)) * 128.0 / M_PI;
1733         if (dx < 0)
1734            cop_angle += 0x80;
1735      }
1736
1737      cop_angle -= 0x80;
1738      m_LEGACY_r0 = dy;
1739      m_LEGACY_r1 = dx;
1740
1741      if (data & 0x80)
1742         space.write_word(cop_regs[0] + (0x34 ^ 2), cop_angle);
2063      LEGACY_execute_130e(space, offset, data);
17432064      return;
17442065   }
17452066
r32351r32352
17542075   if (check_command_matches(command, 0xf9c, 0xb9c, 0xb9c, 0xb9c, 0xb9c, 0xb9c, 0xb9c, 0x99c, 4, 0x007f))
17552076   {
17562077      executed = 1;
1757      int dy = m_LEGACY_r0;
1758      int dx = m_LEGACY_r1;
1759
1760      dx >>= 16;
1761      dy >>= 16;
1762      cop_dist = sqrt((double)(dx*dx + dy*dy));
1763
1764      if (data & 0x80)
1765         space.write_word(cop_regs[0] + (0x38), cop_dist);
2078      LEGACY_execute_3b30(space, offset, data);
17662079      return;
17672080   }
17682081
r32351r32352
17802093   if (check_command_matches(command, 0xf9a, 0xb9a, 0xb9c, 0xb9c, 0xb9c, 0x29c, 0x000, 0x000, 5, 0xfcdd))
17812094   {
17822095      executed = 1;
1783      int dy = m_LEGACY_r0;
1784      int dx = m_LEGACY_r1;
1785      int div = space.read_word(cop_regs[0] + (0x36 ^ 2));
1786      int res;
1787      int cop_dist_raw;
1788
1789      if (!div)
1790      {
1791         printf("divide by zero?\n");
1792         div = 1;
1793      }
1794
1795      /* TODO: calculation of this one should occur at 0x3b30/0x3bb0 I *think* */
1796      /* TODO: recheck if cop_scale still masks at 3 with this command */
1797      dx >>= 11 + cop_scale;
1798      dy >>= 11 + cop_scale;
1799      cop_dist_raw = sqrt((double)(dx*dx + dy*dy));
1800
1801      res = cop_dist_raw;
1802      res /= div;
1803
1804      cop_dist = (1 << (5 - cop_scale)) / div;
1805
1806      /* TODO: bits 5-6-15 */
1807      cop_status = 7;
1808
1809      space.write_word(cop_regs[0] + (0x38 ^ 2), res);
2096      LEGACY_execute_42c2(space, offset, data);
18102097      return;
18112098   }
18122099
r32351r32352
18252112
18262113   if (check_command_matches(command, 0xb80, 0xb82, 0xb84, 0xb86, 0x000, 0x000, 0x000, 0x000, funcval, funcmask))
18272114   {
2115      LEGACY_execute_a100(space, offset, data);
18282116      executed = 1;
1829      m_LEGACY_cop_collision_info[0].y = (space.read_dword(cop_regs[0] + 4));
1830      m_LEGACY_cop_collision_info[0].x = (space.read_dword(cop_regs[0] + 8));
18312117      return;
18322118   }
18332119
r32351r32352
18352121   if (check_command_matches(command, 0xb40, 0xbc0, 0xbc2, 0x000, 0x000, 0x000, 0x000, 0x000, funcval, funcmask))
18362122   {
18372123      executed = 1;
1838      m_LEGACY_cop_collision_info[0].hitbox = space.read_word(cop_regs[2]);
1839      m_LEGACY_cop_collision_info[0].hitbox_y = space.read_word((cop_regs[2] & 0xffff0000) | (m_LEGACY_cop_collision_info[0].hitbox));
1840      m_LEGACY_cop_collision_info[0].hitbox_x = space.read_word(((cop_regs[2] & 0xffff0000) | (m_LEGACY_cop_collision_info[0].hitbox)) + 2);
1841
1842      /* do the math */
1843      LEGACY_cop_take_hit_box_params(0);
1844      cop_hit_status = LEGACY_cop_calculate_collsion_detection();
1845
2124      LEGACY_execute_b100(space, offset, data);
18462125      return;
18472126   }
18482127
18492128   if (check_command_matches(command, 0xba0, 0xba2, 0xba4, 0xba6, 0x000, 0x000, 0x000, 0x000, funcval, funcmask))
18502129   {
18512130      executed = 1;
1852      m_LEGACY_cop_collision_info[1].y = (space.read_dword(cop_regs[1] + 4));
1853      m_LEGACY_cop_collision_info[1].x = (space.read_dword(cop_regs[1] + 8));
2131      LEGACY_execute_a900(space, offset, data);
18542132      return;
18552133   }
18562134
r32351r32352
18582136   if (check_command_matches(command, 0xb60, 0xbe0, 0xbe2, 0x000, 0x000, 0x000, 0x000, 0x000, funcval, funcmask))
18592137   {
18602138      executed = 1;
1861      m_LEGACY_cop_collision_info[1].hitbox = space.read_word(cop_regs[3]);
1862      m_LEGACY_cop_collision_info[1].hitbox_y = space.read_word((cop_regs[3] & 0xffff0000) | (m_LEGACY_cop_collision_info[1].hitbox));
1863      m_LEGACY_cop_collision_info[1].hitbox_x = space.read_word(((cop_regs[3] & 0xffff0000) | (m_LEGACY_cop_collision_info[1].hitbox)) + 2);
1864
1865      /* do the math */
1866      LEGACY_cop_take_hit_box_params(1);
1867      cop_hit_status = LEGACY_cop_calculate_collsion_detection();
2139      LEGACY_execute_b900(space, offset, data);
18682140      return;
18692141   }
18702142
r32351r32352
18722144   if (check_command_matches(command, 0xb80, 0xba0, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 10, 0xfff3))
18732145   {
18742146      executed = 1;
1875      UINT8 offs;
1876      int abs_x, abs_y, rel_xy;
1877
1878      offs = (offset & 3) * 4;
1879
1880      /* TODO: I really suspect that following two are actually taken from the 0xa180 macro command then internally loaded */
1881      abs_x = space.read_word(cop_regs[0] + 8) - m_cop_sprite_dma_abs_x;
1882      abs_y = space.read_word(cop_regs[0] + 4) - m_cop_sprite_dma_abs_y;
1883      rel_xy = space.read_word(m_cop_sprite_dma_src + 4 + offs);
1884
1885      //if(rel_xy & 0x0706)
1886      //  printf("sprite rel_xy = %04x\n",rel_xy);
1887
1888      if (rel_xy & 1)
1889         space.write_word(cop_regs[4] + offs + 4, 0xc0 + abs_x - (rel_xy & 0xf8));
1890      else
1891         space.write_word(cop_regs[4] + offs + 4, (((rel_xy & 0x78) + (abs_x)-((rel_xy & 0x80) ? 0x80 : 0))));
1892
1893      space.write_word(cop_regs[4] + offs + 6, (((rel_xy & 0x7800) >> 8) + (abs_y)-((rel_xy & 0x8000) ? 0x80 : 0)));
2147      LEGACY_execute_6980(space, offset, data);
18942148      return;
18952149   }
18962150
r32351r32352
18982152   if (check_command_matches(command, 0x080, 0x882, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 10, 0xff00))
18992153   {
19002154      executed = 1;
1901      UINT8 offs;
1902
1903      offs = (offset & 3) * 4;
1904
1905      space.write_word(cop_regs[4] + offs + 0, space.read_word(m_cop_sprite_dma_src + offs) + (m_cop_sprite_dma_param & 0x3f));
1906      //space.write_word(cop_regs[4] + offs + 2,space.read_word(m_cop_sprite_dma_src+2 + offs));
2155      LEGACY_execute_c480(space, offset, data);
19072156      return;
19082157   }
19092158
r32351r32352
19142163   if (check_command_matches(command, 0xf80, 0xaa2, 0x984, 0x0c2, 0x000, 0x000, 0x000, 0x000, 5, 0x7ff7))
19152164   {
19162165      executed = 1;
1917      UINT8 offs;
1918      int div;
1919      INT16 dir_offset;
1920      //              INT16 offs_val;
1921
1922      /* TODO: [4-7] could be mirrors of [0-3] (this is the only command so far that uses 4-7 actually)*/
1923      /* ? 0 + [4] */
1924      /* sub32 4 + [5] */
1925      /* write16h 8 + [4] */
1926      /* addmem16 4 + [6] */
1927
1928      // these two are obvious ...
1929      // 0xf x 16 = 240
1930      // 0x14 x 16 = 320
1931      // what are these two instead? scale factor? offsets? (edit: offsets to apply from the initial sprite data)
1932      // 0xfc69 ?
1933      // 0x7f4 ?
1934      //printf("%08x %08x %08x %08x %08x %08x %08x\n",cop_regs[0],cop_regs[1],cop_regs[2],cop_regs[3],cop_regs[4],cop_regs[5],cop_regs[6]);
1935
1936      offs = (offset & 3) * 4;
1937
1938      div = space.read_word(cop_regs[4] + offs);
1939      dir_offset = space.read_word(cop_regs[4] + offs + 8);
1940      //              offs_val = space.read_word(cop_regs[3] + offs);
1941      //420 / 180 = 500 : 400 = 30 / 50 = 98 / 18
1942
1943      /* TODO: this probably trips a cop status flag */
1944      if (div == 0) { div = 1; }
1945
1946
1947      space.write_word((cop_regs[6] + offs + 4), ((space.read_word(cop_regs[5] + offs + 4) + dir_offset) / div));
2166      LEGACY_execute_dde5(space, offset, data);
19482167      return;
19492168   }
19502169
r32351r32352
19522171   if (check_command_matches(command, 0x3a0, 0x3a6, 0x380, 0xaa0, 0x2a6, 0x000, 0x000, 0x000, 8, 0xf3e7))
19532172   {
19542173      executed = 1;
1955      UINT8 cur_angle;
1956      UINT16 flags;
1957
1958      /* 0 [1] */
1959      /* 0xc [1] */
1960      /* 0 [0] */
1961      /* 0 [1] */
1962      /* 0xc [1] */
1963
1964      cur_angle = space.read_byte(cop_regs[1] + (0xc ^ 3));
1965      flags = space.read_word(cop_regs[1]);
1966      //space.write_byte(cop_regs[1] + (0^3),space.read_byte(cop_regs[1] + (0^3)) & 0xfb); //correct?
1967
1968      INT8 tempangle_compare = (INT8)cop_angle_target;
1969      INT8 tempangle_mod_val = (INT8)cop_angle_step;
1970
1971      tempangle_compare &= 0xff;
1972      tempangle_mod_val &= 0xff;
1973
1974      cop_angle_target = tempangle_compare;
1975      cop_angle_step = tempangle_mod_val;
1976
1977      flags &= ~0x0004;
1978
1979      int delta = cur_angle - tempangle_compare;
1980      if (delta >= 128)
1981         delta -= 256;
1982      else if (delta < -128)
1983         delta += 256;
1984      if (delta < 0)
1985      {
1986         if (delta >= -tempangle_mod_val)
1987         {
1988            cur_angle = tempangle_compare;
1989            flags |= 0x0004;
1990         }
1991         else
1992            cur_angle += tempangle_mod_val;
1993      }
1994      else
1995      {
1996         if (delta <= tempangle_mod_val)
1997         {
1998            cur_angle = tempangle_compare;
1999            flags |= 0x0004;
2000         }
2001         else
2002            cur_angle -= tempangle_mod_val;
2003      }
2004
2005      space.write_byte(cop_regs[1] + (0 ^ 2), flags);
2006      space.write_byte(cop_regs[1] + (0xc ^ 3), cur_angle);
2174      LEGACY_execute_6200(space, offset, data);
20072175      return;
20082176   }
20092177
r32351r32352
20132181   if (check_command_matches(command, 0x380, 0x39a, 0x380, 0xa80, 0x29a, 0x000, 0x000, 0x000, 8, 0xf3e7))
20142182   {
20152183      executed = 1;
2016      UINT8 cur_angle;
2017      UINT16 flags;
2018
2019      cur_angle = space.read_byte(cop_regs[0] + (0x34 ^ 3));
2020      flags = space.read_word(cop_regs[0] + (0 ^ 2));
2021      //space.write_byte(cop_regs[1] + (0^3),space.read_byte(cop_regs[1] + (0^3)) & 0xfb); //correct?
2022
2023      INT8 tempangle_compare = (INT8)cop_angle_target;
2024      INT8 tempangle_mod_val = (INT8)cop_angle_step;
2025
2026      tempangle_compare &= 0xff;
2027      tempangle_mod_val &= 0xff;
2028
2029      cop_angle_target = tempangle_compare;
2030      cop_angle_step = tempangle_mod_val;
2031
2032
2033      flags &= ~0x0004;
2034
2035      int delta = cur_angle - tempangle_compare;
2036      if (delta >= 128)
2037         delta -= 256;
2038      else if (delta < -128)
2039         delta += 256;
2040      if (delta < 0)
2041      {
2042         if (delta >= -tempangle_mod_val)
2043         {
2044            cur_angle = tempangle_compare;
2045            flags |= 0x0004;
2046         }
2047         else
2048            cur_angle += tempangle_mod_val;
2049      }
2050      else
2051      {
2052         if (delta <= tempangle_mod_val)
2053         {
2054            cur_angle = tempangle_compare;
2055            flags |= 0x0004;
2056         }
2057         else
2058            cur_angle -= tempangle_mod_val;
2059      }
2060
2061      space.write_byte(cop_regs[0] + (0 ^ 3), flags);
2062      space.write_word(cop_regs[0] + (0x34 ^ 3), cur_angle);
2184      LEGACY_execute_6200_grainbow(space, offset, data);   
20632185      return;
20642186   }
20652187
r32351r32352
20672189   if (check_command_matches(command, 0x984, 0xac4, 0xd82, 0xac2, 0x39b, 0xb9a, 0xb9a, 0xa9a, 5, 0xb07f))
20682190   {
20692191      executed = 1;
2070      int dy = space.read_dword(cop_regs[2] + 4) - space.read_dword(cop_regs[0] + 4);
2071      int dx = space.read_dword(cop_regs[2] + 8) - space.read_dword(cop_regs[0] + 8);
2072
2073      cop_status = 7;
2074      if (!dx) {
2075         cop_status |= 0x8000;
2076         cop_angle = 0;
2077      }
2078      else {
2079         cop_angle = atan(double(dy) / double(dx)) * 128.0 / M_PI;
2080         if (dx < 0)
2081            cop_angle += 0x80;
2082      }
2083
2084      m_LEGACY_r0 = dy;
2085      m_LEGACY_r1 = dx;
2086
2087      //printf("%d %d %f %04x\n",dx,dy,atan(double(dy)/double(dx)) * 128 / M_PI,cop_angle);
2088
2089      if (data & 0x80)
2090         space.write_word(cop_regs[0] + (0x34 ^ 2), cop_angle);
2192      LEGACY_execute_e30e(space, offset, data);
20912193      return;
20922194   }
20932195
r32351r32352
20962198   if (check_command_matches(command, 0xac2, 0x9e0, 0x0a2, 0x000, 0x000, 0x000, 0x000, 0x000, 5, 0xfffb))
20972199   {
20982200      executed = 1;
2099      UINT8 *ROM = space.machine().root_device().memregion("maincpu")->base();
2100      UINT32 rom_addr = (m_cop_rom_addr_hi << 16 | m_cop_rom_addr_lo) & ~1;
2101      UINT16 rom_data = (ROM[rom_addr + 0]) | (ROM[rom_addr + 1] << 8);
2102
2103      /* writes to some unemulated COP registers, then puts the result in here, adding a parameter taken from ROM */
2104      //space.write_word(cop_regs[0]+(0x44 + offset * 4), rom_data);
2105
2106      printf("%04x%04x %04x %04x\n", m_cop_rom_addr_hi, m_cop_rom_addr_lo, m_cop_rom_addr_unk, rom_data);
2201      LEGACY_execute_d104(space, offset, data);
21072202      return;
21082203   }
21092204
2110   if (executed == 0) printf("did not execute %04x\n", data);
2205   if (executed == 0)
2206      if (data!=0xf105) printf("did not execute %04x\n", data); // cup soccer triggers this a lot (and others)
21112207}
21122208
21132209
trunk/src/mame/machine/raiden2cop.h
r32351r32352
171171   void execute_b100(address_space &space, int offset, UINT16 data);
172172   void execute_b900(address_space &space, int offset, UINT16 data);
173173
174   void LEGACY_execute_130e(address_space &space, int offset, UINT16 data);
175   void LEGACY_execute_130e_cupsoc(address_space &space, int offset, UINT16 data);
176   void LEGACY_execute_3b30(address_space &space, int offset, UINT16 data);
177   void LEGACY_execute_a100(address_space &space, int offset, UINT16 data);
178   void LEGACY_execute_b100(address_space &space, int offset, UINT16 data);
179   void LEGACY_execute_a900(address_space &space, int offset, UINT16 data);
180   void LEGACY_execute_b900(address_space &space, int offset, UINT16 data);
181   void LEGACY_execute_0205(address_space &space, int offset, UINT16 data);
182   void LEGACY_execute_42c2(address_space &space, int offset, UINT16 data);
183   void LEGACY_execute_0905(address_space &space, int offset, UINT16 data);
184   void LEGACY_execute_e30e(address_space &space, int offset, UINT16 data);
185   void LEGACY_execute_6200(address_space &space, int offset, UINT16 data);
186   void LEGACY_execute_6200_grainbow(address_space &space, int offset, UINT16 data);
187   void LEGACY_execute_dde5(address_space &space, int offset, UINT16 data);
188   void LEGACY_execute_d104(address_space &space, int offset, UINT16 data);
189   void LEGACY_execute_6980(address_space &space, int offset, UINT16 data);
190   void LEGACY_execute_c480(address_space &space, int offset, UINT16 data);
174191
175192   // Sort DMA (zeroteam, cupsoc)
176193

Previous 199869 Revisions Next


© 1997-2024 The MAME Team