Made BulHit.cpp ASM-accurate

This commit is contained in:
Clownacy 2019-05-06 00:00:10 +01:00
parent dea995ffe6
commit a8c4955b75
2 changed files with 223 additions and 155 deletions

View file

@ -15,6 +15,50 @@ size = 0x100
name = "PutFront" name = "PutFront"
addr = 0x402830 addr = 0x402830
[[func]]
name = "JudgeHitBulletBlock"
addr = 0x4029B0
[[func]]
name = "JudgeHitBulletBlock2"
addr = 0x402B30
[[func]]
name = "JudgeHitBulletTriangleA"
addr = 0x402FC0
[[func]]
name = "JudgeHitBulletTriangleB"
addr = 0x4030B0
[[func]]
name = "JudgeHitBulletTriangleC"
addr = 0x4031A0
[[func]]
name = "JudgeHitBulletTriangleD"
addr = 0x403290
[[func]]
name = "JudgeHitBulletTriangleE"
addr = 0x403380
[[func]]
name = "JudgeHitBulletTriangleF"
addr = 0x403470
[[func]]
name = "JudgeHitBulletTriangleG"
addr = 0x403560
[[func]]
name = "JudgeHitBulletTriangleH"
addr = 0x403650
[[func]]
name = "HitBulletMap"
addr = 0x403740
[[func]] [[func]]
name = "Call_Escape" name = "Call_Escape"
addr = 0x40DD70 addr = 0x40DD70

View file

@ -23,12 +23,13 @@ void Vanish(BULLET *bul)
int JudgeHitBulletBlock(int x, int y, BULLET *bul) int JudgeHitBulletBlock(int x, int y, BULLET *bul)
{ {
int i;
int hit = 0; int hit = 0;
if (bul->x - bul->blockXL < (2 * x + 1) << 12 if (bul->x - bul->blockXL < (0x10 * x + 8) * 0x200
&& bul->blockXL + bul->x > (2 * x - 1) << 12 && bul->x + bul->blockXL > (0x10 * x - 8) * 0x200
&& bul->y - bul->blockYL < (2 * y + 1) << 12 && bul->y - bul->blockYL < (0x10 * y + 8) * 0x200
&& bul->blockYL + bul->y > (2 * y - 1) << 12) && bul->y + bul->blockYL> (0x10 * y - 8) * 0x200)
hit = 0x200; hit |= 0x200;
if (hit && (bul->bbits & 0x60) && GetAttribute(x, y) == 0x43) if (hit && (bul->bbits & 0x60) && GetAttribute(x, y) == 0x43)
{ {
@ -36,8 +37,8 @@ int JudgeHitBulletBlock(int x, int y, BULLET *bul)
bul->cond = 0; bul->cond = 0;
SetCaret(bul->x, bul->y, 2, 0); SetCaret(bul->x, bul->y, 2, 0);
PlaySoundObject(12, 1); PlaySoundObject(12, 1);
for (int i = 0; i < 4; i++) for (i = 0; i < 4; i++)
SetNpChar(4, x << 13, y << 13, Random(-0x200, 0x200), Random(-0x200, 0x200), 0, 0, 256); SetNpChar(4, x * 0x200 * 0x10, y * 0x200 * 0x10, Random(-0x200, 0x200), Random(-0x200, 0x200), 0, 0, 256);
ShiftMapParts(x, y); ShiftMapParts(x, y);
} }
@ -46,28 +47,39 @@ int JudgeHitBulletBlock(int x, int y, BULLET *bul)
int JudgeHitBulletBlock2(int x, int y, uint8_t *atrb, BULLET *bul) int JudgeHitBulletBlock2(int x, int y, uint8_t *atrb, BULLET *bul)
{ {
int i;
int workX;
int workY;
int hit = 0; int hit = 0;
int block[4]; int block[4];
if (bul->bbits & 0x40) if (bul->bbits & 0x40)
{ {
for (int i = 0; i < 4; i++) for (i = 0; i < 4; i++)
{ {
block[i] = *atrb == 0x41 || *atrb == 0x61; if (*atrb == 0x41 || *atrb == 0x61)
block[i] = 1;
else
block[i] = 0;
++atrb; ++atrb;
} }
} }
else else
{ {
for (int i = 0; i < 4; i++) for (i = 0; i < 4; i++)
{ {
block[i] = *atrb == 0x41 || *atrb == 0x43 || *atrb == 0x61; if (*atrb == 0x41 || *atrb == 0x43 || *atrb == 0x61)
block[i] = 1;
else
block[i] = 0;
++atrb; ++atrb;
} }
} }
int workX = (2 * x + 1) << 12; workX = (0x10 * x + 8) * 0x200;
int workY = (2 * y + 1) << 12; workY = (0x10 * y + 8) * 0x200;
//Left wall //Left wall
if (block[0] && block[2]) if (block[0] && block[2])
@ -75,14 +87,15 @@ int JudgeHitBulletBlock2(int x, int y, uint8_t *atrb, BULLET *bul)
if (bul->x - bul->blockXL < workX) if (bul->x - bul->blockXL < workX)
hit |= 1; hit |= 1;
} }
else if (!block[0] || block[2]) else if (block[0] && !block[2])
{ {
if (!block[0] && block[2] && bul->x - bul->blockXL < workX && bul->blockYL + bul->y > workY + 0x600) if (bul->x - bul->blockXL < workX && bul->y - bul->blockYL < workY - 0x600)
hit |= 1; hit |= 1;
} }
else if (bul->x - bul->blockXL < workX && bul->y - bul->blockYL < workY - 0x600) else if (!block[0] && block[2])
{ {
hit |= 1; if (bul->x - bul->blockXL < workX && bul->y + bul->blockYL > workY + 0x600)
hit |= 1;
} }
//Right wall //Right wall
@ -91,30 +104,32 @@ int JudgeHitBulletBlock2(int x, int y, uint8_t *atrb, BULLET *bul)
if (bul->x + bul->blockXL > workX) if (bul->x + bul->blockXL > workX)
hit |= 4; hit |= 4;
} }
else if (!block[1] || block[3]) else if (block[1] && !block[3])
{ {
if (!block[1] && block[3] && bul->x + bul->blockXL > workX && bul->blockYL + bul->y > workY + 0x600) if (bul->x + bul->blockXL > workX && bul->y - bul->blockYL < workY - 0x600)
hit |= 4; hit |= 4;
} }
else if (bul->x + bul->blockXL > workX && bul->y - bul->blockYL < workY - 0x600) else if (!block[1] && block[3])
{ {
hit |= 4; if (bul->x + bul->blockXL > workX && bul->y + bul->blockYL > workY + 0x600)
hit |= 4;
} }
//Ceiling //Ceiling
if (block[0] && block[1]) if (block[0] && block[1])
{ {
if (bul->y - bul->blockYL < workY) if (bul->y - bul->blockYL < workY)
hit |= 2; hit |= 2;
} }
else if (!block[0] || block[1]) else if (block[0] && !block[1])
{ {
if (!block[0] && block[1] && bul->y - bul->blockYL < workY && bul->blockXL + bul->x > workX + 0x600) if (bul->y - bul->blockYL < workY && bul->x - bul->blockXL < workX - 0x600)
hit |= 2; hit |= 2;
} }
else if (bul->y - bul->blockYL < workY && bul->x - bul->blockXL < workX - 0x600) else if (!block[0] && block[1])
{ {
hit |= 2; if (bul->y - bul->blockYL < workY && bul->x + bul->blockXL > workX + 0x600)
hit |= 2;
} }
//Ground //Ground
@ -123,14 +138,15 @@ int JudgeHitBulletBlock2(int x, int y, uint8_t *atrb, BULLET *bul)
if (bul->y + bul->blockYL > workY) if (bul->y + bul->blockYL > workY)
hit |= 8; hit |= 8;
} }
else if (!block[2] || block[3]) else if (block[2] && !block[3])
{ {
if (!block[2] && block[3] && bul->y + bul->blockYL > workY && bul->blockXL + bul->x > workX + 0x600) if (bul->y + bul->blockYL > workY && bul->x - bul->blockXL < workX - 0x600)
hit |= 8; hit |= 8;
} }
else if (bul->y + bul->blockYL > workY && bul->x - bul->blockXL < workX - 0x600) else if (!block[2] && block[3])
{ {
hit |= 8; if (bul->y + bul->blockYL > workY && bul->x + bul->blockXL > workX + 0x600)
hit |= 8;
} }
//Clip //Clip
@ -156,16 +172,16 @@ int JudgeHitBulletBlock2(int x, int y, uint8_t *atrb, BULLET *bul)
int JudgeHitBulletTriangleA(int x, int y, BULLET *bul) int JudgeHitBulletTriangleA(int x, int y, BULLET *bul)
{ {
int hit = 0; int hit = 0;
if (bul->x < (2 * x + 1) << 12 if (bul->x < (0x10 * x + 8) * 0x200
&& bul->x > (2 * x - 1) << 12 && bul->x > (0x10 * x - 8) * 0x200
&& bul->y - 0x400 < (y << 13) - (-0x2000 * x + bul->x) / 2 + 0x800 && bul->y - 0x400 < (y * 0x10 * 0x200) - (bul->x - x * 0x10 * 0x200) / 2 + 0x800
&& bul->y + 0x400 > (2 * y - 1) << 12) && bul->y + 0x400 > (0x10 * y - 8) * 0x200)
{ {
if (bul->bbits & 8) if (bul->bbits & 8)
bul->y = (y << 13) - (-0x2000 * x + bul->x) / 2 + 0xC00; bul->y = (y * 0x10 * 0x200) - (bul->x - x * 0x10 * 0x200) / 2 + 0xC00;
else else
Vanish(bul); Vanish(bul);
hit = 0x82; hit |= 0x82;
} }
return hit; return hit;
} }
@ -173,16 +189,16 @@ int JudgeHitBulletTriangleA(int x, int y, BULLET *bul)
int JudgeHitBulletTriangleB(int x, int y, BULLET *bul) int JudgeHitBulletTriangleB(int x, int y, BULLET *bul)
{ {
int hit = 0; int hit = 0;
if (bul->x < (2 * x + 1) << 12 if (bul->x < (0x10 * x + 8) * 0x200
&& bul->x > (2 * x - 1) << 12 && bul->x > (0x10 * x - 8) * 0x200
&& bul->y - 0x400 < (y << 13) - (-0x2000 * x + bul->x) / 2 - 0x800 && bul->y - 0x400 < (y * 0x10 * 0x200) - (bul->x - x * 0x10 * 0x200) / 2 - 0x800
&& bul->y + 0x400 > (2 * y - 1) << 12) && bul->y + 0x400 > (0x10 * y - 8) * 0x200)
{ {
if (bul->bbits & 8) if (bul->bbits & 8)
bul->y = (y << 13) - (-0x2000 * x + bul->x) / 2 - 0x400; bul->y = (y * 0x10 * 0x200) - (bul->x - x * 0x10 * 0x200) / 2 - 0x400;
else else
Vanish(bul); Vanish(bul);
hit = 0x82; hit |= 0x82;
} }
return hit; return hit;
} }
@ -190,16 +206,16 @@ int JudgeHitBulletTriangleB(int x, int y, BULLET *bul)
int JudgeHitBulletTriangleC(int x, int y, BULLET *bul) int JudgeHitBulletTriangleC(int x, int y, BULLET *bul)
{ {
int hit = 0; int hit = 0;
if (bul->x < (2 * x + 1) << 12 if (bul->x < (0x10 * x + 8) * 0x200
&& bul->x > (2 * x - 1) << 12 && bul->x > (0x10 * x - 8) * 0x200
&& bul->y - 0x400 < (y << 13) + (-0x2000 * x + bul->x) / 2 - 0x800 && bul->y - 0x400 < (y * 0x10 * 0x200) + (bul->x - x * 0x10 * 0x200) / 2 - 0x800
&& bul->y + 0x400 > (2 * y - 1) << 12) && bul->y + 0x400 > (0x10 * y - 8) * 0x200)
{ {
if (bul->bbits & 8) if (bul->bbits & 8)
bul->y = (y << 13) + (-0x2000 * x + bul->x) / 2 - 0x400; bul->y = (y * 0x10 * 0x200) + (bul->x - x * 0x10 * 0x200) / 2 - 0x400;
else else
Vanish(bul); Vanish(bul);
hit = 0x82; hit |= 0x42;
} }
return hit; return hit;
} }
@ -207,16 +223,16 @@ int JudgeHitBulletTriangleC(int x, int y, BULLET *bul)
int JudgeHitBulletTriangleD(int x, int y, BULLET *bul) int JudgeHitBulletTriangleD(int x, int y, BULLET *bul)
{ {
int hit = 0; int hit = 0;
if (bul->x < (2 * x + 1) << 12 if (bul->x < (0x10 * x + 8) * 0x200
&& bul->x > (2 * x - 1) << 12 && bul->x > (0x10 * x - 8) * 0x200
&& bul->y - 0x400 < (y << 13) + (-0x2000 * x + bul->x) / 2 + 0x800 && bul->y - 0x400 < (y * 0x10 * 0x200) + (bul->x - x * 0x10 * 0x200) / 2 + 0x800
&& bul->y + 0x400 > (2 * y - 1) << 12) && bul->y + 0x400 > (0x10 * y - 8) * 0x200)
{ {
if (bul->bbits & 8) if (bul->bbits & 8)
bul->y = (y << 13) + (-0x2000 * x + bul->x) / 2 + 0xC00; bul->y = (y * 0x10 * 0x200) + (bul->x - x * 0x10 * 0x200) / 2 + 0xC00;
else else
Vanish(bul); Vanish(bul);
hit = 0x82; hit |= 0x42;
} }
return hit; return hit;
} }
@ -224,16 +240,16 @@ int JudgeHitBulletTriangleD(int x, int y, BULLET *bul)
int JudgeHitBulletTriangleE(int x, int y, BULLET *bul) int JudgeHitBulletTriangleE(int x, int y, BULLET *bul)
{ {
int hit = 0; int hit = 0;
if (bul->x < (2 * x + 1) << 12 if (bul->x < (0x10 * x + 8) * 0x200
&& bul->x - 0x200 > (2 * x - 1) << 12 && bul->x - 0x200 > (0x10 * x - 8) * 0x200
&& bul->y + 0x400 > (y << 13) + (-0x2000 * x + bul->x) / 2 - 0x800 && bul->y + 0x400 > (y * 0x10 * 0x200) + (bul->x - x * 0x10 * 0x200) / 2 - 0x800
&& bul->y - 0x400 < (2 * y + 1) << 12 ) && bul->y - 0x400 < (0x10 * y + 8) * 0x200)
{ {
if (bul->bbits & 8) if (bul->bbits & 8)
bul->y = (y << 13) + (-0x2000 * x + bul->x) / 2 - 0xC00; bul->y = (y * 0x10 * 0x200) + (bul->x - x * 0x10 * 0x200) / 2 - 0xC00;
else else
Vanish(bul); Vanish(bul);
hit = 0x28; hit |= 0x28;
} }
return hit; return hit;
} }
@ -241,16 +257,16 @@ int JudgeHitBulletTriangleE(int x, int y, BULLET *bul)
int JudgeHitBulletTriangleF(int x, int y, BULLET *bul) int JudgeHitBulletTriangleF(int x, int y, BULLET *bul)
{ {
int hit = 0; int hit = 0;
if (bul->x < (2 * x + 1) << 12 if (bul->x < (0x10 * x + 8) * 0x200
&& bul->x > (2 * x - 1) << 12 && bul->x > (0x10 * x - 8) * 0x200
&& bul->y + 0x400 > (y << 13) + (-0x2000 * x + bul->x) / 2 + 0x800 && bul->y + 0x400 > (y * 0x10 * 0x200) + (bul->x - x * 0x10 * 0x200) / 2 + 0x800
&& bul->y - 0x400 < (2 * y + 1) << 12) && bul->y - 0x400 < (0x10 * y + 8) * 0x200)
{ {
if (bul->bbits & 8) if (bul->bbits & 8)
bul->y = (y << 13) + (-0x2000 * x + bul->x) / 2 + 0x400; bul->y = (y * 0x10 * 0x200) + (bul->x - x * 0x10 * 0x200) / 2 + 0x400;
else else
Vanish(bul); Vanish(bul);
hit = 0x28; hit |= 0x28;
} }
return hit; return hit;
} }
@ -258,16 +274,16 @@ int JudgeHitBulletTriangleF(int x, int y, BULLET *bul)
int JudgeHitBulletTriangleG(int x, int y, BULLET *bul) int JudgeHitBulletTriangleG(int x, int y, BULLET *bul)
{ {
int hit = 0; int hit = 0;
if (bul->x < (2 * x + 1) << 12 if (bul->x < (0x10 * x + 8) * 0x200
&& bul->x > (2 * x - 1) << 12 && bul->x > (0x10 * x - 8) * 0x200
&& bul->y + 0x400 > (y << 13) - (-0x2000 * x + bul->x) / 2 + 0x800 && bul->y + 0x400 > (y * 0x10 * 0x200) - (bul->x - x * 0x10 * 0x200) / 2 + 0x800
&& bul->y - 0x400 < (2 * y + 1) << 12) && bul->y - 0x400 < (0x10 * y + 8) * 0x200)
{ {
if (bul->bbits & 8) if (bul->bbits & 8)
bul->y = (y << 13) - (-0x2000 * x + bul->x) / 2 + 0x400; bul->y = (y * 0x10 * 0x200) - (bul->x - x * 0x10 * 0x200) / 2 + 0x400;
else else
Vanish(bul); Vanish(bul);
hit = 0x18; hit |= 0x18;
} }
return hit; return hit;
} }
@ -275,105 +291,113 @@ int JudgeHitBulletTriangleG(int x, int y, BULLET *bul)
int JudgeHitBulletTriangleH(int x, int y, BULLET *bul) int JudgeHitBulletTriangleH(int x, int y, BULLET *bul)
{ {
int hit = 0; int hit = 0;
if (bul->x < (2 * x + 1) << 12 if (bul->x < (0x10 * x + 8) * 0x200
&& bul->x > (2 * x - 1) << 12 && bul->x > (0x10 * x - 8) * 0x200
&& bul->y + 0x400 > (y << 13) - (-0x2000 * x + bul->x) / 2 - 0x800 && bul->y + 0x400 > (y * 0x10 * 0x200) - (bul->x - x * 0x10 * 0x200) / 2 - 0x800
&& bul->y - 0x400 < (2 * y + 1) << 12 ) && bul->y - 0x400 < (0x10 * y + 8) * 0x200)
{ {
if (bul->bbits & 8) if (bul->bbits & 8)
bul->y = (y << 13) - (-0x2000 * x + bul->x) / 2 - 0xC00; bul->y = (y * 0x10 * 0x200) - (bul->x - x * 0x10 * 0x200) / 2 - 0xC00;
else else
Vanish(bul); Vanish(bul);
hit = 0x18; hit |= 0x18;
} }
return hit; return hit;
} }
void HitBulletMap() void HitBulletMap()
{ {
for (int i = 0; i < BULLET_MAX; i++) int i;
int j;
int x;
int y;
unsigned char atrb[4];
for (i = 0; i < BULLET_MAX; i++)
{ {
if (gBul[i].cond & 0x80) int offx[4];
int offy[4];
if ((gBul[i].cond & 0x80) == 0)
continue;
x = gBul[i].x / 0x10 / 0x200;
y = gBul[i].y / 0x10 / 0x200;
//Get surrounding tiles
offx[0] = 0;
offx[1] = 1;
offx[2] = 0;
offx[3] = 1;
offy[0] = 0;
offy[1] = 0;
offy[2] = 1;
offy[3] = 1;
atrb[0] = GetAttribute(x, y);
atrb[1] = GetAttribute(x + 1, y);
atrb[2] = GetAttribute(x, y + 1);
atrb[3] = GetAttribute(x + 1, y + 1);
//Clear hit tiles
gBul[i].flag = 0;
if (gBul[i].bbits & 4)
{ {
int x = gBul[i].x / 0x2000; // For some reason a 'continue' just doesn't produce the same assembly
int y = gBul[i].y / 0x2000; }
else
//Get surrounding tiles {
int offy[4]; for (j = 0; j < 4; j++)
int offx[4];
offx[0] = 0;
offx[1] = 1;
offx[2] = 0;
offx[3] = 1;
offy[0] = 0;
offy[1] = 0;
offy[2] = 1;
offy[3] = 1;
uint8_t atrb[4];
atrb[0] = GetAttribute(x, y);
atrb[1] = GetAttribute(x + 1, y);
atrb[2] = GetAttribute(x, y + 1);
atrb[3] = GetAttribute(x + 1, y + 1);
//Clear hit tiles
gBul[i].flag = 0;
if (!(gBul[i].bbits & 4))
{ {
for (int j = 0; j < 4; j++) if ((gBul[i].cond & 0x80) == 0)
continue;
switch (atrb[j])
{ {
if (gBul[i].cond & 0x80) case 0x41:
{ case 0x43:
switch (atrb[j]) case 0x44:
{ case 0x61:
case 0x41: case 0x64:
case 0x43: gBul[i].flag |= JudgeHitBulletBlock(x + offx[j], y + offy[j], &gBul[i]);
case 0x44: break;
case 0x61: case 0x50:
case 0x64: case 0x70:
gBul[i].flag |= JudgeHitBulletBlock(x + offx[j], y + offy[j], &gBul[i]); gBul[i].flag |= JudgeHitBulletTriangleA(x + offx[j], y + offy[j], &gBul[i]);
break; break;
case 0x50: case 0x51:
case 0x70: case 0x71:
gBul[i].flag |= JudgeHitBulletTriangleA(x + offx[j], y + offy[j], &gBul[i]); gBul[i].flag |= JudgeHitBulletTriangleB(x + offx[j], y + offy[j], &gBul[i]);
break; break;
case 0x51: case 0x52:
case 0x71: case 0x72:
gBul[i].flag |= JudgeHitBulletTriangleB(x + offx[j], y + offy[j], &gBul[i]); gBul[i].flag |= JudgeHitBulletTriangleC(x + offx[j], y + offy[j], &gBul[i]);
break; break;
case 0x52: case 0x53:
case 0x72: case 0x73:
gBul[i].flag |= JudgeHitBulletTriangleC(x + offx[j], y + offy[j], &gBul[i]); gBul[i].flag |= JudgeHitBulletTriangleD(x + offx[j], y + offy[j], &gBul[i]);
break; break;
case 0x53: case 0x54:
case 0x73: case 0x74:
gBul[i].flag |= JudgeHitBulletTriangleD(x + offx[j], y + offy[j], &gBul[i]); gBul[i].flag |= JudgeHitBulletTriangleE(x + offx[j], y + offy[j], &gBul[i]);
break; break;
case 0x54: case 0x55:
case 0x74: case 0x75:
gBul[i].flag |= JudgeHitBulletTriangleE(x + offx[j], y + offy[j], &gBul[i]); gBul[i].flag |= JudgeHitBulletTriangleF(x + offx[j], y + offy[j], &gBul[i]);
break; break;
case 0x55: case 0x56:
case 0x75: case 0x76:
gBul[i].flag |= JudgeHitBulletTriangleF(x + offx[j], y + offy[j], &gBul[i]); gBul[i].flag |= JudgeHitBulletTriangleG(x + offx[j], y + offy[j], &gBul[i]);
break; break;
case 0x56: case 0x57:
case 0x76: case 0x77:
gBul[i].flag |= JudgeHitBulletTriangleG(x + offx[j], y + offy[j], &gBul[i]); gBul[i].flag |= JudgeHitBulletTriangleH(x + offx[j], y + offy[j], &gBul[i]);
break; break;
case 0x57:
case 0x77:
gBul[i].flag |= JudgeHitBulletTriangleH(x + offx[j], y + offy[j], &gBul[i]);
break;
default:
break;
}
}
} }
gBul[i].flag |= JudgeHitBulletBlock2(x, y, atrb, &gBul[i]);
} }
gBul[i].flag |= JudgeHitBulletBlock2(x, y, atrb, &gBul[i]);
} }
} }
} }