Skip to content

Commit

Permalink
m_Do_graphic work
Browse files Browse the repository at this point in the history
  • Loading branch information
LagoLunatic committed Oct 4, 2024
1 parent d71cf42 commit 23ca424
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 36 deletions.
2 changes: 1 addition & 1 deletion include/JSystem/JFramework/JFWDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class JKRHeap;

typedef void (*JFWDisplayUnkFunc)(void);

extern bool JFWAutoAbortGfx;
extern u8 JFWAutoAbortGfx;

class JFWAlarm : public OSAlarm {
public:
Expand Down
2 changes: 1 addition & 1 deletion include/d/d_particle.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ class dPa_control_c {
void drawShipTail(JPADrawInfo* inf) { draw(inf, dPtclGroup_ShipTail_e); }
void drawWind(JPADrawInfo* inf) { draw(inf, dPtclGroup_Wind_e); }
void draw2Dfore(JPADrawInfo* inf) { draw(inf, dPtclGroup_2Dfore_e); }
void draw2Dback(JPADrawInfo* inf) { draw(inf, dPtclGroup_2Dfore_e); }
void draw2Dback(JPADrawInfo* inf) { draw(inf, dPtclGroup_2Dback_e); }
void draw2DmenuFore(JPADrawInfo* inf) { draw(inf, dPtclGroup_2DmenuFore_e); }
void draw2DmenuBack(JPADrawInfo* inf) { draw(inf, dPtclGroup_2DmenuBack_e); }

Expand Down
4 changes: 2 additions & 2 deletions src/JSystem/JFramework/JFWDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

JFWDisplay* JFWDisplay::sManager = NULL;

bool JFWAutoAbortGfx = true;
u8 JFWAutoAbortGfx = 1;
Mtx e_mtx = {
{1.0f, 0.0f, 0.0f, 0.0f},
{0.0f, 1.0f, 0.0f, 0.0f},
Expand Down Expand Up @@ -495,7 +495,7 @@ void JFWGXDrawDoneAutoAbort() {
/* 8025640C-802564D4 .text JFWGXAbortAlarmHandler__FP7OSAlarmP9OSContext */
void JFWGXAbortAlarmHandler(OSAlarm*, OSContext*) {
diagnoseGpHang();
if(JFWAutoAbortGfx != true) {
if(JFWAutoAbortGfx != 1) {
OSReport("自動復帰しません\n");
JUT_WARN(VERSION_SELECT(1351, 1350, 1350), "GP FREEZE!");
JUT_ASSERT(VERSION_SELECT(1352, 1351, 1351), 0);
Expand Down
213 changes: 181 additions & 32 deletions src/m_Do/m_Do_graphic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ u32 mCaptureTextureSize;
u32 mCaptureCaptureSize;
GXDrawSyncCallback mCaptureOldCB;
OSThreadQueue mCaptureThreadQueue;
u64 mCaptureTimeOutTicks;
u64 mCaptureTimeOutTicks = OS_TIMER_CLOCK;

JKRHeap * mDoGph_gInf_c::mHeap[2] = {};
GXColor mDoGph_gInf_c::mBackColor = {};
Expand Down Expand Up @@ -501,7 +501,7 @@ void drawDepth(view_class* view, view_port_class* viewport, int depth) {

s16 x = (s16)viewport->mXOrig & ~0x07;
s16 y = (s16)viewport->mYOrig & ~0x07;
y = (y < 0) ? y : 0; // y = y & (y >> 31);
s16 y2 = (y < 0) ? 0 : y;
s16 w = (s16)viewport->mWidth & ~0x07;
s16 h = (s16)viewport->mHeight & ~0x07;

Expand All @@ -513,8 +513,10 @@ void drawDepth(view_class* view, view_port_class* viewport, int depth) {
zbuf += GXGetTexBufferSize(320, hh, GX_TF_IA8, GX_FALSE, 0);
fbbuf += GXGetTexBufferSize(320, hh, mDoGph_gInf_c::getFrameBufferTimg()->format, GX_FALSE, 0);
}
y = y2;

u16 hw = w >> 1, hh = h >> 1;
u16 hw = w >> 1;
u16 hh = h >> 1;
GXSetCopyFilter(GX_FALSE, NULL, GX_TRUE, JUTVideo::getManager()->getRenderMode()->vfilter);

GXSetTexCopySrc(x, y, w, h);
Expand Down Expand Up @@ -594,32 +596,35 @@ void drawDepth(view_class* view, view_port_class* viewport, int depth) {
GXSetTevSwapModeTable(GX_TEV_SWAP3, GX_CH_BLUE, GX_CH_BLUE, GX_CH_BLUE, GX_CH_ALPHA);
GXSetTevSwapMode(GX_TEVSTAGE0, GX_TEV_SWAP0, GX_TEV_SWAP0);

if (y == 0 && (s16)viewport->mScissor.mYOrig != 0) {
s16 h = (f32)((s16)viewport->mScissor.mYOrig) + (f32)viewport->mScissor.mHeight;
GXSetNumChans(1);
GXSetChanCtrl(GX_ALPHA0, false, GX_SRC_REG, GX_SRC_REG, 0, GX_DF_NONE, GX_AF_NONE);
GXSetNumTexGens(0);
GXSetNumTevStages(1);
GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0);
GXSetTevColorIn(GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO);
GXSetTevColorOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO);
GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
GXSetBlendMode(GX_BM_NONE, GX_BL_SRC_ALPHA, GX_BL_INV_SRC_ALPHA, GX_LO_CLEAR);
GXSetAlphaCompare(GX_ALWAYS, 0, GX_AOP_OR, GX_ALWAYS, 0);
GXClearVtxDesc();
GXSetVtxDesc(GX_VA_POS, GX_DIRECT);
GXBegin(GX_QUADS, GX_VTXFMT0, 8);
GXPosition3s16(0, 0, -5);
GXPosition3s16(640, 0, -5);
GXPosition3s16(640, y, -5);
GXPosition3s16(0, y, -5);

GXPosition3s16(0, h, -5);
GXPosition3s16(640, h, -5);
GXPosition3s16(640, 480, -5);
GXPosition3s16(0, 480, -5);
GXEnd();
if (y == 0) {
s16 h = (s16)viewport->mScissor.mYOrig;
if (h != 0) {
h += (f32)viewport->mScissor.mHeight;
GXSetNumChans(1);
GXSetChanCtrl(GX_ALPHA0, false, GX_SRC_REG, GX_SRC_REG, 0, GX_DF_NONE, GX_AF_NONE);
GXSetNumTexGens(0);
GXSetNumTevStages(1);
GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0);
GXSetTevColorIn(GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO);
GXSetTevColorOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO);
GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
GXSetBlendMode(GX_BM_NONE, GX_BL_SRC_ALPHA, GX_BL_INV_SRC_ALPHA, GX_LO_CLEAR);
GXSetAlphaCompare(GX_ALWAYS, 0, GX_AOP_OR, GX_ALWAYS, 0);
GXClearVtxDesc();
GXSetVtxDesc(GX_VA_POS, GX_DIRECT);
GXBegin(GX_QUADS, GX_VTXFMT0, 8);
GXPosition3s16(0, 0, -5);
GXPosition3s16(640, 0, -5);
GXPosition3s16(640, y, -5);
GXPosition3s16(0, y, -5);

GXPosition3s16(0, h, -5);
GXPosition3s16(640, h, -5);
GXPosition3s16(640, 480, -5);
GXPosition3s16(0, 480, -5);
GXEnd();
}
}

GXSetScissor(viewport->mScissor.mXOrig, viewport->mScissor.mYOrig, viewport->mScissor.mWidth, viewport->mScissor.mHeight);
Expand Down Expand Up @@ -726,15 +731,159 @@ void mDoGph_CaptureCansel() {
}
}

#define COLOR_SQUARE_MAG(r0, g0, b0, r1, g1, b1) (r0 - r1)*(r0 - r1) + (g0 - g1)*(g0 - g1) + (b0 - b1)*(b0 - b1)

/* 80009C38-8000A180 .text blockenc__FPUc */
void blockenc(u8*) {
void blockenc(u8* block) {
/* Nonmatching */
u8 colors[16]; // sp18
u32 color_mags[4]; // sp08
u32 pix_idx;
u32 color_num = 0; // r11
u32 i = 0; // r8
pix_idx = 0; // r10
for (; i < 0x30; i += 3, pix_idx += 4) {
u32 r9 = 0; // r9
u8* pix = &block[pix_idx];
for (int j = 0; j < color_num; j++) {
u8* temp = &colors[r9*3];
if (temp[0] == pix[0] && temp[1] == pix[1] && temp[2] == pix[2]) {
break;
}
r9++;
}
if (r9 == color_num) {
colors[r9*3 + 0] = pix[0];
colors[r9*3 + 1] = pix[1];
colors[r9*3 + 2] = pix[2];
color_num += 1;
}
}

u32 color_0_idx = 0; // r17
u32 color_1_idx = 0; // r16
if (color_num > 1) {
u32 r23 = 0;
u32 r18 = INT32_MAX;
for (; r23 < color_num*3 - 3; r23 += 3) {
u32 r0 = colors[r23+0] * 30;
u32 g0 = colors[r23+1] * 59;
u32 b0 = colors[r23+2] * 11;
for (u32 r21 = r23+3; r21 < color_num*3 - 3; r21 += 3) {
u32 r1 = colors[r21+0] * 30;
u32 g1 = colors[r21+1] * 59;
u32 b1 = colors[r21+2] * 11;
u32 r20 = 0; // r20
u32 pix_idx = 0; // r19
for (u32 r22 = 0; r22 < 0x10; r22++, pix_idx += 4) {
// u32 b2 = block[pix_idx + 2] * 11;
// u32 r2 = block[pix_idx + 0] * 30;
// u32 g2 = block[pix_idx + 1] * 59;
color_mags[0] = COLOR_SQUARE_MAG(r0, g0, b0, block[pix_idx+0] * 30, block[pix_idx+1] * 59, block[pix_idx+2] * 11);
color_mags[1] = COLOR_SQUARE_MAG(r1, g1, b1, block[pix_idx+0] * 30, block[pix_idx+1] * 59, block[pix_idx+2] * 11);
u32 r3 = (r0 * 5 + r1 * 3) / 8;
u32 g3 = (g0 * 5 + g1 * 3) / 8;
u32 b3 = (b0 * 5 + b1 * 3) / 8;
color_mags[2] = COLOR_SQUARE_MAG(r3, g3, b3, block[pix_idx+0] * 30, block[pix_idx+1] * 59, block[pix_idx+2] * 11);
u32 r4 = (r1 * 5 + r0 * 3) / 8;
u32 g4 = (g1 * 5 + g0 * 3) / 8;
u32 b4 = (b1 * 5 + b0 * 3) / 8;
color_mags[3] = COLOR_SQUARE_MAG(r4, g4, b4, block[pix_idx+0] * 30, block[pix_idx+1] * 59, block[pix_idx+2] * 11);

u32 r5 = 0;
u32 r6 = INT32_MAX;
for (; r5 < 4; r5++) {
if (color_mags[r5] < r6) {
r6 = color_mags[r5];
}
}

r20 += r6;
}

if (r20 < r18) {
r18 = r20;
color_0_idx = r23;
color_1_idx = r21;
}
}
}
}

u32 r11 = (colors[color_0_idx + 0] & 0xF8) << 8 |
(colors[color_0_idx + 1] & 0xFC) << 3 |
(colors[color_0_idx + 2] & 0xF8) >> 3;
u32 r4 = (colors[color_1_idx + 0] & 0xF8) << 8 |
(colors[color_1_idx + 1] & 0xFC) << 3 |
(colors[color_1_idx + 2] & 0xF8) >> 3;
if (r11 < r4) {
u32 temp = r11;
r11 = r4;
r4 = temp;
} else if (r11 == r4) {
r4 = 0;
}
block[0x40] = r11 >> 8;
block[0x41] = r11 & 0xFF;
block[0x42] = r4 >> 8;
block[0x43] = r4 & 0xFF;

u32 r0 = ((r11 >> 8) & 0xF8) * 30;
u32 g0 = ((r11 >> 3) & 0xFC) * 59;
u32 b0 = ((r11 << 3) & 0xFC) * 11;
u32 r1 = ((r4 >> 8) & 0xF8) * 30;
u32 g1 = ((r4 >> 3) & 0xFC) * 59;
u32 b1 = ((r4 << 3) & 0xFC) * 11;
u32 r6 = 30; // r6 (bit offset within r8)
u32 r8 = 0; // r8 (bitfield of color indexes)
for (pix_idx = 0; pix_idx < 0x40; pix_idx += 4) {
// u32 b2 = block[pix_idx + 2] * 11;
// u32 r2 = block[pix_idx + 0] * 30;
// u32 g2 = block[pix_idx + 1] * 59;
color_mags[0] = COLOR_SQUARE_MAG(r0, g0, b0, block[pix_idx+0] * 30, block[pix_idx+1] * 59, block[pix_idx+2] * 11);
color_mags[1] = COLOR_SQUARE_MAG(r1, g1, b1, block[pix_idx+0] * 30, block[pix_idx+1] * 59, block[pix_idx+2] * 11);
u32 r3 = (r0 * 5 + r1 * 3) / 8;
u32 g3 = (g0 * 5 + g1 * 3) / 8;
u32 b3 = (b0 * 5 + b1 * 3) / 8;
color_mags[2] = COLOR_SQUARE_MAG(r3, g3, b3, block[pix_idx+0] * 30, block[pix_idx+1] * 59, block[pix_idx+2] * 11);
u32 r4 = (r1 * 5 + r0 * 3) / 8;
u32 g4 = (g1 * 5 + g0 * 3) / 8;
u32 b4 = (b1 * 5 + b0 * 3) / 8;
color_mags[3] = COLOR_SQUARE_MAG(r4, g4, b4, block[pix_idx+0] * 30, block[pix_idx+1] * 59, block[pix_idx+2] * 11);

u32 r5 = 0;
u32 r24;
u32 r25 = INT32_MAX;
for (; r5 < 4; r5++) {
if (color_mags[r5] < r25) {
r25 = color_mags[r5];
r24 = r5;
}
}

r8 |= (r24 & 0x03) << r6;
r6 -= 2;
}

block[0x44] = r8 >> 24;
block[0x45] = r8 >> 16;
block[0x46] = r8 >> 8;
block[0x47] = r8 & 0xFF;
}

/* 8000A180-8000A530 .text encode_s3tc__FPUcPUcii9_GXTexFmt */
void encode_s3tc(u8*, u8*, int, int, GXTexFmt) {
void encode_s3tc(u8*, u8* r26, int, int, GXTexFmt) {
/* Nonmatching */
OSReport("16 <= i8low && i8high <= 235");
u32 i8low;// = 256; // r30
u32 i8high;// = 0; // r29
u8 block[0x48]; // sp08;
blockenc(block);
memcpy(r26, &block[0x40], 8);
JUT_ASSERT(0x8A7, 16 <= i8low && i8high <= 235);
blockenc(block);
memcpy(r26, &block[0x40], 8);
blockenc(block);
memcpy(r26, &block[0x40], 8);
}

/* 8000A530-8000A744 .text setUpRectangle__Fv */
Expand Down

0 comments on commit 23ca424

Please sign in to comment.