diff options
| author | U-Lameguy64-LT\Lameguy64 <lameguy64@gmail.com> | 2022-04-01 14:39:04 +0800 |
|---|---|---|
| committer | U-Lameguy64-LT\Lameguy64 <lameguy64@gmail.com> | 2022-04-01 14:39:04 +0800 |
| commit | a8b404b3400c3ebd8e0b923dcaefcc49ea563e36 (patch) | |
| tree | 497e052bf5eb3aaed387cefa8a38b53027ffc8ac /indev | |
| parent | 8a01ce9efe1c03b4c103b47006b5ac3af585743c (diff) | |
| download | psn00bsdk-a8b404b3400c3ebd8e0b923dcaefcc49ea563e36.tar.gz | |
Fixed up psxmdec prototype to use psxpress
Diffstat (limited to 'indev')
| -rw-r--r-- | indev/psxmdec/main.c | 212 | ||||
| -rw-r--r-- | indev/psxmdec/makefile | 41 | ||||
| -rw-r--r-- | indev/psxmdec/mdec.s | 185 | ||||
| -rw-r--r-- | indev/psxmdec/table.h | 102 | ||||
| -rw-r--r-- | indev/psxmdec/vlc.c | 11 |
5 files changed, 67 insertions, 484 deletions
diff --git a/indev/psxmdec/main.c b/indev/psxmdec/main.c index f4f0f51..25baf11 100644 --- a/indev/psxmdec/main.c +++ b/indev/psxmdec/main.c @@ -1,17 +1,18 @@ -#include <sys/types.h>
+#include <stdint.h>
#include <stdio.h>
-#include <string.h>
#include <stdlib.h>
-#include <psxgte.h>
+#include <stddef.h>
#include <psxgpu.h>
+#include <psxpress.h>
+#include <hwregs_c.h>
-/* mdec.s */
-extern void mdec_reset( void );
-extern void mdec_setscale( void );
-extern void mdec_setquants( void );
-extern void mdec_cmd( unsigned int cmd );
-extern void mdec_in( void *src, int blocks );
-extern void mdec_out( void *dst, int blocks );
+#define SCREEN_XRES 320
+#define SCREEN_YRES 240
+
+//#define BLOCK_SIZE 8 // Monochrome (8x8), 15bpp display
+//#define BLOCK_SIZE 12 // Monochrome (8x8), 24bpp display
+//#define BLOCK_SIZE 16 // Color (16x16), 15bpp display
+#define BLOCK_SIZE 24 // Color (16x16), 24bpp display
/* vlc.c */
int DecDCTvlc( unsigned short *mdec_bs, unsigned short *mdec_rl );
@@ -19,173 +20,74 @@ int DecDCTvlc( unsigned short *mdec_bs, unsigned short *mdec_rl ); /* data.s */
extern unsigned short bs_data[];
-DISPENV disp[2];
-DRAWENV draw[2];
-int db;
-
-void memory_browser(unsigned int addr)
-{
- int i,j,key;
- unsigned char *ptr,*pptr;
-
- while(1)
- {
- /* Set cursor position to top-left */
- printf("\033[1;1H");
- printf("MEMVIEW 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF");
-
- ptr = (unsigned char*)addr;
-
- /* Print contents from current location of memory */
- for(j=0; j<23; j++)
- {
- printf("\n%04X: ", (unsigned int)ptr);
- pptr = ptr;
- for(i=0; i<16; i++)
- {
- printf("%02X ", *ptr);
- ptr++;
- }
- printf(" ");
- for(i=0; i<16; i++)
- {
- if(( *pptr < 32 ) || ( *pptr > 127 ) )
- {
- printf(".");
- }
- else
- {
- printf("%c", *pptr);
- }
- pptr++;
- }
- }
-
- /* Parse input */
- while(1)
- {
- key = getchar();
- if( key == 0x1B )
- {
- key = getchar();
-
- if( key == 0x5B )
- {
- key = getchar();
- if( key == 0x41 ) // Up
- {
- addr -= 16;
- break;
- }
- else if( key == 0x42 ) // Down
- {
- addr += 16;
- break;
- }
- if( key == 0x35 ) // Page up
- {
- addr -= 16*23;
- break;
- }
- else if( key == 0x36 ) // Page down
- {
- addr += 16*23;
- break;
- }
- }
- }
-
- }
- }
-
-} /* memory_browser */
+DISPENV disp;
void init( void )
{
- ResetGraph( 0 );
-
- SetDefDispEnv( &disp[0], 0, 0, 320, 240 );
- SetDefDispEnv( &disp[1], 0, 240, 320, 240 );
+ ResetGraph(0);
+ DecDCTReset(0);
- SetDefDrawEnv( &draw[0], 0, 240, 320, 240 );
- SetDefDrawEnv( &draw[1], 0, 0, 320, 240 );
+ SetDefDispEnv(&disp, 0, 0, SCREEN_XRES, SCREEN_YRES);
- draw[0].isbg = draw[1].isbg = 1;
- setRGB0( &draw[0], 0, 63, 0 );
- setRGB0( &draw[1], 0, 63, 0 );
+ disp.isrgb24 = disp.isrgb24 = 1;
- PutDispEnv( &disp[1] );
- PutDrawEnv( &draw[1] );
- db = 0;
+ PutDispEnv(&disp);
+ SetDispMask(1);
} /* init */
-void display( void )
-{
- DrawSync( 0 );
- VSync( 0 );
-
- PutDispEnv( &disp[db] );
- PutDrawEnv( &draw[db] );
- SetDispMask( 1 );
-
- db = !db;
-
-} /* display */
void decode_test( void )
{
- unsigned short *out_buff;
- unsigned short *dec_buff;
- int dec_len;
- RECT rect;
- int xx;
-
- out_buff = (unsigned short*)malloc( 131072 );
- dec_buff = (unsigned short*)malloc( 7680 );
-
- memset( out_buff, 0, 131072 );
- DecDCTvlc( bs_data, out_buff );
-
- dec_len = ((unsigned short*)out_buff)[0];
-
- printf( "out_buff=%p len=%d\n", out_buff, dec_len );
-
- //memory_browser( (unsigned int)(out_buff+2) );
- mdec_cmd( 0x38000000|dec_len );
-
- mdec_in( out_buff+2, 8 );
-
- rect.x = 320; rect.y = 0;
- rect.w = 16; rect.h = 240;
- xx = 0;
- //while( xx < 320 )
- {
- mdec_out( dec_buff, 120 );
- LoadImage( &rect, (unsigned int*)dec_buff );
- DrawSync( 0 );
- xx += 16;
- rect.x += 16;
+ uint16_t *out_buff;
+ uint16_t dec_len;
+
+ // Allocate and decode VLC encoded BS data
+ printf("Decode start...\n");
+ out_buff = (uint16_t*)malloc(4*((*(long*)bs_data)+1));
+ DecDCTvlc(bs_data, out_buff);
+
+ // Print out decompression results
+ dec_len = ((uint16_t*)out_buff)[0];
+ printf("out_buff=%p len=%d\n", out_buff, dec_len);
+
+ // Initialize MDEC data input
+ MDEC0 = 0x30000000 | dec_len; // 0x38000000 for 15bpp
+ DecDCTinRaw((const uint32_t*)(out_buff+1), dec_len);
+
+ // Decode image slice-by-slice
+ for (uint32_t x = 0; x < (SCREEN_XRES * 3 / 2); x += BLOCK_SIZE)
+ { // 24bpp
+ RECT rect;
+ uint32_t slice[BLOCK_SIZE * SCREEN_YRES / 2];
+
+ rect.x = x;
+ rect.y = 0;
+ rect.w = BLOCK_SIZE;
+ rect.h = SCREEN_YRES;
+
+ // Configure the MDEC to output to the slice buffer and let it finish
+ // decoding a slice, then upload it to the framebuffer.
+ DecDCTout(slice, BLOCK_SIZE * SCREEN_YRES / 2);
+ DecDCToutSync(0);
+
+ LoadImage(&rect, (u_long *) slice);
+ DrawSync(0);
}
+ free(out_buff);
+
} /* decode_test */
int main( int argc, const char *argv[] )
{
init();
- /* init MDEC */
- mdec_reset();
- mdec_setscale();
- mdec_setquants();
-
decode_test();
- while( 1 )
- {
- display();
- }
+ for (;;)
+ __asm__ volatile("");
- return( 0 );
+ return 0;
} /* main */
diff --git a/indev/psxmdec/makefile b/indev/psxmdec/makefile deleted file mode 100644 index 3b921e0..0000000 --- a/indev/psxmdec/makefile +++ /dev/null @@ -1,41 +0,0 @@ -include ../../psn00bsdk-setup.mk
-
-TARGET = mdectest.elf
-
-CFILES = $(notdir $(wildcard *.c))
-CPPFILES = $(notdir $(wildcard *.cpp))
-AFILES = $(notdir $(wildcard *.s))
-
-OFILES = $(addprefix build/,$(CFILES:.c=.o)) \
- $(addprefix build/,$(CPPFILES:.cpp=.o)) \
- $(addprefix build/,$(AFILES:.s=.o))
-
-LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc
-
-CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections
-
-CPPFLAGS = $(CFLAGS) -fno-exceptions
-
-AFLAGS = -g -msoft-float
-
-LDFLAGS = -g -Ttext=0x80010000 -gc-sections \
- -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x
-
-all: $(OFILES)
- $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET)
- elf2x -q $(TARGET)
-
-build/%.o: %.c
- @mkdir -p $(dir $@)
- $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
-
-build/%.o: %.cpp
- @mkdir -p $(dir $@)
- $(CXX) $(AFLAGS) $(INCLUDE) -c $< -o $@
-
-build/%.o: %.s
- @mkdir -p $(dir $@)
- $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@
-
-clean:
- rm -rf build $(TARGET) $(TARGET:.elf=.exe)
\ No newline at end of file diff --git a/indev/psxmdec/mdec.s b/indev/psxmdec/mdec.s deleted file mode 100644 index a7b5094..0000000 --- a/indev/psxmdec/mdec.s +++ /dev/null @@ -1,185 +0,0 @@ -.set noreorder
-
-.include "hwregs_a.h"
-
-.section .text
-
-.global mdec_reset # Resets the MDEC
-.type mdec_reset, @function
-mdec_reset:
-
- lui $a0, IOBASE
-
- lui $v0, 0xE000 # Reset MDEC
- sw $v0, MDEC1($a0)
- nop
-
- lui $v1, 0x8004 # Wait until reset completes
-.Lreset_wait:
- lw $v0, MDEC1($a0)
- nop
- bne $v0, $v1, .Lreset_wait
- nop
-
- jr $ra
- nop
-
-
-.global mdec_cmd # Sends a MDEC command word
-.type mdec_cmd, @function
-mdec_cmd:
-
- lui $a1, IOBASE
-
-.Lcmd_ready: # Wait until command busy is zero
- lw $v0, MDEC1($a1)
- lui $v1, 0x2000
- and $v0, $v1
- bnez $v0, .Lcmd_ready
- nop
-
- sw $a0, MDEC0($a1) # Write command word
-
- jr $ra
- nop
-
-.global mdec_in # Transmit data to DMA0 (MDEC in)
-.type mdec_in, @function
-mdec_in:
-
- # a0 - data source address
- # a1 - blocks to transfer (64 bytes per block)
-
- lui $a3, IOBASE
-
-.Lmdec_in_wait: # Wait until MDEC is ready for data
- lw $v0, MDEC1($a3)
- lui $v1, 0x1000
- and $v0, $v1
- beqz $v0, .Lmdec_in_wait
- nop
-
- sw $a0, D0_MADR($a3) # Set source address
-
- andi $v0, $a1, 0xFFFF # Set transfer length
- sll $v0, 16
- ori $v0, 0x20 # 32 word block size
- sw $v0, D0_BCR($a3)
-
- lui $v0, 0x0100 # Begin transfer
- ori $v0, 0x0201
- sw $v0, D0_CHCR($a3)
-
- jr $ra
- nop
-
-.global mdec_out # Transmit data to DMA0 (MDEC in)
-.type mdec_out, @function
-mdec_out:
-
- # a0 - data source address
- # a1 - blocks to transfer (64 bytes per block)
-
- lui $a3, IOBASE
-
-.Lmdec_out_ready: # Wait until MDEC is ready for data
- lw $v0, MDEC1($a3)
- lui $v1, 0x1000
- and $v0, $v1
- beqz $v0, .Lmdec_out_ready
- nop
-
- sw $a0, D1_MADR($a3) # Set source address
-
- andi $v0, $a1, 0xFFFF # Set transfer length
- sll $v0, 16
- ori $v0, 0x20 # 32 word block size
- sw $v0, D1_BCR($a3)
-
- lui $v0, 0x0100 # Begin transfer
- ori $v0, 0x0200
- sw $v0, D1_CHCR($a3)
-
-.Lmdec_out_wait:
- lw $v0, D1_CHCR($a3)
- lui $v1, 0x0200
- and $v0, $v1
- bnez $v0, .Lmdec_out_wait
- nop
-
- jr $ra
- nop
-
-.global mdec_setscale # Uploads the internal scaletable to MDEC
-.type mdec_setscale, @function
-mdec_setscale:
-
- addiu $sp, -4
- sw $ra, 0($sp)
-
- lui $a0, 0x6000 # Set scaletable command
- jal mdec_cmd
- nop
-
- la $a0, _mdec_scaletable # Upload scaletable
- jal mdec_in
- li $a1, 1 # 64 halfwords
-
- lw $ra, 0($sp)
- addiu $sp, 4
- jr $ra
- nop
-
-
-.global mdec_setquants # Uploads the internal quant tables
-.type mdec_setquants, @function
-mdec_setquants:
-
- addiu $sp, -4
- sw $ra, 0($sp)
-
- lui $a0, 0x4000 # Set quant tables command
- ori $a0, 0x0001 # luma + chroma data
- jal mdec_cmd
- nop
-
- la $a0, _mdec_qtables # Upload quant tables
- jal mdec_in
- li $a1, 2 # 128 halfwords
-
- lw $ra, 0($sp)
- addiu $sp, 4
- jr $ra
- nop
-
-
-.section .data
-
-_mdec_qtables:
- # taken from CCITT Rec. T.81
- .hword 16, 11, 10, 16, 24, 40, 51, 61 # Luma table
- .hword 12, 12, 14, 19, 26, 58, 60, 55
- .hword 14, 13, 16, 24, 40, 57, 69, 56
- .hword 14, 17, 22, 29, 51, 87, 80, 62
- .hword 18, 22, 37, 56, 68, 109, 103, 77
- .hword 24, 35, 55, 64, 81, 104, 113, 92
- .hword 49, 64, 78, 87, 103, 121, 120, 101
- .hword 72, 92, 95, 98, 112, 100, 103, 99
- .hword 17, 18, 24, 47, 99, 99, 99, 99 # Chroma table
- .hword 18, 21, 26, 66, 99, 99, 99, 99
- .hword 24, 26, 56, 99, 99, 99, 99, 99
- .hword 47, 66, 99, 99, 99, 99, 99, 99
- .hword 99, 99, 99, 99, 99, 99, 99, 99
- .hword 99, 99, 99, 99, 99, 99, 99, 99
- .hword 99, 99, 99, 99, 99, 99, 99, 99
- .hword 99, 99, 99, 99, 99, 99, 99, 99
-
-_mdec_scaletable:
- .hword 0x5A82,0x5A82,0x5A82,0x5A82,0x5A82,0x5A82,0x5A82,0x5A82
- .hword 0x7D8A,0x6A6D,0x471C,0x18F8,0xE707,0xB8E3,0x9592,0x8275
- .hword 0x7641,0x30FB,0xCF04,0x89BE,0x89BE,0xCF04,0x30FB,0x7641
- .hword 0x6A6D,0xE707,0x8275,0xB8E3,0x471C,0x7D8A,0x18F8,0x9592
- .hword 0x5A82,0xA57D,0xA57D,0x5A82,0x5A82,0xA57D,0xA57D,0x5A82
- .hword 0x471C,0x8275,0x18F8,0x6A6D,0x9592,0xE707,0x7D8A,0xB8E3
- .hword 0x30FB,0x89BE,0x7641,0xCF04,0xCF04,0x7641,0x89BE,0x30FB
- .hword 0x18F8,0xB8E3,0x6A6D,0x8275,0x7D8A,0x9592,0x471C,0xE707
diff --git a/indev/psxmdec/table.h b/indev/psxmdec/table.h deleted file mode 100644 index 3e50b18..0000000 --- a/indev/psxmdec/table.h +++ /dev/null @@ -1,102 +0,0 @@ -const static huff_t table0[]={
- {6,3},{8,5},{10,6},{12,8},{76,9},{66,9},{20,11},{58,13},{48,13},{38,13},{32,13},{52,14},{50,14},{48,14},{46,14},{62,15},{60,15},{58,15},{56,15},{54,15},{52,15},{50,15},{48,15},{46,15},{44,15},{42,15},{40,15},{38,15},{36,15},{34,15},{32,15},{48,16},{46,16},{44,16},{42,16},{40,16},{38,16},{36,16},{34,16},{32,16},
-};
-const static huff_t table1[]={
- {6,4},{12,7},{74,9},{24,11},{54,13},{44,14},{42,14},{62,16},{60,16},{58,16},{56,16},{54,16},{52,16},{50,16},{38,17},{36,17},{34,17},{32,17},
-};
-const static huff_t table2[]={
- {10,5},{8,8},{22,11},{40,13},{40,14},
-};
-const static huff_t table3[]={
- {14,6},{72,9},{56,13},{38,14},
-};
-const static huff_t table4[]={
- {12,6},{30,11},{36,13},
-};
-const static huff_t table5[]={
- {14,7},{18,11},{36,14},
-};
-const static huff_t table6[]={
- {10,7},{60,13},{40,17},
-};
-const static huff_t table7[]={
- {8,7},{42,13},
-};
-const static huff_t table8[]={
- {14,8},{34,13},
-};
-const static huff_t table9[]={
- {10,8},{34,14},
-};
-const static huff_t table10[]={
- {78,9},{32,14},
-};
-const static huff_t table11[]={
- {70,9},{52,17},
-};
-const static huff_t table12[]={
- {68,9},{50,17},
-};
-const static huff_t table13[]={
- {64,9},{48,17},
-};
-const static huff_t table14[]={
- {28,11},{46,17},
-};
-const static huff_t table15[]={
- {26,11},{44,17},
-};
-const static huff_t table16[]={
- {16,11},{42,17},
-};
-const static huff_t table17[]={
- {62,13},
-};
-const static huff_t table18[]={
- {52,13},
-};
-const static huff_t table19[]={
- {50,13},
-};
-const static huff_t table20[]={
- {46,13},
-};
-const static huff_t table21[]={
- {44,13},
-};
-const static huff_t table22[]={
- {62,14},
-};
-const static huff_t table23[]={
- {60,14},
-};
-const static huff_t table24[]={
- {58,14},
-};
-const static huff_t table25[]={
- {56,14},
-};
-const static huff_t table26[]={
- {54,14},
-};
-const static huff_t table27[]={
- {62,17},
-};
-const static huff_t table28[]={
- {60,17},
-};
-const static huff_t table29[]={
- {58,17},
-};
-const static huff_t table30[]={
- {56,17},
-};
-const static huff_t table31[]={
- {54,17},
-};
-const static huff_t *huff_table[]={
- table0,table1,table2,table3,table4,table5,table6,table7,table8,table9,table10,table11,table12,table13,table14,table15,table16,table17,table18,table19,table20,table21,table22,table23,table24,table25,table26,table27,table28,table29,table30,table31,
-};
-const static int maxlevel[]={
- 40,18,5,4,3,3,3,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
-};
diff --git a/indev/psxmdec/vlc.c b/indev/psxmdec/vlc.c index bc64a12..064cfb3 100644 --- a/indev/psxmdec/vlc.c +++ b/indev/psxmdec/vlc.c @@ -1,3 +1,12 @@ +/* This file is a trimmed version of
+ * https://cgit.grumpycoder.net/cgit/PSX-Bundle/tree/psxdev/vlc.c
+ * that only includes the VLC decompression routine. It cannot be
+ * included as part of the PSn00bSDK Run-time libraries due to license
+ * incompatibilities but is included here largely for prototyping and
+ * reference purposes as a better optimized implementation is preferred
+ * to support full-motion-video playback.
+ *
+ */
#include <sys/types.h>
typedef unsigned short Uint16;
@@ -7,7 +16,7 @@ typedef struct { unsigned int code,nbits;
} huff_t;
-#include "table.h"
+//#include "table.h"
#define CODE1(a,b,c) (((a)<<10)|((b)&0x3ff)|((c)<<16))
/* run, level, bit */
|
