aboutsummaryrefslogtreecommitdiff
path: root/libpsn00b
diff options
context:
space:
mode:
authorspicyjpeg <thatspicyjpeg@gmail.com>2022-10-16 23:52:19 +0200
committerspicyjpeg <thatspicyjpeg@gmail.com>2022-10-16 23:52:19 +0200
commit03434a230d8c3ed2e32a3885128e05e42ee11769 (patch)
treed7b06d4bce91472a1f01b9fb3a5965a9822c1a90 /libpsn00b
parent6eabb5aa549254c2272cedee26d4245f31f2dc7a (diff)
downloadpsn00bsdk-03434a230d8c3ed2e32a3885128e05e42ee11769.tar.gz
Add mdec/strvideo example, fix psxpress bug
Diffstat (limited to 'libpsn00b')
-rw-r--r--libpsn00b/include/psxcd.h7
-rw-r--r--libpsn00b/psxcd/getsector.c23
-rw-r--r--libpsn00b/psxcd/psxcd.c10
-rw-r--r--libpsn00b/psxpress/mdec.c5
-rw-r--r--libpsn00b/psxpress/vlc.s10
-rw-r--r--libpsn00b/psxpress/vlc2.c5
6 files changed, 44 insertions, 16 deletions
diff --git a/libpsn00b/include/psxcd.h b/libpsn00b/include/psxcd.h
index cf9ecad..429a439 100644
--- a/libpsn00b/include/psxcd.h
+++ b/libpsn00b/include/psxcd.h
@@ -55,8 +55,10 @@
#define CdlModeAP 0x02
#define CdlModeRept 0x04
#define CdlModeSF 0x08
-#define CdlModeSize0 0x10
-#define CdlModeSize1 0x20
+//#define CdlModeSize0 0x10
+//#define CdlModeSize1 0x20
+#define CdlModeIgnore 0x10
+#define CdlModeSize 0x20
#define CdlModeRT 0x40
#define CdlModeSpeed 0x80
@@ -146,6 +148,7 @@ uint32_t CdSyncCallback(CdlCB func);
long CdReadyCallback(CdlCB func);
int CdGetSector(void *madr, int size);
int CdGetSector2(void *madr, int size);
+int CdDataSync(int mode);
CdlFILE* CdSearchFile(CdlFILE *loc, const char *filename);
diff --git a/libpsn00b/psxcd/getsector.c b/libpsn00b/psxcd/getsector.c
index bc1c8ae..ee5315a 100644
--- a/libpsn00b/psxcd/getsector.c
+++ b/libpsn00b/psxcd/getsector.c
@@ -7,6 +7,16 @@
#include <psxcd.h>
#include <hwregs_c.h>
+#define DATA_SYNC_TIMEOUT 0x100000
+
+/* Private utilities */
+
+#ifdef NDEBUG
+#define _LOG(...)
+#else
+#define _LOG(...) printf(__VA_ARGS__)
+#endif
+
/* DMA transfer functions */
int CdGetSector(void *madr, int size) {
@@ -33,3 +43,16 @@ int CdGetSector2(void *madr, int size) {
return 1;
}
+
+int CdDataSync(int mode) {
+ if (mode)
+ return (DMA_CHCR(3) >> 24) & 1;
+
+ for (int i = DATA_SYNC_TIMEOUT; i; i--) {
+ if (!(DMA_CHCR(3) & (1 << 24)))
+ return 0;
+ }
+
+ _LOG("psxcd: CdDataSync() timeout\n");
+ return -1;
+}
diff --git a/libpsn00b/psxcd/psxcd.c b/libpsn00b/psxcd/psxcd.c
index 160a1ed..f48542d 100644
--- a/libpsn00b/psxcd/psxcd.c
+++ b/libpsn00b/psxcd/psxcd.c
@@ -285,18 +285,10 @@ int CdRead(int sectors, uint32_t *buf, int mode)
_cd_read_addr = buf;
// Determine sector based on mode flags
- if( mode & CdlModeSize0 )
- {
- _cd_read_sector_sz = 2328 / 4;
- }
- else if( mode & CdlModeSize1 )
- {
+ if( mode & CdlModeSize )
_cd_read_sector_sz = 2340 / 4;
- }
else
- {
_cd_read_sector_sz = 2048 / 4;
- }
_cd_read_counter = VSync(-1);
diff --git a/libpsn00b/psxpress/mdec.c b/libpsn00b/psxpress/mdec.c
index d308994..06510cb 100644
--- a/libpsn00b/psxpress/mdec.c
+++ b/libpsn00b/psxpress/mdec.c
@@ -164,6 +164,11 @@ int DecDCTinSync(int mode) {
void DecDCTout(uint32_t *data, size_t length) {
DecDCToutSync(0);
+ if ((length >= DMA_CHUNK_LENGTH) && (length % DMA_CHUNK_LENGTH)) {
+ _LOG("psxpress: transfer data length (%d) is not a multiple of %d, rounding\n", length, DMA_CHUNK_LENGTH);
+ length += DMA_CHUNK_LENGTH - 1;
+ }
+
DMA_MADR(1) = (uint32_t) data;
if (length < DMA_CHUNK_LENGTH)
DMA_BCR(1) = 0x00010000 | length;
diff --git a/libpsn00b/psxpress/vlc.s b/libpsn00b/psxpress/vlc.s
index fe51642..885a3f7 100644
--- a/libpsn00b/psxpress/vlc.s
+++ b/libpsn00b/psxpress/vlc.s
@@ -131,10 +131,12 @@ _vlc_skip_context_load:
#nop
.Lprocess_dc_v2_coefficient: # if (!coeff_index && !is_v3)
- # The DC coefficient in version 2 frames is not compressed.
- srl $v0, $t0, 22 # *output = (window >> (32 - 10)) | quant_scale
- or $v0, $t3
- addiu $t7, 1 # coeff_index++
+ # The DC coefficient in version 2 frames is not compressed. Value 0x1ff is
+ # used to signal the end of the bitstream.
+ srl $v0, $t0, 22 # prefix = (window >> (32 - 10))
+ li $v1, 0x01ff
+ beq $v0, $v1, .Lstop_processing # if (prefix == 0x1ff) break
+ or $v0, $t3 # *output = prefix | quant_scale
sll $t0, 10 # window <<= 10
addiu $t5, -10 # bit_offset -= 10
b .Lwrite_value
diff --git a/libpsn00b/psxpress/vlc2.c b/libpsn00b/psxpress/vlc2.c
index 73b54b2..9eb99bf 100644
--- a/libpsn00b/psxpress/vlc2.c
+++ b/libpsn00b/psxpress/vlc2.c
@@ -141,7 +141,10 @@ int __attribute__((optimize(3))) DecDCTvlcContinue2(
// TODO: version 3 is currently not supported.
return -1;
} else {
- value = _get_bits_unsigned(10);
+ value = _get_bits_unsigned(10);
+ if (value == 0x1ff)
+ break;
+
*output = value | quant_scale;
_advance_window(10);
}