aboutsummaryrefslogtreecommitdiff
path: root/libpsn00b
diff options
context:
space:
mode:
authorspicyjpeg <thatspicyjpeg@gmail.com>2023-04-04 00:46:20 +0200
committerspicyjpeg <thatspicyjpeg@gmail.com>2023-04-04 00:46:20 +0200
commit8e3a757d4d7d5dfc62f69ce4ede08f1cf79e3461 (patch)
tree2cbbfe5b2a1f2ba53a4d070ed142f8fbc9ba49b2 /libpsn00b
parent09f321e37fc187affa664d32e36e32c0533a7e8e (diff)
downloadpsn00bsdk-8e3a757d4d7d5dfc62f69ce4ede08f1cf79e3461.tar.gz
Add IsIdleGPU(), tweak psxgpu.h, fix mdec/strvideo
Diffstat (limited to 'libpsn00b')
-rw-r--r--libpsn00b/include/psxgpu.h48
-rw-r--r--libpsn00b/include/psxpress.h5
-rw-r--r--libpsn00b/psxgpu/common.c15
-rw-r--r--libpsn00b/psxpress/vlc2.c11
4 files changed, 52 insertions, 27 deletions
diff --git a/libpsn00b/include/psxgpu.h b/libpsn00b/include/psxgpu.h
index 2329908..78d8342 100644
--- a/libpsn00b/include/psxgpu.h
+++ b/libpsn00b/include/psxgpu.h
@@ -83,7 +83,7 @@ typedef enum _GPU_VideoMode {
(p)->u0 = (_u0), (p)->v0 = (_v0), \
(p)->u1 = (_u1), (p)->v1 = (_v1), \
(p)->u2 = (_u2), (p)->v2 = (_v2)
-
+
#define setUV4(p, _u0, _v0, _u1, _v1, _u2, _v2, _u3, _v3) \
(p)->u0 = (_u0), (p)->v0 = (_v0), \
(p)->u1 = (_u1), (p)->v1 = (_v1), \
@@ -202,38 +202,48 @@ typedef enum _GPU_VideoMode {
#define setTexWindow_T(p, r) \
(p)->code[0] = (0xe2000000 | \
- ((r)->w % 32) | \
- (((r)->h % 32) << 5) | \
- (((r)->x % 32) << 10) | \
- (((r)->y % 32) << 15) \
+ ((r)->w & 0x1f) | \
+ (((r)->h & 0x1f) << 5) | \
+ (((r)->x & 0x1f) << 10) | \
+ (((r)->y & 0x1f) << 15) \
)
#define setTexWindow(p, r) \
setlen(p, 1), setTexWindow_T(p, r)
-#define setDrawArea_T(p, r) \
+#define setDrawAreaXY_T(p, _x0, _y0, _x1, _y1) \
(p)->code[0] = (0xe3000000 | \
- ((r)->x % 1024) | \
- (((r)->y % 1024) << 10) \
+ ((_x0) & 0x3ff) | \
+ (((_y0) & 0x3ff) << 10) \
), \
(p)->code[1] = (0xe4000000 | \
- (((r)->x + (r)->w - 1) % 1024) | \
- ((((r)->y + (r)->h - 1) % 1024) << 10) \
+ ((_x1) & 0x3ff) | \
+ (((_y1) & 0x3ff) << 10) \
+ )
+#define setDrawAreaXY(p, _x0, _y0, _x1, _y1) \
+ setlen(p, 2), setDrawAreaXY_T(p, _x0, _y0, _x1, _y1)
+
+#define setDrawArea_T(p, r) \
+ setDrawAreaXY_T(p, \
+ (r)->x, \
+ (r)->y, \
+ (r)->x + (r)->w - 1, \
+ (r)->y + (r)->h - 1 \
)
#define setDrawArea(p, r) \
setlen(p, 2), setDrawArea_T(p, r)
#define setDrawOffset_T(p, _x, _y) \
(p)->code[0] = (0xe5000000 | \
- ((_x) % 1024) | \
- (((_y) % 1024) << 11) \
+ ((_x) & 0x7ff) | \
+ (((_y) & 0x7ff) << 11) \
)
#define setDrawOffset(p, _x, _y) \
setlen(p, 1), setDrawOffset_T(p, _x, _y)
-#define setDrawMask_T(p, sb, mt) \
- (p)->code[0] = (0xe6000000 | (sb) | ((mt) << 1))
-#define setDrawMask(p, sb, mt) \
- setlen(p, 1), setDrawMask_T(p, sb, mt)
+#define setDrawStp_T(p, pbw, mt) \
+ (p)->code[0] = (0xe6000000 | (pbw) | ((mt) << 1))
+#define setDrawStp(p, pbw, mt) \
+ setlen(p, 1), setDrawStp_T(p, pbw, mt)
/* Primitive structure definitions */
@@ -469,7 +479,7 @@ _DEF_PRIM(DR_TWIN,
_DEF_PRIM(DR_TPAGE,
uint32_t code[1];
)
-_DEF_PRIM(DR_MASK,
+_DEF_PRIM(DR_STP,
uint32_t code[1];
)
@@ -481,6 +491,9 @@ _DEF_PRIM(DR_ENV,
FILL_T fill;
)
+#undef _DEF_PRIM
+#undef _DEF_ALIAS
+
/* Structure definitions */
typedef struct _RECT {
@@ -545,6 +558,7 @@ void PutDrawEnv(DRAWENV *env);
void PutDrawEnvFast(DRAWENV *env);
int GetODE(void);
+int IsIdleGPU(int timeout);
int VSync(int mode);
void *VSyncHaltFunction(void (*func)(void));
void *VSyncCallback(void (*func)(void));
diff --git a/libpsn00b/include/psxpress.h b/libpsn00b/include/psxpress.h
index c3b13f4..ea0c2ec 100644
--- a/libpsn00b/include/psxpress.h
+++ b/libpsn00b/include/psxpress.h
@@ -246,8 +246,6 @@ int DecDCToutSync(int mode);
* can be different). If max_size = 0, the entire frame will always be decoded
* in one shot.
*
- * Only bitstream version 2 is currently supported.
- *
* WARNING: InitGeom() must be called prior to using DecDCTvlcStart() for the
* first time. Attempting to call this function with the GTE disabled will
* result in a crash.
@@ -411,7 +409,8 @@ void DecDCTvlcCopyTableV3(VLC_TableV3 *addr);
* buffer can be different). If max_size = 0, the entire frame will always be
* decoded in one shot.
*
- * Only bitstream version 2 is currently supported.
+ * This function only supports decoding version 1 and 2 bitstreams. Use
+ * DecDCTvlcStart() to decode a version 3 bitstream.
*
* @param ctx Pointer to VLC_Context structure (which will be initialized)
* @param buf
diff --git a/libpsn00b/psxgpu/common.c b/libpsn00b/psxgpu/common.c
index 537f672..e354261 100644
--- a/libpsn00b/psxgpu/common.c
+++ b/libpsn00b/psxgpu/common.c
@@ -321,3 +321,18 @@ void DrawOTag2(const uint32_t *ot) {
DMA_BCR(DMA_GPU) = 0;
DMA_CHCR(DMA_GPU) = 0x01000401;
}
+
+/* Queue pause/resume API */
+
+int IsIdleGPU(int timeout) {
+ if (timeout <= 0)
+ timeout = 1;
+
+ for (; timeout; timeout--) {
+ if (GPU_GP1 & (1 << 26))
+ return 0;
+ }
+
+ //_sdk_log("IsIdleGPU() timeout\n");
+ return -1;
+}
diff --git a/libpsn00b/psxpress/vlc2.c b/libpsn00b/psxpress/vlc2.c
index 24c54ce..7d9d9f3 100644
--- a/libpsn00b/psxpress/vlc2.c
+++ b/libpsn00b/psxpress/vlc2.c
@@ -123,7 +123,7 @@ int __attribute__((optimize(3))) DecDCTvlcContinue2(
*output = (uint16_t) _get_bits_unsigned(22);
_advance_window(22);
} else if (window >> 24) {
- // The first lookup table is for codes that not start with
+ // The first lookup table is for codes that do not start with
// 00000000.
value = _vlc_huffman_table2->ac[_get_bits_unsigned(13)];
_advance_window(value >> 16);
@@ -136,12 +136,9 @@ int __attribute__((optimize(3))) DecDCTvlcContinue2(
*output = (uint16_t) value;
}
} else {
- // Parse the DC (first) coefficient for this block. Version 2
- // simply stores the signed 10-bit value as-is, while version 3
- // uses a delta encoding combined with a compression method similar
- // to exp-Golomb.
+ // Parse the DC (first) coefficient for this block.
if (is_v3) {
- // TODO: version 3 is currently not supported.
+ // This implementation does not support version 3.
return -1;
} else {
value = _get_bits_unsigned(10);
@@ -161,7 +158,7 @@ int __attribute__((optimize(3))) DecDCTvlcContinue2(
// time and processes each 16-bit word starting from the the MSB, so an
// endianness conversion is necessary to preserve bit order when
// reading 32 bits at a time. Also note that the PS1 CPU is not capable
- // of shifting by more than 31 bits - it will shift by 0 bits instead!
+ // of shifting by >=31 bits - it will shift by (N % 32) bits instead!
if (bit_offset < 0) {
window = next_window << (-bit_offset);
bit_offset += 32;